Skip to content

Commit 5d0c2af

Browse files
committed
Revert "allow mqttStatus() to return without waiting for connection"
This reverts commit f3d1eb6.
1 parent e1a5233 commit 5d0c2af

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/AdafruitIO.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ char* AdafruitIO::userAgent()
230230

231231
aio_status_t AdafruitIO::mqttStatus()
232232
{
233-
static uint32_t lastTried = 0; // remember last attempt to connect
234-
// if the connection irretrievably failed,
233+
// if the connection failed,
235234
// return so we don't hammer IO
236235
if(_status == AIO_CONNECT_FAILED)
237236
{
@@ -249,12 +248,7 @@ aio_status_t AdafruitIO::mqttStatus()
249248

250249
if(_mqtt->connected())
251250
return AIO_CONNECTED;
252-
253-
// don't try to connect more often than the throttle interval
254-
if(lastTried != 0 && millis() < (lastTried + AIO_THROTTLE_RECONNECT_INTERVAL))
255-
return AIO_DISCONNECTED;
256251

257-
lastTried = millis();
258252
switch(_mqtt->connect(_username, _key)) {
259253
case 0:
260254
return AIO_CONNECTED;
@@ -266,6 +260,8 @@ aio_status_t AdafruitIO::mqttStatus()
266260
case 3: // mqtt service unavailable
267261
case 6: // throttled
268262
case 7: // banned -> all MQTT bans are temporary, so eventual retry is permitted
263+
// delay to prevent fast reconnects
264+
delay(AIO_THROTTLE_RECONNECT_INTERVAL);
269265
return AIO_DISCONNECTED;
270266
default:
271267
return AIO_DISCONNECTED;

0 commit comments

Comments
 (0)