@@ -32,14 +32,6 @@ void setup() {
32
32
33
33
Serial.print (" Connecting to Adafruit IO" );
34
34
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
35
// start MQTT connection to io.adafruit.com
44
36
io.connect ();
45
37
@@ -52,12 +44,23 @@ void setup() {
52
44
// wait for an MQTT connection
53
45
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
54
46
// method to check on MQTT connection status specifically
55
-
56
47
while (io.mqttStatus () < AIO_CONNECTED) {
57
48
Serial.print (" ." );
58
49
delay (500 );
59
50
}
60
51
52
+ // Because Adafruit IO doesn't support the MQTT retain flag, we can use the
53
+ // get() function to ask IO to resend the last value for this feed to just
54
+ // this MQTT client.
55
+ //
56
+ // Behind the scenes, the library is MQTT publishing an empty message to the
57
+ // {username}/f/counter/csv/get topic to trigger a resend on the
58
+ // {username}/f/counter/csv topic that this client is already subscribed to.
59
+ // That means calling get() will cause the handleMessage function we attached
60
+ // to this feed to be called with the most recent data record published to
61
+ // the feed.
62
+ counter->get ();
63
+
61
64
// we are connected
62
65
Serial.println ();
63
66
Serial.println (io.statusText ());
0 commit comments