Skip to content

Commit f218bce

Browse files
committed
Limit max delay instead of the reconnection counter.
1 parent fb16d9a commit f218bce

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/ArduinoIoTCloudTCP.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,11 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectMqttBroker()
363363
return State::SubscribeMqttTopics;
364364
}
365365

366-
static unsigned long const RECONNECTION_RETRY_DELAY_ms = 1000;
367-
_last_connection_attempt_cnt = min(_last_connection_attempt_cnt + 1, 5);
368-
_next_connection_attempt_tick = millis() + pow(2, _last_connection_attempt_cnt) * RECONNECTION_RETRY_DELAY_ms;
366+
static unsigned long const RECONNECTION_RETRY_DELAY_ms = 1000;
367+
static unsigned long const MAX_RECONNECTION_RETRY_DELAY_ms = 32000;
368+
_last_connection_attempt_cnt++;
369+
unsigned long const reconnection_retry_delay = min(MAX_RECONNECTION_RETRY_DELAY_ms, pow(2, _last_connection_attempt_cnt) * RECONNECTION_RETRY_DELAY_ms);
370+
_next_connection_attempt_tick = millis() + reconnection_retry_delay;
369371

370372
DEBUG_ERROR("ArduinoIoTCloudTCP::%s could not connect to %s:%d", __FUNCTION__, _brokerAddress.c_str(), _brokerPort);
371373
return State::ConnectPhy;

0 commit comments

Comments
 (0)