From e2d193e591a95399283976578cb15ce5dd8a2a6a Mon Sep 17 00:00:00 2001 From: "Sandner, Denny" Date: Sun, 18 Sep 2022 13:37:28 +0200 Subject: [PATCH 1/2] =?UTF-8?q?#288=20MQTT=20Topic=20L=C3=A4nge=20zu=20kur?= =?UTF-8?q?z?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/esp8266/app.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index c72983e4..eb2c9e39 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -390,7 +390,7 @@ void app::processPayload(bool retransmit) { // MQTT send out if(mMqttActive) { record_t<> *recRealtime = iv->getRecordStruct(RealTimeRunData_Debug); - char topic[30], val[10]; + char topic[32 + MAX_NAME_LENGTH], val[10]; float total[4]; memset(total, 0, sizeof(float) * 4); for (uint8_t id = 0; id < mSys->getNumInverters(); id++) { @@ -398,7 +398,7 @@ void app::processPayload(bool retransmit) { if (NULL != iv) { if (iv->isAvailable(mTimestamp, rec)) { for (uint8_t i = 0; i < rec->length; i++) { - snprintf(topic, 30, "%s/ch%d/%s", iv->name, rec->assign[i].ch, fields[rec->assign[i].fieldId]); + 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); if(recRealtime == rec) { @@ -428,7 +428,7 @@ void app::processPayload(bool retransmit) { case 2: fieldId = FLD_YD; break; case 3: fieldId = FLD_PDC; break; } - snprintf(topic, 30, "total/%s", fields[fieldId]); + snprintf(topic, 32 + MAX_NAME_LENGTH, "total/%s", fields[fieldId]); snprintf(val, 10, "%.3f", total[i]); mMqtt.sendMsg(topic, val); } From 96d397e8a9902c4fc3ab90cb61033c77cc0d0480 Mon Sep 17 00:00:00 2001 From: "Sandner, Denny" Date: Sun, 18 Sep 2022 18:45:28 +0200 Subject: [PATCH 2/2] =?UTF-8?q?#268=20Statusausgabe=20=C3=BCber=20MQTT=20r?= =?UTF-8?q?ealisiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/esp8266/app.cpp | 41 ++++++++++++++++++++++++++++++++++++++--- tools/esp8266/config.h | 5 +++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index eb2c9e39..62636ff0 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -390,7 +390,7 @@ void app::processPayload(bool retransmit) { // MQTT send out if(mMqttActive) { record_t<> *recRealtime = iv->getRecordStruct(RealTimeRunData_Debug); - char topic[32 + MAX_NAME_LENGTH], val[10]; + char topic[32 + MAX_NAME_LENGTH], val[32]; float total[4]; memset(total, 0, sizeof(float) * 4); for (uint8_t id = 0; id < mSys->getNumInverters(); id++) { @@ -411,10 +411,31 @@ void app::processPayload(bool retransmit) { } } } + + if(iv->isProducing(mTimestamp, rec)){ + snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available_text", iv->name); + snprintf(val, 32, DEF_MQTT_IV_MESSAGE_INVERTER_AVAIL_AND_PRODUCED); + mMqtt.sendMsg(topic, val); + snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available", iv->name); + snprintf(val, 32, "2"); + mMqtt.sendMsg(topic, val); + } else { + snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available_text", iv->name); + snprintf(val, 32, DEF_MQTT_IV_MESSAGE_INVERTER_AVAIL_AND_NOT_PRODUCED); + mMqtt.sendMsg(topic, val); + snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available", iv->name); + snprintf(val, 32, "1"); + mMqtt.sendMsg(topic, val); + } + + snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/last_success", iv->name); + snprintf(val, 48, "%i", iv->getLastTs(rec) * 1000); + mMqtt.sendMsg(topic, val); + yield(); } - } - } + } + } } // total values (sum of all inverters) @@ -446,6 +467,20 @@ void app::processPayload(bool retransmit) { #endif } } + + if(mMqttActive) { + record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug); + char topic[32 + MAX_NAME_LENGTH], val[32]; + if (!iv->isAvailable(mTimestamp, rec) && !iv->isProducing(mTimestamp, rec)){ + snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available_text", iv->name); + snprintf(val, 32, DEF_MQTT_IV_MESSAGE_NOT_AVAIL_AND_NOT_PRODUCED); + mMqtt.sendMsg(topic, val); + snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/available", iv->name); + snprintf(val, 32, "0"); + mMqtt.sendMsg(topic, val); + } + } + yield(); } } diff --git a/tools/esp8266/config.h b/tools/esp8266/config.h index 26ff32c5..99e0e16e 100644 --- a/tools/esp8266/config.h +++ b/tools/esp8266/config.h @@ -108,6 +108,11 @@ // default MQTT topic #define DEF_MQTT_TOPIC "inverter" +//default MQTT Message Inverter Status +#define DEF_MQTT_IV_MESSAGE_NOT_AVAIL_AND_NOT_PRODUCED "not available and not producing" // STATUS 0 +#define DEF_MQTT_IV_MESSAGE_INVERTER_AVAIL_AND_NOT_PRODUCED "available and not producing" // STATUS 1 +#define DEF_MQTT_IV_MESSAGE_INVERTER_AVAIL_AND_PRODUCED "available and producing" // STATUS 2 + #if __has_include("config_override.h") #include "config_override.h" #endif