Skip to content

Commit f7cb725

Browse files
authored
Add IFTTT Example (#61)
* Adding IFTTT example (gmailbox) * fix comments * add example serial text
1 parent 35404b4 commit f7cb725

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Adafruit IO IFTTT Example - Gmailbox
2+
// Tutorial Link: https://learn.adafruit.com/gmailbox
3+
//
4+
// Adafruit invests time and resources providing this open source code.
5+
// Please support Adafruit and open source hardware by purchasing
6+
// products from Adafruit!
7+
//
8+
// Written by Brent Rubell for Adafruit Industries
9+
// Copyright (c) 2018 Adafruit Industries
10+
// Licensed under the MIT license.
11+
//
12+
// All text above must be included in any redistribution.
13+
14+
/************************** Configuration ***********************************/
15+
16+
// edit the config.h tab and enter your Adafruit IO credentials
17+
// and any additional configuration needed for WiFi, cellular,
18+
// or ethernet clients.
19+
#include "config.h"
20+
21+
// Import Servo Libraries
22+
#if defined(ARDUINO_ARCH_ESP32)
23+
// ESP32Servo Library (https://github.com/madhephaestus/ESP32Servo)
24+
// installation: library manager -> search -> "ESP32Servo"
25+
#include <ESP32Servo.h>
26+
#else
27+
#include <Servo.h>
28+
#endif
29+
30+
/************************ Example Starts Here *******************************/
31+
32+
// pin used to control the servo
33+
#define SERVO_PIN 14
34+
35+
// Flag's up position, in degrees
36+
#define FLAG_UP 0
37+
38+
// Flag's down position, in degrees
39+
#define FLAG_DOWN 180
40+
41+
// How long to hold the flag up, in seconds
42+
#define FLAG_DELAY 2
43+
44+
// create an instance of the servo class
45+
Servo servo;
46+
47+
// set up the 'servo' feed
48+
AdafruitIO_Feed *gmail_feed = io.feed("gmail");
49+
50+
void setup() {
51+
52+
// start the serial connection
53+
Serial.begin(115200);
54+
55+
// wait for serial monitor to open
56+
while(! Serial);
57+
58+
Serial.print("IFTTT Gmailbox");
59+
60+
// tell the servo class which pin we are using
61+
servo.attach(SERVO_PIN);
62+
63+
// connect to io.adafruit.com
64+
Serial.print("Connecting to Adafruit IO");
65+
io.connect();
66+
67+
// set up a message handler for the 'servo' feed.
68+
// the handleMessage function (defined below)
69+
// will be called whenever a message is
70+
// received from adafruit io.
71+
gmail_feed->onMessage(handleMessage);
72+
73+
// wait for a connection
74+
while(io.status() < AIO_CONNECTED) {
75+
Serial.print(".");
76+
delay(500);
77+
}
78+
79+
// we are connected
80+
Serial.println();
81+
Serial.println(io.statusText());
82+
gmail_feed->get();
83+
84+
// write flag to down position
85+
servo.write(FLAG_DOWN);
86+
87+
}
88+
89+
void loop() {
90+
91+
// io.run(); is required for all sketches.
92+
// it should always be present at the top of your loop
93+
// function. it keeps the client connected to
94+
// io.adafruit.com, and processes any incoming data.
95+
io.run();
96+
97+
}
98+
99+
// this function is called whenever a 'gmail' message
100+
// is received from Adafruit IO. it was attached to
101+
// the gmail feed in the setup() function above.
102+
void handleMessage(AdafruitIO_Data *data) {
103+
104+
Serial.println("You've got mail!");
105+
servo.write(FLAG_UP);
106+
// wait FLAG_DELAY seconds
107+
delay(FLAG_DELAY * 1000);
108+
servo.write(FLAG_DOWN);
109+
}

examples/adafruitio_23_ifttt/config.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/************************ Adafruit IO Config *******************************/
2+
3+
// visit io.adafruit.com if you need to create an account,
4+
// or if you need your Adafruit IO key.
5+
#define IO_USERNAME "your_username"
6+
#define IO_KEY "your_key"
7+
8+
/******************************* WIFI **************************************/
9+
10+
// the AdafruitIO_WiFi client will work with the following boards:
11+
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
12+
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
13+
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
14+
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
15+
// - Feather WICED -> https://www.adafruit.com/products/3056
16+
17+
#define WIFI_SSID "your_ssid"
18+
#define WIFI_PASS "your_pass"
19+
20+
// comment out the following two lines if you are using fona or ethernet
21+
#include "AdafruitIO_WiFi.h"
22+
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
23+
24+
25+
/******************************* FONA **************************************/
26+
27+
// the AdafruitIO_FONA client will work with the following boards:
28+
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
29+
30+
// uncomment the following two lines for 32u4 FONA,
31+
// and comment out the AdafruitIO_WiFi client in the WIFI section
32+
// #include "AdafruitIO_FONA.h"
33+
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
34+
35+
36+
/**************************** ETHERNET ************************************/
37+
38+
// the AdafruitIO_Ethernet client will work with the following boards:
39+
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
40+
41+
// uncomment the following two lines for ethernet,
42+
// and comment out the AdafruitIO_WiFi client in the WIFI section
43+
// #include "AdafruitIO_Ethernet.h"
44+
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);

0 commit comments

Comments
 (0)