-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from brentru/add-iot-basics-schedule-trigger
Add IO Basics Example: Scheduled Trigger
- Loading branch information
Showing
3 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
examples/adafruitio_25_schedule_trigger/adafruitio_25_schedule_trigger.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Adafruit IO Schedule Trigger Example | ||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-scheduled-triggers/ | ||
// | ||
// Adafruit invests time and resources providing this open source code. | ||
// Please support Adafruit and open source hardware by purchasing | ||
// products from Adafruit! | ||
// | ||
// Written by Brent Rubell for Adafruit Industries | ||
// Copyright (c) 2020 Adafruit Industries | ||
// Licensed under the MIT license. | ||
// | ||
// All text above must be included in any redistribution. | ||
|
||
/************************** 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" | ||
|
||
/************************ Example Starts Here *******************************/ | ||
|
||
|
||
// Relay is connected to PyPortal's D3 connector | ||
#define RELAY_POWER_PIN 3 | ||
|
||
// Set up the 'relay feed' | ||
AdafruitIO_Feed *relay = io.feed("relay"); | ||
|
||
void setup() { | ||
|
||
// start the serial connection | ||
Serial.begin(115200); | ||
|
||
// wait for serial monitor to open | ||
while(! Serial); | ||
|
||
Serial.print("Connecting to Adafruit IO"); | ||
|
||
// connect to io.adafruit.com | ||
io.connect(); | ||
|
||
// set up a message handler for the 'relay' feed. | ||
// the handleMessage function (defined below) | ||
// will be called whenever a message is | ||
// received from adafruit io | ||
relay->onMessage(handleMessage); | ||
|
||
// wait for a connection | ||
while(io.status() < AIO_CONNECTED) { | ||
Serial.print("."); | ||
delay(500); | ||
} | ||
|
||
// we are connected | ||
Serial.println(); | ||
Serial.println(io.statusText()); | ||
|
||
// Get the last known value from the feed | ||
relay->get(); | ||
|
||
} | ||
|
||
void loop() { | ||
|
||
// io.run(); is required for all sketches. | ||
// it should always be present at the top of your loop | ||
// function. it keeps the client connected to | ||
// io.adafruit.com, and processes any incoming data. | ||
io.run(); | ||
|
||
} | ||
|
||
// this function is called whenever an 'relay' feed message | ||
// is received from Adafruit IO. it was attached to | ||
// the 'relay' feed in the setup() function above. | ||
void handleMessage(AdafruitIO_Data *data) { | ||
|
||
Serial.print("feed received new data <- "); | ||
Serial.println(data->toChar()); | ||
|
||
// Check to see if the morning scheduled trigger has executed | ||
if (strcmp(data->toChar(), "morning") == 0) { | ||
Serial.println("Turning lights ON"); | ||
digitalWrite(RELAY_POWER_PIN, HIGH); | ||
} | ||
// Check to see if the evening scheduled trigger has executed | ||
else if (strcmp(data->toChar(), "night") == 0) { | ||
Serial.println("Turning lights OFF"); | ||
digitalWrite(RELAY_POWER_PIN, LOW); | ||
} | ||
else { | ||
Serial.println("Unexpected data received from Adafruit IO"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/************************ 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 "your_username" | ||
#define IO_KEY "your_key" | ||
|
||
/******************************* 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 | ||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116 | ||
// - Adafruit Metro M4 Express AirLift Lite -> | ||
// https://www.adafruit.com/product/4000 | ||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201 | ||
|
||
#define WIFI_SSID "your_ssid" | ||
#define WIFI_PASS "your_pass" | ||
|
||
// uncomment the following line if you are using airlift | ||
//#define USE_AIRLIFT | ||
|
||
// uncomment the following line if you are using winc1500 | ||
// #define USE_WINC1500 | ||
|
||
// comment out the following lines if you are using fona or ethernet | ||
#include "AdafruitIO_WiFi.h" | ||
|
||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \ | ||
defined(ADAFRUIT_PYPORTAL) | ||
// Configure the pins used for the ESP32 connection | ||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant | ||
// Don't change the names of these #define's! they match the variant ones | ||
#define SPIWIFI SPI | ||
#define SPIWIFI_SS 10 // Chip select pin | ||
#define SPIWIFI_ACK 9 // a.k.a BUSY or READY pin | ||
#define ESP32_RESETN 6 // Reset pin | ||
#define ESP32_GPIO0 -1 // Not connected | ||
#endif | ||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, | ||
SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI); | ||
#else | ||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); | ||
#endif | ||
/******************************* FONA **************************************/ | ||
|
||
// the AdafruitIO_FONA client will work with the following boards: | ||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027 | ||
|
||
// uncomment the following two lines for 32u4 FONA, | ||
// and comment out the AdafruitIO_WiFi client in the WIFI section | ||
// #include "AdafruitIO_FONA.h" | ||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY); | ||
|
||
/**************************** ETHERNET ************************************/ | ||
|
||
// the AdafruitIO_Ethernet client will work with the following boards: | ||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201 | ||
|
||
// uncomment the following two lines for ethernet, | ||
// and comment out the AdafruitIO_WiFi client in the WIFI section | ||
// #include "AdafruitIO_Ethernet.h" | ||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=Adafruit IO Arduino | ||
version=3.9.1 | ||
version=4.0.0 | ||
author=Adafruit | ||
maintainer=Adafruit <[email protected]> | ||
sentence=Arduino library to access Adafruit IO. | ||
|