Browse Source

Force WiFi reconnect after MQTT_MAX_TRIES

fastled
Xose Pérez 7 years ago
parent
commit
4b301d6620
2 changed files with 18 additions and 0 deletions
  1. +2
    -0
      code/espurna/config/general.h
  2. +16
    -0
      code/espurna/mqtt.ino

+ 2
- 0
code/espurna/config/general.h View File

@ -102,6 +102,8 @@
#define MQTT_QOS 0 #define MQTT_QOS 0
#define MQTT_KEEPALIVE 30 #define MQTT_KEEPALIVE 30
#define MQTT_RECONNECT_DELAY 10000 #define MQTT_RECONNECT_DELAY 10000
#define MQTT_TRY_INTERVAL 30000
#define MQTT_MAX_TRIES 5
#define MQTT_SKIP_RETAINED 1 #define MQTT_SKIP_RETAINED 1
#define MQTT_SKIP_TIME 1000 #define MQTT_SKIP_TIME 1000
#define MQTT_ACTION_TOPIC "/action" #define MQTT_ACTION_TOPIC "/action"


+ 16
- 0
code/espurna/mqtt.ino View File

@ -139,6 +139,22 @@ void mqttConnect() {
if (!mqtt.connected()) { if (!mqtt.connected()) {
// Last option: reconnect to wifi after MQTT_MAX_TRIES attemps in a row
#if MQTT_MAX_TRIES > 0
static unsigned int tries = 0;
static unsigned long last_try = millis();
if (millis() - last_try < MQTT_TRY_INTERVAL) {
if (++tries > MQTT_MAX_TRIES) {
wifiDisconnect();
tries = 0;
return;
}
} else {
tries = 0;
}
last_try = millis();
#endif
mqtt.disconnect(); mqtt.disconnect();
char * host = strdup(getSetting("mqttServer", MQTT_SERVER).c_str()); char * host = strdup(getSetting("mqttServer", MQTT_SERVER).c_str());


Loading…
Cancel
Save