Browse Source

Merge pull request #1456 from mcspr/mqtt-reconnect-delay

MQTT reconnect delay based on last disconnection
refactor-terminal
Xose Pérez 5 years ago
committed by GitHub
parent
commit
2cd80ca32e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
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