From 7f4498c0626e9095115040421eb1fed953ec2982 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Sat, 19 Feb 2022 10:32:23 +0100 Subject: [PATCH] Send system values to MQTT on regular interval --- src/AmsToMqttBridge.ino | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index b27d041f..0222a7b4 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -367,6 +367,7 @@ bool longPressActive = false; bool wifiConnected = false; unsigned long lastTemperatureRead = 0; +unsigned long lastSysupdate = 0; unsigned long lastErrorBlink = 0; int lastError = 0; @@ -550,6 +551,12 @@ void loop() { } debugD("Used %d ms to update temperature", millis()-start); } + if(now - lastSysupdate > 10000) { + if(mqtt != NULL && mqttHandler != NULL && WiFi.getMode() != WIFI_AP && WiFi.status() == WL_CONNECTED && mqtt->connected() && !topic.isEmpty()) { + mqttHandler->publishSystem(&hw); + } + lastSysupdate = now; + } } delay(1); // Needed for auto modem sleep #if defined(ESP32) @@ -899,16 +906,6 @@ bool readHanPort() { if(mqttHandler->publish(&data, &meterState, &ea)) { mqtt->loop(); delay(10); - if(data.getListType() == 3 && eapi != NULL) { - mqttHandler->publishPrices(eapi); - mqtt->loop(); - delay(10); - } - if(data.getListType() >= 2) { - mqttHandler->publishSystem(&hw); - mqtt->loop(); - delay(10); - } } }