show mqtt disconnect error in log, on first connect only

This commit is contained in:
Proddy
2023-01-30 17:04:33 +01:00
parent 8f68163f90
commit d39d62c2f8
2 changed files with 6 additions and 2 deletions

View File

@@ -461,9 +461,11 @@ 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;
}
first_connect_attempted_ = true;
connecting_ = false;
if (reason == AsyncMqttClientDisconnectReason::TCP_DISCONNECTED) {
LOG_WARNING("MQTT disconnected: TCP");

View File

@@ -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_;