diff --git a/src/mqtt.cpp b/src/mqtt.cpp index bf6f519ee..c1cd5e63b 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -280,6 +280,9 @@ void Mqtt::on_connect() { publish("info", doc, false); // send with retain off publish("status", "online", true); // say we're alive to the Last Will topic, with retain on + + reset_publish_fails(); // reset fail count to 0 + LOG_INFO(F("MQTT connected")); } diff --git a/src/mqtt.h b/src/mqtt.h index 5a066833c..6fe18ef1c 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -69,7 +69,7 @@ class Mqtt { enum Operation { PUBLISH, SUBSCRIBE }; - static constexpr uint8_t MQTT_TOPIC_MAX_SIZE = 60; // include host and base etc + static constexpr uint8_t MQTT_TOPIC_MAX_SIZE = 60; // are static to be accessed from EMS devices static void subscribe(const uint8_t device_id, const std::string & topic, mqtt_function_p cb); @@ -108,6 +108,10 @@ class Mqtt { return mqtt_publish_fails_; } + static void reset_publish_fails() { + mqtt_publish_fails_ = 0; + } + private: static uuid::log::Logger logger_; @@ -156,6 +160,7 @@ class Mqtt { std::string topic_; mqtt_function_p mqtt_function_; }; + static std::vector mqtt_functions_; // list of mqtt callbacks for all devices uint32_t last_mqtt_poll_ = 0; @@ -165,7 +170,7 @@ class Mqtt { static std::string hostname_; static uint8_t mqtt_qos_; static uint16_t publish_time_; -}; // namespace emsesp +}; } // namespace emsesp