1
- // Adafruit IO Time Subscription Example
1
+ // Adafruit IO Time Topic Subscription Example
2
2
//
3
3
// Adafruit invests time and resources providing this open source code.
4
4
// Please support Adafruit and open source hardware by purchasing
5
5
// products from Adafruit!
6
6
//
7
- // Written by Todd Treece for Adafruit Industries
8
- // Copyright (c) 2016 Adafruit Industries
7
+ // Written by Adam Bachman, Brent Rubell for Adafruit Industries
8
+ // Copyright (c) 2018 Adafruit Industries
9
9
// Licensed under the MIT license.
10
10
//
11
11
// All text above must be included in any redistribution.
22
22
// set up the 'time/seconds' topic
23
23
AdafruitIO_Time *seconds = io.time(AIO_TIME_SECONDS);
24
24
25
+ // set up the 'time/milliseconds' topic
26
+ AdafruitIO_Time *msecs = io.time(AIO_TIME_MILLIS);
27
+
28
+ // set up the 'time/ISO-8601' topic
29
+ AdafruitIO_Time *iso = io.time(AIO_TIME_ISO);
30
+
25
31
void setup () {
26
32
27
33
// start the serial connection
@@ -35,11 +41,14 @@ void setup() {
35
41
// start MQTT connection to io.adafruit.com
36
42
io.connect ();
37
43
38
- // set up a message handler for the count feed.
39
- // the handleMessage function (defined below)
40
- // will be called whenever a message is
41
- // received from adafruit io.
42
- seconds->onMessage (handleMessage);
44
+ // attach message handler for the seconds feed
45
+ seconds->onMessage (handleSecs);
46
+
47
+ // attach a message handler for the msecs feed
48
+ msecs->onMessage (handleMillis);
49
+
50
+ // attach a message handler for the ISO feed
51
+ iso->onMessage (handleISO);
43
52
44
53
// wait for an MQTT connection
45
54
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
@@ -63,17 +72,29 @@ void loop() {
63
72
// io.adafruit.com, and processes any incoming data.
64
73
io.run ();
65
74
75
+ delay (5 );
66
76
// Because this sketch isn't publishing, we don't need
67
77
// a delay() in the main program loop.
68
78
69
79
}
70
80
71
- // this function is called whenever a 'counter' message
72
- // is received from Adafruit IO. it was attached to
73
- // the counter feed in the setup() function above.
74
- void handleMessage (char *data, uint16_t len) {
75
81
76
- Serial.print (" received <- " );
82
+ // message handler for the seconds feed
83
+ void handleSecs (char *data, uint16_t len) {
84
+ Serial.print (" Seconds Feed: " );
77
85
Serial.println (data);
86
+ }
87
+
78
88
89
+ // message handler for the milliseconds feed
90
+ void handleMillis (char *data, uint16_t len) {
91
+ Serial.print (" Millis Feed: " );
92
+ Serial.println (data);
93
+ }
94
+
95
+
96
+ // message handler for the ISO-8601 feed
97
+ void handleISO (char *data, uint16_t len) {
98
+ Serial.print (" ISO Feed: " );
99
+ Serial.println (data);
79
100
}
0 commit comments