File tree Expand file tree Collapse file tree 3 files changed +9
-14
lines changed Expand file tree Collapse file tree 3 files changed +9
-14
lines changed Original file line number Diff line number Diff line change @@ -168,18 +168,15 @@ const __FlashStringHelper* AdafruitIO::statusText()
168
168
aio_status_t AdafruitIO::run (uint16_t busywait_ms)
169
169
{
170
170
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 ();
177
174
}
178
175
179
176
// loop until we have a connection
180
177
// 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 () ;
183
180
184
181
if (busywait_ms > 0 )
185
182
_packetread_timeout = busywait_ms;
@@ -191,7 +188,7 @@ aio_status_t AdafruitIO::run(uint16_t busywait_ms)
191
188
_mqtt->ping ();
192
189
_last_ping = millis ();
193
190
}
194
- return _status ;
191
+ return status () ;
195
192
}
196
193
197
194
aio_status_t AdafruitIO::status ()
@@ -253,7 +250,7 @@ aio_status_t AdafruitIO::mqttStatus()
253
250
254
251
if (_mqtt->connected ())
255
252
return AIO_CONNECTED;
256
-
253
+
257
254
switch (_mqtt->connect (_username, _key)) {
258
255
case 0 :
259
256
return AIO_CONNECTED;
Original file line number Diff line number Diff line change 12
12
#ifndef ADAFRUITIO_H
13
13
#define ADAFRUITIO_H
14
14
15
- #ifndef ADAFRUITIO_RUN_TIMEOUT
16
- #define ADAFRUITIO_RUN_TIMEOUT 60000
17
- #endif
18
-
19
15
#include " Arduino.h"
20
16
#include " Adafruit_MQTT.h"
21
17
#include " AdafruitIO_Definitions.h"
Original file line number Diff line number Diff line change @@ -72,6 +72,8 @@ class AdafruitIOGroupCallback {
72
72
#define AIO_PING_INTERVAL 60000
73
73
// Time to wait between re-connecting to Adafruit IO after throttled
74
74
#define AIO_THROTTLE_RECONNECT_INTERVAL 60000
75
+ // Time to wait for a successful reconnection of MQTT
76
+ #define AIO_MQTT_CONNECTION_TIMEOUT 60000
75
77
76
78
#define AIO_ERROR_TOPIC " /errors"
77
79
#define AIO_THROTTLE_TOPIC " /throttle"
You can’t perform that action at this time.
0 commit comments