From 6f17013375624210e196c619eedd2bf435c91290 Mon Sep 17 00:00:00 2001 From: proddy Date: Sat, 20 Feb 2021 16:00:08 +0100 Subject: [PATCH] fix MQTT payloads being rejected when MQTT is connecting (fixes #369) --- CHANGELOG_LATEST.md | 2 ++ src/mqtt.cpp | 13 ++++++++++++- src/mqtt.h | 4 ++++ src/version.h | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 0637551ee..ebac06e0e 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -14,6 +14,7 @@ See https://github.com/proddy/EMS-ESP/issues/632 - multiple roomcontrollers - readback after write with delay (give ems-devices time to set the value) - Thermostat ES72/RC20 device 66 to command-set RC20_2 +- MQTT payloads not adding to queue when MQTT is re-connecting (fixes #369) ### Changed - split `show values` in smaller packages (edited) @@ -21,6 +22,7 @@ See https://github.com/proddy/EMS-ESP/issues/632 - check flowsensor for `tap_water_active` - mqtt prefixed with `Base` - count Dallas sensor fails +- switch from SPIFFS to LITTLEFS ### Removed diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 8ad6ff8a9..b19dd057e 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -499,6 +499,15 @@ void Mqtt::on_connect() { publish_retain(F("status"), "online", true); // say we're alive to the Last Will topic, with retain on mqtt_publish_fails_ = 0; // reset fail count to 0 + + /* + // for debugging only + LOG_INFO("Queue size: %d", mqtt_messages_.size()); + for (const auto & message : mqtt_messages_) { + auto content = message.content_; + LOG_INFO(F(" [%02d] (%d) topic=%s payload=%s"), message.id_, content->operation, content->topic.c_str(), content->payload.c_str()); + } + */ } // Home Assistant Discovery - the main master Device called EMS-ESP @@ -560,6 +569,8 @@ std::shared_ptr Mqtt::queue_message(const uint8_t operation, message = std::make_shared(operation, full_topic, payload, retain); } + // LOG_INFO("Added to queue: %s %s", message->topic.c_str(), message->payload.c_str()); // debugging only + // if the queue is full, make room but removing the last one if (mqtt_messages_.size() >= MAX_MQTT_MESSAGES) { mqtt_messages_.pop_front(); @@ -580,7 +591,7 @@ std::shared_ptr Mqtt::queue_message(const uint8_t operation, // add MQTT message to queue, payload is a string std::shared_ptr Mqtt::queue_publish_message(const std::string & topic, const std::string & payload, bool retain) { - if (!enabled() || !connecting_) { + if (!enabled()) { return nullptr; }; return queue_message(Operation::PUBLISH, topic, payload, retain); diff --git a/src/mqtt.h b/src/mqtt.h index c760a767d..6abf6ff40 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -138,6 +138,10 @@ class Mqtt { return mqtt_enabled_; } + static bool is_connecting() { + return connecting_; + } + static std::string base() { return mqtt_base_; } diff --git a/src/version.h b/src/version.h index b1593a0b5..ae42691a6 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define EMSESP_APP_VERSION "3.0.0b1" +#define EMSESP_APP_VERSION "3.0.0b2"