diff --git a/src/mqtt.cpp b/src/mqtt.cpp index e414daa1b..4cf6cb60e 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -461,10 +461,12 @@ void Mqtt::start() { mqttClient_->onConnect([this](bool sessionPresent) { on_connect(); }); mqttClient_->onDisconnect([this](AsyncMqttClientDisconnectReason reason) { - if (!connecting_) { + // only show the error once, not every 2 seconds + if (!connecting_ && first_connect_attempted_) { return; } - connecting_ = false; + first_connect_attempted_ = true; + connecting_ = false; if (reason == AsyncMqttClientDisconnectReason::TCP_DISCONNECTED) { LOG_WARNING("MQTT disconnected: TCP"); } else if (reason == AsyncMqttClientDisconnectReason::MQTT_IDENTIFIER_REJECTED) { diff --git a/src/mqtt.h b/src/mqtt.h index 16f607145..8de219c11 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -297,6 +297,8 @@ class Mqtt { uint32_t last_publish_heartbeat_ = 0; uint32_t last_publish_queue_ = 0; + bool first_connect_attempted_ = false; + static bool connecting_; static bool initialized_; static uint32_t mqtt_publish_fails_;