Skip to content

Commit 06caedb

Browse files
author
brentru
committed
example to subscribe to one of each time/ topic
1 parent c806c03 commit 06caedb

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

examples/adafruitio_17_time_subscribe/adafruitio_17_time_subscribe.ino

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// Adafruit IO Time Subscription Example
1+
// Adafruit IO Time Topic Subscription Example
22
//
33
// Adafruit invests time and resources providing this open source code.
44
// Please support Adafruit and open source hardware by purchasing
55
// products from Adafruit!
66
//
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
99
// Licensed under the MIT license.
1010
//
1111
// All text above must be included in any redistribution.
@@ -22,6 +22,12 @@
2222
// set up the 'time/seconds' topic
2323
AdafruitIO_Time *seconds = io.time(AIO_TIME_SECONDS);
2424

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+
2531
void setup() {
2632

2733
// start the serial connection
@@ -35,11 +41,14 @@ void setup() {
3541
// start MQTT connection to io.adafruit.com
3642
io.connect();
3743

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);
4352

4453
// wait for an MQTT connection
4554
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
@@ -63,17 +72,29 @@ void loop() {
6372
// io.adafruit.com, and processes any incoming data.
6473
io.run();
6574

75+
delay(5);
6676
// Because this sketch isn't publishing, we don't need
6777
// a delay() in the main program loop.
6878

6979
}
7080

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) {
7581

76-
Serial.print("received <- ");
82+
// message handler for the seconds feed
83+
void handleSecs(char *data, uint16_t len) {
84+
Serial.print("Seconds Feed: ");
7785
Serial.println(data);
86+
}
87+
7888

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);
79100
}

0 commit comments

Comments
 (0)