File tree Expand file tree Collapse file tree
examples/adafruitio_01_subscribe Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments