File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
examples/adafruitio_01_subscribe Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,15 @@ void setup() {
32
32
33
33
Serial.print (" Connecting to Adafruit IO" );
34
34
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
36
44
io.connect ();
37
45
38
46
// set up a message handler for the count feed.
@@ -41,8 +49,11 @@ void setup() {
41
49
// received from adafruit io.
42
50
counter->onMessage (handleMessage);
43
51
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) {
46
57
Serial.print (" ." );
47
58
delay (500 );
48
59
}
You can’t perform that action at this time.
0 commit comments