From a5b0b2b1136e88b3cbaafe2461a89c6455ff8be3 Mon Sep 17 00:00:00 2001 From: Florian Weber Date: Sun, 15 Dec 2024 16:45:37 +0000 Subject: [PATCH] add some logging informations and added function that solarumschichtung does not switch on if the woodstove is active --- docker-compose.yml | 2 -- nodeApp/config.json | 21 +++++++++---- nodeApp/index.js | 77 +++++++++++++++++++++++++++++++++++---------- 3 files changed, 75 insertions(+), 25 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index ef654d3..7936b48 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3' - services: influxdb: image: influxdb:2.7-alpine diff --git a/nodeApp/config.json b/nodeApp/config.json index ba7691b..c67e9ff 100644 --- a/nodeApp/config.json +++ b/nodeApp/config.json @@ -190,12 +190,21 @@ "Notumschichtung": { "Temperaturlabel": "PufferHeizraumTemperatur5", "Ton": 70.0, - "Toff": 65.0, - "mqtt": { - "ctrlTopic": "RelaisUmschichtung/cmnd/POWER1", - "msgOn": "ON", - "msgOff": "OFF" - } + "Toff": 65.0 + }, + "mqtt": { + "ctrlTopic": "RelaisUmschichtung/cmnd/POWER1", + "msgOn": "ON", + "msgOff": "OFF" + }, + "Differenzregelung": { + "QuelltemperaturLabel": "PufferHeizraumTemperatur3", + "ZieltemperaturLabel": "PufferHolzraumTemperatur1", + "dTon": 2.0, + "dToff": 1.0 + }, + "FreigabeHolzofen":{ + "KesselstatusAus": 43 } } } \ No newline at end of file diff --git a/nodeApp/index.js b/nodeApp/index.js index b7b44b9..07b8210 100644 --- a/nodeApp/index.js +++ b/nodeApp/index.js @@ -29,7 +29,7 @@ let configuredInputs = {}; // use socket.on('open', ...) when using serialport socket.on('connect', function () { - // make some calls + console.log("socket connected starting interval timer"); setInterval(() => { requestTemps(); }, config.interval); @@ -44,8 +44,11 @@ fs.readFile('config.json', function (err, data) { configuredInputs.forEach(element => { inputValues[element.label] = { value: null, synced: false, unitConversionDivider: 1 }; }); + console.log("config read"); + console.log("now connecting to influxdb"); influxClient = new InfluxDB({ url: influxUrl, token: config.influxToken }); influxWriteClient = influxClient.getWriteApi(influxOrg, influxBucket, 'ms'); + console.log("connected to influxdb, now trying to connect to modbus tcp and mqtt"); socket.connect(options); mqttClient = mqtt.connect(config.mqttBrokerAddress, { username: config.mqttUser, @@ -115,17 +118,17 @@ async function writeToInflux() { for (const key in inputValues) { if (Object.hasOwnProperty.call(inputValues, key)) { let point = new Point('CF2').floatField(key, inputValues[key].value); - influxWriteClient.writePoint(point); - influxWriteClient.flush(); + influxWriteClient.writePoint(point); } } + influxWriteClient.flush(); } async function sendMQTT(topic, msg) { - let notumschichtung = config.UmschichtungSolar.Notumschichtung + let mqttConfig = config.UmschichtungSolar.mqtt; if (typeof mqttClient !== 'undefined' || mqttClient !== null) { if (mqttClient.connected) { mqttClient.publish(topic, msg, { retain: true }); - console.log(msg); + //console.log(msg); } else { console.log("client not connected to the mqtt broker"); } @@ -135,28 +138,68 @@ async function sendMQTT(topic, msg) { //send status over mqtt let val = 0.0; - if (msg == notumschichtung.mqtt.msgOn) { + if (msg == mqttConfig.msgOn) { val = 100.0; - } else if (msg == notumschichtung.mqtt.msgOff) { + } else if (msg == mqttConfig.msgOff) { val = 0.0; } let point = new Point('Solarumschichtung').floatField("pumpePercent", val); influxWriteClient.writePoint(point); influxWriteClient.flush(); } - +let outputRegler1 = false; +let outputRegler2 = false; async function calculateLogic() { - let notumschichtung = config.UmschichtungSolar.Notumschichtung - let temp = inputValues[notumschichtung.Temperaturlabel]; - let topic = notumschichtung.mqtt.ctrlTopic; - let msgOn = notumschichtung.mqtt.msgOn; - let msgOff = notumschichtung.mqtt.msgOff; - let Ton = notumschichtung.Ton; - let Toff = notumschichtung.Toff; + //Notumschichtung regler 1 + let umschichtungSolar = config.UmschichtungSolar; + let notumschichtung = umschichtungSolar.Notumschichtung + let temptNotumschichtung = inputValues[notumschichtung.Temperaturlabel].value; + let TonNotumschichtung = notumschichtung.Ton; + let ToffNotumschichtung = notumschichtung.Toff; + + //mqtt relais + //console.log(umschichtungSolar); + let topic = umschichtungSolar.mqtt.ctrlTopic; + + let msgOn = umschichtungSolar.mqtt.msgOn; + let msgOff = umschichtungSolar.mqtt.msgOff; + + //Differenzregelung + let differenzregelung = umschichtungSolar.Differenzregelung + let quellTemperatur = inputValues[differenzregelung.QuelltemperaturLabel].value; + let zielTemperatur = inputValues[differenzregelung.ZieltemperaturLabel].value; + let dTon = differenzregelung.dTon; + let dToff = differenzregelung.dToff; - if (temp.value >= Ton) { + //Freigabe Holzofen + let kesselstatus = inputValues["Kesselstatus"].value; + let freigabeHolzofen = kesselstatus === umschichtungSolar.FreigabeHolzofen.KesselstatusAus ? true : false; + + if (temptNotumschichtung >= TonNotumschichtung) { + outputRegler1 = true; + + } else if (temptNotumschichtung <= ToffNotumschichtung) { + outputRegler1 = false; + } + + let diff = quellTemperatur - zielTemperatur; + if(diff >= dTon){ + outputRegler2 = true; + }else if (diff <= dToff) { + outputRegler2 = false; + } + + let point = new Point('Solarumschichtung').floatField("regler1", outputRegler1 ? 100.0 : 0.0); + influxWriteClient.writePoint(point); + point = new Point('Solarumschichtung').floatField("regler2", outputRegler2 ? 100.0 : 0.0); + influxWriteClient.writePoint(point); + point = new Point('Solarumschichtung').floatField("freigabeHolzofen", freigabeHolzofen ? 100.0 : 0.0); + influxWriteClient.writePoint(point); + influxWriteClient.flush(); + + if(freigabeHolzofen && outputRegler1 && outputRegler2){ sendMQTT(topic, msgOn); - } else if (temp.value <= Toff) { + }else{ sendMQTT(topic, msgOff); } }