File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -168,18 +168,15 @@ const __FlashStringHelper* AdafruitIO::statusText()
168168aio_status_t AdafruitIO::run (uint16_t busywait_ms)
169169{
170170 uint32_t timeStart = millis ();
171- aio_status_t net_status = networkStatus ();
172- // If we aren't connected, return network status -- fail quickly
173- // Previous version would just hang on a network error
174- if (net_status != AIO_NET_CONNECTED) {
175- _status = net_status;
176- return _status;
171+ // If we aren't network connected, return status -- fail quickly
172+ if (status () < AIO_NET_CONNECTED) {
173+ return status ();
177174 }
178175
179176 // loop until we have a connection
180177 // mqttStatus() will try to reconnect before returning
181- while (mqttStatus () != AIO_CONNECTED && millis () - timeStart < ADAFRUITIO_RUN_TIMEOUT ){}
182- if (mqttStatus () != AIO_CONNECTED) return _status ;
178+ while (mqttStatus () != AIO_CONNECTED && millis () - timeStart < AIO_MQTT_CONNECTION_TIMEOUT ){}
179+ if (mqttStatus () != AIO_CONNECTED) return status () ;
183180
184181 if (busywait_ms > 0 )
185182 _packetread_timeout = busywait_ms;
@@ -191,7 +188,7 @@ aio_status_t AdafruitIO::run(uint16_t busywait_ms)
191188 _mqtt->ping ();
192189 _last_ping = millis ();
193190 }
194- return _status ;
191+ return status () ;
195192}
196193
197194aio_status_t AdafruitIO::status ()
@@ -253,7 +250,7 @@ aio_status_t AdafruitIO::mqttStatus()
253250
254251 if (_mqtt->connected ())
255252 return AIO_CONNECTED;
256-
253+
257254 switch (_mqtt->connect (_username, _key)) {
258255 case 0 :
259256 return AIO_CONNECTED;
Original file line number Diff line number Diff line change 1212#ifndef ADAFRUITIO_H
1313#define ADAFRUITIO_H
1414
15- #ifndef ADAFRUITIO_RUN_TIMEOUT
16- #define ADAFRUITIO_RUN_TIMEOUT 60000
17- #endif
18-
1915#include " Arduino.h"
2016#include " Adafruit_MQTT.h"
2117#include " AdafruitIO_Definitions.h"
Original file line number Diff line number Diff line change @@ -72,6 +72,8 @@ class AdafruitIOGroupCallback {
7272#define AIO_PING_INTERVAL 60000
7373// Time to wait between re-connecting to Adafruit IO after throttled
7474#define AIO_THROTTLE_RECONNECT_INTERVAL 60000
75+ // Time to wait for a successful reconnection of MQTT
76+ #define AIO_MQTT_CONNECTION_TIMEOUT 60000
7577
7678#define AIO_ERROR_TOPIC " /errors"
7779#define AIO_THROTTLE_TOPIC " /throttle"
You can’t perform that action at this time.
0 commit comments