From ad2327047341e6126a8198c96fc5ff32fcab4a1e Mon Sep 17 00:00:00 2001 From: Gbradel Date: Thu, 28 Jun 2018 12:46:25 +0200 Subject: [PATCH] Fix Mqtt onlinemode bug --- src/core/CoolBoard.cpp | 6 ++++++ src/core/CoolBoard.h | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/CoolBoard.cpp b/src/core/CoolBoard.cpp index fa28a8d3..61670896 100644 --- a/src/core/CoolBoard.cpp +++ b/src/core/CoolBoard.cpp @@ -516,12 +516,18 @@ void CoolBoard::mqttConnect() { if (this->coolPubSubClient->connect(this->mqttId.c_str())) { this->coolPubSubClient->subscribe(this->mqttInTopic.c_str()); INFO_LOG("Subscribed to MQTT input topic"); + mqttRetries = 0; } else { WARN_LOG("MQTT connection failed, retrying"); + mqttRetries++; } delay(5); i++; } + if (mqttRetries >= MAX_MQTT_RETRIES) { + SPIFFS.end(); + ESP.restart(); + } } void CoolBoard::mqttLog(String data) { diff --git a/src/core/CoolBoard.h b/src/core/CoolBoard.h index 483272fe..ecde8fb3 100644 --- a/src/core/CoolBoard.h +++ b/src/core/CoolBoard.h @@ -41,10 +41,11 @@ #define ENABLE_I2C_PIN 5 #define BOOTSTRAP_PIN 0 -#define MQTT_RETRIES 5 #define MIN_BAT_VOLTAGE 3.5 #define NOT_IN_CHARGING 1.8 #define LOW_POWER_SLEEP 300 +#define MQTT_RETRIES 5 +#define MAX_MQTT_RETRIES 15 class CoolBoard { @@ -86,6 +87,7 @@ class CoolBoard { void mqttLog(String data); private: + uint8_t mqttRetries = 0; CoolBoardSensors coolBoardSensors; CoolBoardLed coolBoardLed; CoolWifi *coolWifi = new CoolWifi;