From 11da97477260a3894be0bdb62c2c83a5e48ff944 Mon Sep 17 00:00:00 2001 From: lumapu Date: Sun, 6 Nov 2022 20:16:09 +0100 Subject: [PATCH] fix #397 MQTT reports zero values fix #397 remove "not producing" if not yet available for MQTT and HTML --- tools/esp8266/app.cpp | 54 ++++++++++++++++++----------------- tools/esp8266/html/index.html | 12 ++++---- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 52f22f43..4889e892 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -612,10 +612,10 @@ void app::sendMqtt(void) { } snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available_text", iv->name); snprintf(val, 32, "%s%s%s%s", - (MQTT_STATUS_NOT_AVAIL_NOT_PROD) ? "not " : "", + (MQTT_STATUS_NOT_AVAIL_NOT_PROD) ? "not yet " : "", "available and ", - (MQTT_STATUS_NOT_AVAIL_NOT_PROD || MQTT_STATUS_AVAIL_NOT_PROD) ? "not " : "", - "producing" + (MQTT_STATUS_AVAIL_NOT_PROD) ? "not " : "", + (MQTT_STATUS_NOT_AVAIL_NOT_PROD) ? "" : "producing" ); mMqtt.sendMsg(topic, val); @@ -629,32 +629,34 @@ void app::sendMqtt(void) { } // data - for (uint8_t i = 0; i < rec->length; i++) { - snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", iv->name, rec->assign[i].ch, fields[rec->assign[i].fieldId]); - snprintf(val, 10, "%.3f", iv->getValue(i, rec)); - mMqtt.sendMsg(topic, val); - - // calculate total values for RealTimeRunData_Debug - if (mMqttSendList.front() == RealTimeRunData_Debug) { - if (CH0 == rec->assign[i].ch) { - switch (rec->assign[i].fieldId) { - case FLD_PAC: - total[0] += iv->getValue(i, rec); - break; - case FLD_YT: - total[1] += iv->getValue(i, rec); - break; - case FLD_YD: - total[2] += iv->getValue(i, rec); - break; - case FLD_PDC: - total[3] += iv->getValue(i, rec); - break; + if(iv->isAvailable(mUtcTimestamp, rec)) { + for (uint8_t i = 0; i < rec->length; i++) { + snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", iv->name, rec->assign[i].ch, fields[rec->assign[i].fieldId]); + snprintf(val, 10, "%.3f", iv->getValue(i, rec)); + mMqtt.sendMsg(topic, val); + + // calculate total values for RealTimeRunData_Debug + if (mMqttSendList.front() == RealTimeRunData_Debug) { + if (CH0 == rec->assign[i].ch) { + switch (rec->assign[i].fieldId) { + case FLD_PAC: + total[0] += iv->getValue(i, rec); + break; + case FLD_YT: + total[1] += iv->getValue(i, rec); + break; + case FLD_YD: + total[2] += iv->getValue(i, rec); + break; + case FLD_PDC: + total[3] += iv->getValue(i, rec); + break; + } } + sendTotal = true; } - sendTotal = true; + yield(); } - yield(); } } diff --git a/tools/esp8266/html/index.html b/tools/esp8266/html/index.html index 8b8157b4..2e37ace9 100644 --- a/tools/esp8266/html/index.html +++ b/tools/esp8266/html/index.html @@ -153,11 +153,13 @@ for(var i of obj) { html += "Inverter #" + i["id"] + ": " + i["name"] + " (v" + i["version"] + ") is "; if(false == i["is_avail"]) - html += "not "; - html += "available and is "; - if(false == i["is_producing"]) - html += "not "; - html += "producing\n"; + html += "not yet available"; + else { + html += "available and is "; + if(false == i["is_producing"]) + html += "not "; + html += "producing\n"; + } if(false == i["is_avail"]) { if(i["ts_last_success"] > 0) {