added devcontainer.

fix build error, deploy using docker-compose works,
misc changes
using global MQTT instead of local one to tap to already existin broker
This commit is contained in:
Dobromir Popov ONE
2023-05-14 21:40:57 +03:00
parent 145e202d24
commit 95ce6e8c87
7 changed files with 78 additions and 14 deletions

View File

@@ -7,7 +7,7 @@ const util = require('util');
var app = require('express')();
var db = require('./db');
var config = require('./setup_const');
//var config = require('./setup_const');
var passport = require('passport');
var Strategy = require('passport-local').Strategy;
var CookieStrategy = require('passport-cookie').Strategy;

View File

@@ -2,7 +2,10 @@
var db = require("./db");
const env = process.env.NODE_ENV || "development";
console.log("ENV: %s", env);
const config = require(__dirname + "/../config/config.json")[env];
const path = require('path');
const configPath = path.join(__dirname, '/../config/config.json');
const config = require(configPath)[env];
console.log("MQTT: Checking config sources: process.env.MQTT_HOST: %s", process.env.MQTT_HOST);
console.log("MQTT: Checking config sources: process.env.MQTT_PORT_HTTP: %s", process.env.MQTT_PORT_HTTP);
@@ -169,6 +172,28 @@ mqtt_client.on("message", function (topic, message) {
console.log("MQTT> unexpected json payload at /Water/stop:" + message);
}
}
if(topic === EspDeviceName + "/ping"){
try {
console.log("MQTT> processing /ping message. Payload:" + context);
var data = context.replace(/^\{|\}$/g, '').split('|');
var ip = data[4].replace(/"/g, '');
console.log("got reporded garden controller IP: " + ip);
console.log("MQTT> /ping got us " + data.length + "data items");
config.gardenIP = ip;
// Make a copy of config and change that
let newConfig = Object.assign({}, config);
newConfig.gardenIP = ip;
// Write the new config back to the original file
fs.writeFileSync(configPath, JSON.stringify(newConfig, null, 2));
} catch (e) {
console.log("MQTT> error at /ping: " + e);
}
}
if (!handled) {
console.log(topic + " > " + message);