Skip to content

Commit b8be6bd

Browse files
committed
add default packetread timeout of 100ms and allow overrides
1 parent 882680d commit b8be6bd

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

AdafruitIO.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ AdafruitIO::AdafruitIO(const char *user, const char *key)
1616
_throttle_topic = 0;
1717
_err_sub = 0;
1818
_throttle_sub = 0;
19+
_packetread_timeout = 100;
1920

2021
_init();
2122
}
@@ -29,6 +30,7 @@ AdafruitIO::AdafruitIO(const __FlashStringHelper *user, const __FlashStringHelpe
2930
_throttle_topic = 0;
3031
_err_sub = 0;
3132
_throttle_sub = 0;
33+
_packetread_timeout = 100;
3234

3335
_init();
3436
}
@@ -159,7 +161,10 @@ void AdafruitIO::run(uint16_t busywait_ms)
159161
// loop until we have a connection
160162
while(mqttStatus() != AIO_CONNECTED){}
161163

162-
_mqtt->processPackets(busywait_ms);
164+
if(busywait_ms > 0)
165+
_packetread_timeout = busywait_ms;
166+
167+
_mqtt->processPackets(_packetread_timeout);
163168

164169
// ping to keep connection alive if needed
165170
if(millis() > (_last_ping + AIO_PING_INTERVAL)) {

AdafruitIO.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AdafruitIO {
3333

3434
void connect();
3535

36-
void run(uint16_t busywait_ms = 100);
36+
void run(uint16_t busywait_ms = 0);
3737

3838
AdafruitIO_Feed* feed(const char *name);
3939
AdafruitIO_Feed* feed(const __FlashStringHelper *name);
@@ -50,8 +50,12 @@ class AdafruitIO {
5050
uint32_t _last_ping = 0;
5151

5252
Adafruit_MQTT *_mqtt;
53+
5354
const char *_host = "io.adafruit.com";
5455
uint16_t _port = 8883;
56+
57+
uint16_t _packetread_timeout;
58+
5559
const char *_username;
5660
const char *_key;
5761

AdafruitIO_FONA.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ AdafruitIO_FONA::AdafruitIO_FONA(const char *user, const char *key):AdafruitIO(u
1414
_serial = new SoftwareSerial(FONA_TX, FONA_RX);
1515
_fona = new Adafruit_FONA(FONA_RST);
1616
_mqtt = new Adafruit_MQTT_FONA(_fona, _host, _port);
17+
_packetread_timeout = 1000;
1718
}
1819

1920
AdafruitIO_FONA::AdafruitIO_FONA(const __FlashStringHelper *user, const __FlashStringHelper *key):AdafruitIO(user, key)
2021
{
2122
_serial = new SoftwareSerial(FONA_TX, FONA_RX);
2223
_fona = new Adafruit_FONA(FONA_RST);
2324
_mqtt = new Adafruit_MQTT_FONA(_fona, _host, _port);
25+
_packetread_timeout = 1000;
2426
}
2527

2628
void AdafruitIO_FONA::setAPN(FONAFlashStringPtr apn, FONAFlashStringPtr username=0, FONAFlashStringPtr password=0)

0 commit comments

Comments
 (0)