Skip to content

Commit feceacd

Browse files
author
brentru
committed
add example
1 parent 1ee8c76 commit feceacd

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

examples/adafruitio_25_schedule_trigger/adafruitio_25_schedule_trigger.ino

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020

2121
/************************ Example Starts Here *******************************/
2222

23+
24+
// Relay is connected to PyPortal's D3 connector
25+
#define RELAY_POWER_PIN 3
26+
27+
// Set up the 'relay feed'
28+
AdafruitIO_Feed *relay = io.feed("relay");
29+
2330
void setup() {
2431

2532
// start the serial connection
@@ -33,6 +40,12 @@ void setup() {
3340
// connect to io.adafruit.com
3441
io.connect();
3542

43+
// set up a message handler for the 'relay' feed.
44+
// the handleMessage function (defined below)
45+
// will be called whenever a message is
46+
// received from adafruit io
47+
relay->onMessage(handleMessage);
48+
3649
// wait for a connection
3750
while(io.status() < AIO_CONNECTED) {
3851
Serial.print(".");
@@ -43,6 +56,9 @@ void setup() {
4356
Serial.println();
4457
Serial.println(io.statusText());
4558

59+
// Get the last known value from the feed
60+
relay->get();
61+
4662
}
4763

4864
void loop() {
@@ -53,5 +69,27 @@ void loop() {
5369
// io.adafruit.com, and processes any incoming data.
5470
io.run();
5571

72+
}
73+
74+
// this function is called whenever an 'relay' feed message
75+
// is received from Adafruit IO. it was attached to
76+
// the 'relay' feed in the setup() function above.
77+
void handleMessage(AdafruitIO_Data *data) {
78+
79+
Serial.print("feed received new data <- ");
80+
Serial.println(data->toChar());
5681

57-
}
82+
// Check to see if the morning scheduled trigger has executed
83+
if (strcmp(data->toChar(), "morning") == 0) {
84+
Serial.println("Turning lights ON");
85+
digitalWrite(RELAY_POWER_PIN, HIGH);
86+
}
87+
// Check to see if the evening scheduled trigger has executed
88+
else if (strcmp(data->toChar(), "night") == 0) {
89+
Serial.println("Turning lights OFF");
90+
digitalWrite(RELAY_POWER_PIN, LOW);
91+
}
92+
else {
93+
Serial.println("Unexpected data received from Adafruit IO");
94+
}
95+
}

examples/adafruitio_25_schedule_trigger/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define WIFI_PASS "your_pass"
2323

2424
// uncomment the following line if you are using airlift
25-
// #define USE_AIRLIFT
25+
#define USE_AIRLIFT
2626

2727
// uncomment the following line if you are using winc1500
2828
// #define USE_WINC1500

0 commit comments

Comments
 (0)