From e76722ad335c2e6765549657a331491249ff858c Mon Sep 17 00:00:00 2001 From: lumapu Date: Thu, 11 Apr 2024 21:34:05 +0200 Subject: [PATCH] 0.8.110 * add disable retain flag #1582 --- src/CHANGES.md | 2 ++ src/config/settings.h | 4 ++++ src/publisher/pubMqtt.h | 3 +++ src/web/RestApi.h | 1 + src/web/html/setup.html | 9 +++++++-- src/web/lang.json | 5 +++++ src/web/web.h | 1 + 7 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index 29a3fb41c..1ad0ee1e0 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -2,6 +2,8 @@ ## 0.8.110 - 2024-04-11 * revert CMT2300A changes #1553 +* merged PR: fix closing tag #1584 +* add disable retain flag #1582 ## 0.8.109 - 2024-04-09 * fix hal patch diff --git a/src/config/settings.h b/src/config/settings.h index 2d1d22298..e97519a1b 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -165,6 +165,7 @@ typedef struct { char pwd[MQTT_PWD_LEN]; char topic[MQTT_TOPIC_LEN]; uint16_t interval; + bool enableRetain; } cfgMqtt_t; typedef struct { @@ -490,6 +491,7 @@ class settings { snprintf(mCfg.mqtt.pwd, MQTT_PWD_LEN, "%s", DEF_MQTT_PWD); snprintf(mCfg.mqtt.topic, MQTT_TOPIC_LEN, "%s", DEF_MQTT_TOPIC); mCfg.mqtt.interval = 0; // off + mCfg.mqtt.enableRetain = true; mCfg.inst.sendInterval = SEND_INTERVAL; mCfg.inst.rstYieldMidNight = false; @@ -746,6 +748,7 @@ class settings { obj[F("pwd")] = mCfg.mqtt.pwd; obj[F("topic")] = mCfg.mqtt.topic; obj[F("intvl")] = mCfg.mqtt.interval; + obj[F("retain")] = mCfg.mqtt.enableRetain; } else { getVal(obj, F("port"), &mCfg.mqtt.port); @@ -755,6 +758,7 @@ class settings { getChar(obj, F("clientId"), mCfg.mqtt.clientId, MQTT_CLIENTID_LEN); getChar(obj, F("pwd"), mCfg.mqtt.pwd, MQTT_PWD_LEN); getChar(obj, F("topic"), mCfg.mqtt.topic, MQTT_TOPIC_LEN); + getVal(obj, F("retain"), &mCfg.mqtt.enableRetain); } } diff --git a/src/publisher/pubMqtt.h b/src/publisher/pubMqtt.h index 91227c05a..8506a87cf 100644 --- a/src/publisher/pubMqtt.h +++ b/src/publisher/pubMqtt.h @@ -205,6 +205,9 @@ class PubMqtt { else snprintf(mTopic.data(), mTopic.size(), "%s", subTopic); + if(!mCfgMqtt->enableRetain) + retained = false; + mClient.publish(mTopic.data(), qos, retained, payload); yield(); mTxCnt++; diff --git a/src/web/RestApi.h b/src/web/RestApi.h index 1ed5d2047..968ea0e8b 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -710,6 +710,7 @@ class RestApi { obj[F("pwd")] = (strlen(mConfig->mqtt.pwd) > 0) ? F("{PWD}") : String(""); obj[F("topic")] = String(mConfig->mqtt.topic); obj[F("interval")] = String(mConfig->mqtt.interval); + obj[F("retain")] = (bool)mConfig->mqtt.enableRetain; } void getNtp(JsonObject obj) { diff --git a/src/web/html/setup.html b/src/web/html/setup.html index 122f54279..e0c1693a9 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -246,6 +246,10 @@ +
+
{#RETAIN}
+
+
@@ -282,7 +286,7 @@
{#DISP_LUMINANCE}
-
+

{#DISP_PINOUT}

@@ -291,7 +295,7 @@

{#GRAPH_OPTIONS}

{#GRAPH_SHOW_RATIO}
-
+
@@ -922,6 +926,7 @@ function parseMqtt(obj) { for(var i of [["Addr", "broker"], ["Port", "port"], ["ClientId", "clientId"], ["User", "user"], ["Pwd", "pwd"], ["Topic", "topic"], ["Interval", "interval"]]) document.getElementsByName("mqtt"+i[0])[0].value = obj[i[1]]; + document.getElementsByName("retain")[0].checked = obj.retain } function parseNtp(obj) { diff --git a/src/web/lang.json b/src/web/lang.json index ff0062ee5..42669e288 100644 --- a/src/web/lang.json +++ b/src/web/lang.json @@ -413,6 +413,11 @@ "en": "Send Inverter data in a fixed interval, even if there is no change. A value of '0' disables the fixed interval. The data is published once it was successfully received from inverter. (default: 0)", "de": "Wechselrichterdaten in fixem Intervall schicken, auch wenn es keine Änderung gab. Ein Wert von '0' deaktiviert das fixe Intervall, die Wechselrichterdaten werden übertragen, sobald neue zur Verfügung stehen. (Standard: 0)" }, + { + "token": "RETAIN", + "en": "enable retain flag", + "de": "'Retain Flag' aktivieren" + }, { "token": "DISPLAY_CONFIG", "en": "Display Config", diff --git a/src/web/web.h b/src/web/web.h index e88aa813f..7b73fe9f9 100644 --- a/src/web/web.h +++ b/src/web/web.h @@ -583,6 +583,7 @@ class Web { request->arg("mqttTopic").toCharArray(mConfig->mqtt.topic, MQTT_TOPIC_LEN); mConfig->mqtt.port = request->arg("mqttPort").toInt(); mConfig->mqtt.interval = request->arg("mqttInterval").toInt(); + mConfig->mqtt.enableRetain = (request->arg("retain") == "on"); // serial console mConfig->serial.debug = (request->arg("serDbg") == "on");