Browse Source

MQTT reconnect delay based on last disconnection

refactor-terminal
Max Prokhorov 6 years ago
parent
commit
7e71c29bf9
1 changed files with 4 additions and 3 deletions
  1. +4
    -3
      code/espurna/mqtt.ino

+ 4
- 3
code/espurna/mqtt.ino View File

@ -51,6 +51,7 @@ char *_mqtt_clientid;
#if MQTT_SKIP_RETAINED
unsigned long _mqtt_connected_at = 0;
#endif
unsigned long _mqtt_disconnected_at = 0;
std::vector<mqtt_callback_f> _mqtt_callbacks;
@ -75,9 +76,7 @@ void _mqttConnect() {
if (_mqtt.connected()) return;
// Check reconnect interval
static unsigned long last = 0;
if (millis() - last < _mqtt_reconnect_delay) return;
last = millis();
if (millis() - _mqtt_disconnected_at < _mqtt_reconnect_delay) return;
// Increase the reconnect delay
_mqtt_reconnect_delay += MQTT_RECONNECT_DELAY_STEP;
@ -414,6 +413,8 @@ void _mqttOnConnect() {
void _mqttOnDisconnect() {
_mqtt_disconnected_at = millis();
DEBUG_MSG_P(PSTR("[MQTT] Disconnected!\n"));
// Send disconnect event to subscribers


Loading…
Cancel
Save