From 193802aae4658598881c103573caf72fb28861a5 Mon Sep 17 00:00:00 2001 From: fila612 Date: Mon, 18 Jul 2022 09:58:02 +0200 Subject: [PATCH] HASS - MQTT Retained Messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In #104 durch @KG3RK3N vorgeschlagen und von mir smoke-getestet. Scheint den gewünschten Erfolg zu bringen. --- tools/esp8266/app.cpp | 2 +- tools/esp8266/mqtt.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 38b75e6e..dbb3ee9e 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -930,7 +930,7 @@ void app::sendMqttDiscoveryConfig(void) { } serializeJson(doc, buffer); - mMqtt.sendMsg2(discoveryTopic, buffer); + mMqtt.sendMsg2(discoveryTopic, buffer, true); doc.clear(); yield(); diff --git a/tools/esp8266/mqtt.h b/tools/esp8266/mqtt.h index 853cd9ba..89570344 100644 --- a/tools/esp8266/mqtt.h +++ b/tools/esp8266/mqtt.h @@ -39,15 +39,15 @@ class mqtt { //DPRINTLN(DBG_VERBOSE, F("mqtt.h:sendMsg")); char top[64]; snprintf(top, 64, "%s/%s", mTopic, topic); - sendMsg2(top, msg); + sendMsg2(top, msg, false); } - void sendMsg2(const char *topic, const char *msg) { + void sendMsg2(const char *topic, const char *msg, boolean retained) { if(mAddressSet) { if(!mClient->connected()) reconnect(); if(mClient->connected()) - mClient->publish(topic, msg); + mClient->publish(topic, msg, retained); } }