fix MQTT payloads being rejected when MQTT is connecting (fixes #369)

This commit is contained in:
proddy
2021-02-20 16:00:08 +01:00
parent 49ce35f1bf
commit 6f17013375
4 changed files with 19 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ See https://github.com/proddy/EMS-ESP/issues/632
- multiple roomcontrollers - multiple roomcontrollers
- readback after write with delay (give ems-devices time to set the value) - readback after write with delay (give ems-devices time to set the value)
- Thermostat ES72/RC20 device 66 to command-set RC20_2 - Thermostat ES72/RC20 device 66 to command-set RC20_2
- MQTT payloads not adding to queue when MQTT is re-connecting (fixes #369)
### Changed ### Changed
- split `show values` in smaller packages (edited) - 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` - check flowsensor for `tap_water_active`
- mqtt prefixed with `Base` - mqtt prefixed with `Base`
- count Dallas sensor fails - count Dallas sensor fails
- switch from SPIFFS to LITTLEFS
### Removed ### Removed

View File

@@ -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 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 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 // Home Assistant Discovery - the main master Device called EMS-ESP
@@ -560,6 +569,8 @@ std::shared_ptr<const MqttMessage> Mqtt::queue_message(const uint8_t operation,
message = std::make_shared<MqttMessage>(operation, full_topic, payload, retain); message = std::make_shared<MqttMessage>(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 the queue is full, make room but removing the last one
if (mqtt_messages_.size() >= MAX_MQTT_MESSAGES) { if (mqtt_messages_.size() >= MAX_MQTT_MESSAGES) {
mqtt_messages_.pop_front(); mqtt_messages_.pop_front();
@@ -580,7 +591,7 @@ std::shared_ptr<const MqttMessage> Mqtt::queue_message(const uint8_t operation,
// add MQTT message to queue, payload is a string // add MQTT message to queue, payload is a string
std::shared_ptr<const MqttMessage> Mqtt::queue_publish_message(const std::string & topic, const std::string & payload, bool retain) { std::shared_ptr<const MqttMessage> Mqtt::queue_publish_message(const std::string & topic, const std::string & payload, bool retain) {
if (!enabled() || !connecting_) { if (!enabled()) {
return nullptr; return nullptr;
}; };
return queue_message(Operation::PUBLISH, topic, payload, retain); return queue_message(Operation::PUBLISH, topic, payload, retain);

View File

@@ -138,6 +138,10 @@ class Mqtt {
return mqtt_enabled_; return mqtt_enabled_;
} }
static bool is_connecting() {
return connecting_;
}
static std::string base() { static std::string base() {
return mqtt_base_; return mqtt_base_;
} }

View File

@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.0.0b1" #define EMSESP_APP_VERSION "3.0.0b2"