Here's my contribution to the code for Episode 367: Most Useless IoT Device Ever - Part 2 It's ugly, but it works!
//element14 Presents IoT Rock Phase II
//Maui airport monitor by Matthew Eargle
//https://airbornesurfer.com
//Completely useless function to tell us when someone arrives in a place we aren't
//Especially when that place is somewhere we'd rather be
//Based on Adafruit GMailbox Example Code
//https://learn.adafruit.com/gmailbox
//Please support open source developers--we're all in this together!
/************************** Configuration ***********************************/
// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"
/************************** Start Code *************************************/
// set up feed
AdafruitIO_Feed *gmail_feed = io.feed("IoT Rock");
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
// start the serial connection
Serial.begin(115200);
// wait for serial monitor to open
while(! Serial);
Serial.print("Maui Monitor");
// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();
// set up a message handler for the monitor feed.
// the handleMessage function (defined below)
// will be called whenever a message is
// received from adafruit io.
gmail_feed->onMessage(handleMessage);
// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// connection established
Serial.println();
Serial.println(io.statusText());
gmail_feed->get();
// write led indicator off
digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
io.run();
digitalWrite(LED_BUILTIN, LOW);
}
// this function is called whenever a 'gmail' message
// is received from Adafruit IO. it was attached to
// the gmail feed in the setup() function above.
void handleMessage(AdafruitIO_Data *data) {
Serial.println("Someone Landed!");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}
You're also going to need a file named config.h in the same folder as this Arduino sketch. The config file contains the following:
/************************ Adafruit IO Config *******************************/ // visit io.adafruit.com if you need to create an account, // or if you need your Adafruit IO key. #define IO_USERNAME "AdafruitIOUsername" #define IO_KEY "AdafruitIOAPIKey" /******************************* WIFI **************************************/ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 // - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 #define WIFI_SSID "SSID" #define WIFI_PASS "password" // comment out the following two lines if you are using fona or ethernet #include "AdafruitIO_WiFi.h" AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);