Skip to content

Commit f957b91

Browse files
committed
add feed->lastValue example to adafruitio_01_subscribe sketch
1 parent cea44d3 commit f957b91

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

examples/adafruitio_01_subscribe/adafruitio_01_subscribe.ino

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ void setup() {
3232

3333
Serial.print("Connecting to Adafruit IO");
3434

35-
// connect to io.adafruit.com
35+
// because Adafruit IO doesn't support the MQTT
36+
// retain flag right now, we need to load the
37+
// last value for the "counter" feed manually and
38+
// send it our handleMessage function
39+
if (counter->exists()) {
40+
handleMessage(counter->lastValue());
41+
}
42+
43+
// start MQTT connection to io.adafruit.com
3644
io.connect();
3745

3846
// set up a message handler for the count feed.
@@ -41,8 +49,11 @@ void setup() {
4149
// received from adafruit io.
4250
counter->onMessage(handleMessage);
4351

44-
// wait for a connection
45-
while(io.status() < AIO_CONNECTED) {
52+
// wait for an MQTT connection
53+
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
54+
// method to check on MQTT connection status specifically
55+
56+
while(io.mqttStatus() < AIO_CONNECTED) {
4657
Serial.print(".");
4758
delay(500);
4859
}

0 commit comments

Comments
 (0)