mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
show mqtt disconnect error in log, on first connect only
This commit is contained in:
@@ -461,9 +461,11 @@ void Mqtt::start() {
|
|||||||
mqttClient_->onConnect([this](bool sessionPresent) { on_connect(); });
|
mqttClient_->onConnect([this](bool sessionPresent) { on_connect(); });
|
||||||
|
|
||||||
mqttClient_->onDisconnect([this](AsyncMqttClientDisconnectReason reason) {
|
mqttClient_->onDisconnect([this](AsyncMqttClientDisconnectReason reason) {
|
||||||
if (!connecting_) {
|
// only show the error once, not every 2 seconds
|
||||||
|
if (!connecting_ && first_connect_attempted_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
first_connect_attempted_ = true;
|
||||||
connecting_ = false;
|
connecting_ = false;
|
||||||
if (reason == AsyncMqttClientDisconnectReason::TCP_DISCONNECTED) {
|
if (reason == AsyncMqttClientDisconnectReason::TCP_DISCONNECTED) {
|
||||||
LOG_WARNING("MQTT disconnected: TCP");
|
LOG_WARNING("MQTT disconnected: TCP");
|
||||||
|
|||||||
@@ -297,6 +297,8 @@ class Mqtt {
|
|||||||
uint32_t last_publish_heartbeat_ = 0;
|
uint32_t last_publish_heartbeat_ = 0;
|
||||||
uint32_t last_publish_queue_ = 0;
|
uint32_t last_publish_queue_ = 0;
|
||||||
|
|
||||||
|
bool first_connect_attempted_ = false;
|
||||||
|
|
||||||
static bool connecting_;
|
static bool connecting_;
|
||||||
static bool initialized_;
|
static bool initialized_;
|
||||||
static uint32_t mqtt_publish_fails_;
|
static uint32_t mqtt_publish_fails_;
|
||||||
|
|||||||
Reference in New Issue
Block a user