Send system values to MQTT on regular interval

This commit is contained in:
Gunnar Skjold
2022-02-19 10:32:23 +01:00
parent 1f03013c98
commit 7f4498c062

View File

@@ -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);
}
}
}