first commit
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
// Adafruit IO Publish Example
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016 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 *******************************/
|
||||
|
||||
// this int will hold the current count for our sketch
|
||||
int count = 0;
|
||||
|
||||
// set up the 'counter' feed
|
||||
AdafruitIO_Feed *counter = io.feed("counter");
|
||||
|
||||
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();
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// save count to the 'counter' feed on Adafruit IO
|
||||
Serial.print("sending -> ");
|
||||
Serial.println(count);
|
||||
counter->save(count);
|
||||
|
||||
// increment the count by 1
|
||||
count++;
|
||||
|
||||
// Adafruit IO is rate limited for publishing, so a delay is required in
|
||||
// between feed->save events. In this example, we will wait three seconds
|
||||
// (1000 milliseconds == 1 second) during each loop.
|
||||
delay(3000);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,84 @@
|
||||
// Adafruit IO Subscription Example
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016 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 *******************************/
|
||||
|
||||
// set up the 'counter' feed
|
||||
AdafruitIO_Feed *counter = io.feed("counter");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
|
||||
// start MQTT connection to io.adafruit.com
|
||||
io.connect();
|
||||
|
||||
// set up a message handler for the count feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io.
|
||||
counter->onMessage(handleMessage);
|
||||
|
||||
// wait for an MQTT connection
|
||||
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
|
||||
// method to check on MQTT connection status specifically
|
||||
while(io.mqttStatus() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// Because Adafruit IO doesn't support the MQTT retain flag, we can use the
|
||||
// get() function to ask IO to resend the last value for this feed to just
|
||||
// this MQTT client after the io client is connected.
|
||||
counter->get();
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// Because this sketch isn't publishing, we don't need
|
||||
// a delay() in the main program loop.
|
||||
|
||||
}
|
||||
|
||||
// this function is called whenever a 'counter' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the counter feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
Serial.print("received <- ");
|
||||
Serial.println(data->value());
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,104 @@
|
||||
// Adafruit IO Publish & Subscribe Example
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016 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 *******************************/
|
||||
|
||||
// this int will hold the current count for our sketch
|
||||
int count = 0;
|
||||
|
||||
// Track time of last published messages and limit feed->save events to once
|
||||
// every IO_LOOP_DELAY milliseconds.
|
||||
//
|
||||
// Because this sketch is publishing AND subscribing, we can't use a long
|
||||
// delay() function call in the main loop since that would prevent io.run()
|
||||
// from being called often enough to receive all incoming messages.
|
||||
//
|
||||
// Instead, we can use the millis() function to get the current time in
|
||||
// milliseconds and avoid publishing until IO_LOOP_DELAY milliseconds have
|
||||
// passed.
|
||||
#define IO_LOOP_DELAY 5000
|
||||
unsigned long lastUpdate = 0;
|
||||
|
||||
// set up the 'counter' feed
|
||||
AdafruitIO_Feed *counter = io.feed("counter");
|
||||
|
||||
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 count feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io.
|
||||
counter->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
counter->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();
|
||||
|
||||
if (millis() > (lastUpdate + IO_LOOP_DELAY)) {
|
||||
// save count to the 'counter' feed on Adafruit IO
|
||||
Serial.print("sending -> ");
|
||||
Serial.println(count);
|
||||
counter->save(count);
|
||||
|
||||
// increment the count by 1
|
||||
count++;
|
||||
|
||||
// after publishing, store the current time
|
||||
lastUpdate = millis();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// this function is called whenever a 'counter' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the counter feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
Serial.print("received <- ");
|
||||
Serial.println(data->value());
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/************************ 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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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);
|
||||
@@ -0,0 +1,157 @@
|
||||
// Adafruit IO Multiple Feed Example
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016 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 *******************************/
|
||||
|
||||
// holds the current count value for our sketch
|
||||
int count = 0;
|
||||
// holds the boolean (true/false) state of the light
|
||||
bool is_on = false;
|
||||
|
||||
// track time of last published messages and limit feed->save events to once
|
||||
// every IO_LOOP_DELAY milliseconds
|
||||
#define IO_LOOP_DELAY 15000
|
||||
unsigned long lastUpdate;
|
||||
|
||||
// set up the 'counter' feed
|
||||
AdafruitIO_Feed *counter = io.feed("counter");
|
||||
|
||||
// set up the 'counter-two' feed
|
||||
AdafruitIO_Feed *counter_two = io.feed("counter-two");
|
||||
|
||||
// set up the 'light' feed
|
||||
AdafruitIO_Feed *light = io.feed("light");
|
||||
|
||||
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();
|
||||
|
||||
// attach message handler for the counter feed.
|
||||
counter->onMessage(handleCount);
|
||||
|
||||
// attach the same message handler for the second counter feed.
|
||||
counter_two->onMessage(handleCount);
|
||||
|
||||
// attach a new message handler for the light feed.
|
||||
light->onMessage(handleLight);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
// make sure all feeds get their current values right away
|
||||
counter->get();
|
||||
counter_two->get();
|
||||
light->get();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// process messages and keep connection alive
|
||||
io.run();
|
||||
|
||||
if (millis() > (lastUpdate + IO_LOOP_DELAY)) {
|
||||
Serial.println();
|
||||
|
||||
// save current count to 'counter'
|
||||
Serial.print("sending -> counter ");
|
||||
Serial.println(count);
|
||||
counter->save(count);
|
||||
|
||||
// increment the count by 1 and save the value to 'counter-two'
|
||||
Serial.print("sending -> counter-two ");
|
||||
Serial.println(count + 1);
|
||||
counter_two->save(count + 1);
|
||||
|
||||
// print out the light value we are sending to Adafruit IO
|
||||
Serial.print("sending -> light ");
|
||||
if(is_on)
|
||||
Serial.println("is on.\n");
|
||||
else
|
||||
Serial.println("is off.\n");
|
||||
|
||||
// save state of light to 'light' feed
|
||||
light->save(is_on);
|
||||
|
||||
// increment count value
|
||||
count++;
|
||||
|
||||
// for the purpose of this demo, toggle the
|
||||
// light state based on the count value
|
||||
if((count % 2) == 0)
|
||||
is_on = true;
|
||||
else
|
||||
is_on = false;
|
||||
|
||||
// update timer
|
||||
lastUpdate = millis();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// you can set a separate message handler for a single feed,
|
||||
// as we do in this example for the light feed
|
||||
void handleLight(AdafruitIO_Data *data) {
|
||||
|
||||
// print out the received light value
|
||||
Serial.print("received <- light ");
|
||||
|
||||
// use the isTrue helper to get the
|
||||
// boolean state of the light
|
||||
if(data->isTrue())
|
||||
Serial.println("is on.");
|
||||
else
|
||||
Serial.println("is off.");
|
||||
|
||||
}
|
||||
|
||||
// you can also attach multiple feeds to the same
|
||||
// meesage handler function. both counter and counter-two
|
||||
// are attached to this callback function, and messages
|
||||
// for both will be received by this function.
|
||||
void handleCount(AdafruitIO_Data *data) {
|
||||
|
||||
Serial.print("received <- ");
|
||||
|
||||
// since we are using the same function to handle
|
||||
// messages for two feeds, we can use feedName() in
|
||||
// order to find out which feed the message came from.
|
||||
Serial.print(data->feedName());
|
||||
Serial.print(" ");
|
||||
|
||||
// print out the received count or counter-two value
|
||||
Serial.println(data->value());
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,124 @@
|
||||
// Adafruit IO Location Example
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016 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 *******************************/
|
||||
|
||||
// this value integer will hold the current count value for our sketch
|
||||
int value = 0;
|
||||
|
||||
// these double values will hold our fake GPS data
|
||||
double lat = 42.331427;
|
||||
double lon = -83.045754;
|
||||
double ele = 0;
|
||||
|
||||
// track time of last published messages and limit feed->save events to once
|
||||
// every IO_LOOP_DELAY milliseconds
|
||||
#define IO_LOOP_DELAY 5000
|
||||
unsigned long lastUpdate;
|
||||
|
||||
// set up the 'location' feed
|
||||
AdafruitIO_Feed *location = io.feed("location");
|
||||
|
||||
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 location feed.
|
||||
location->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
location->get();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// process messages and keep connection alive
|
||||
io.run();
|
||||
|
||||
if (millis() > (lastUpdate + IO_LOOP_DELAY)) {
|
||||
Serial.println("----- sending -----");
|
||||
Serial.print("value: ");
|
||||
Serial.println(value);
|
||||
Serial.print("lat: ");
|
||||
Serial.println(lat, 6);
|
||||
Serial.print("lon: ");
|
||||
Serial.println(lon, 6);
|
||||
Serial.print("ele: ");
|
||||
Serial.println(ele, 2);
|
||||
|
||||
// save value and location data to the
|
||||
// 'location' feed on Adafruit IO
|
||||
location->save(value, lat, lon, ele);
|
||||
|
||||
// shift all values (for demo purposes)
|
||||
value += 1;
|
||||
lat -= 0.01;
|
||||
lon += 0.02;
|
||||
ele += 1;
|
||||
|
||||
// wait one second (1000 milliseconds == 1 second)
|
||||
lastUpdate = millis();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
// since we sent an int, we can use toInt()
|
||||
// to get the int value from the received IO
|
||||
// data.
|
||||
int received_value = data->toInt();
|
||||
|
||||
// the lat() lon() and ele() methods
|
||||
// will allow you to get the double values
|
||||
// for the location data sent by IO
|
||||
double received_lat = data->lat();
|
||||
double received_lon = data->lon();
|
||||
double received_ele = data->ele();
|
||||
|
||||
// print out the received values
|
||||
Serial.println("----- received -----");
|
||||
Serial.print("value: ");
|
||||
Serial.println(received_value);
|
||||
Serial.print("lat: ");
|
||||
Serial.println(received_lat, 6);
|
||||
Serial.print("lon: ");
|
||||
Serial.println(received_lon, 6);
|
||||
Serial.print("ele: ");
|
||||
Serial.println(received_ele, 2);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,192 @@
|
||||
// Adafruit IO Type Conversion Example
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016 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 *******************************/
|
||||
|
||||
// set up variables for all of the supported types
|
||||
char *char_val = "character value";
|
||||
String string_val = "string value";
|
||||
bool bool_val = true;
|
||||
int int_val = -10;
|
||||
unsigned int uint_val = 20;
|
||||
long long_val = 186000L;
|
||||
unsigned long ulong_val = millis();
|
||||
double double_val = 1.3053;
|
||||
float float_val = 2.4901;
|
||||
|
||||
// set up variable that will allow us to flip between sending types
|
||||
int current_type = 0;
|
||||
|
||||
// track time of last published messages and limit feed->save events to once
|
||||
// every IO_LOOP_DELAY milliseconds
|
||||
#define IO_LOOP_DELAY 5000
|
||||
unsigned long lastUpdate;
|
||||
|
||||
// set up the 'type' feed
|
||||
AdafruitIO_Feed *type = io.feed("type");
|
||||
|
||||
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 type feed.
|
||||
type->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// process messages and keep connection alive
|
||||
io.run();
|
||||
|
||||
if (millis() > (lastUpdate + IO_LOOP_DELAY)) {
|
||||
Serial.println("----- sending -----");
|
||||
|
||||
// in order to demonstrate sending values
|
||||
// as different types, we will switch between
|
||||
// types in a loop using the current_type variable
|
||||
if(current_type == 0) {
|
||||
Serial.print("char: ");
|
||||
Serial.println(char_val);
|
||||
type->save(char_val);
|
||||
} else if(current_type == 1) {
|
||||
Serial.print("string: ");
|
||||
Serial.println(string_val);
|
||||
type->save(string_val);
|
||||
} else if(current_type == 2) {
|
||||
Serial.print("bool: ");
|
||||
Serial.println(bool_val);
|
||||
type->save(bool_val);
|
||||
} else if(current_type == 3) {
|
||||
Serial.print("int: ");
|
||||
Serial.println(int_val);
|
||||
type->save(int_val);
|
||||
} else if(current_type == 4) {
|
||||
Serial.print("unsigned int: ");
|
||||
Serial.println(uint_val);
|
||||
type->save(uint_val);
|
||||
} else if(current_type == 5) {
|
||||
Serial.print("long: ");
|
||||
Serial.println(long_val);
|
||||
type->save(long_val);
|
||||
} else if(current_type == 6) {
|
||||
Serial.print("unsigned long: ");
|
||||
Serial.println(ulong_val);
|
||||
type->save(ulong_val);
|
||||
} else if(current_type == 7) {
|
||||
Serial.print("double: ");
|
||||
Serial.println(double_val);
|
||||
type->save(double_val);
|
||||
} else if(current_type == 8) {
|
||||
Serial.print("float: ");
|
||||
Serial.println(float_val);
|
||||
type->save(float_val);
|
||||
}
|
||||
|
||||
// move to the next type
|
||||
current_type++;
|
||||
|
||||
// reset type if we have reached the end
|
||||
if(current_type > 8)
|
||||
current_type = 0;
|
||||
|
||||
Serial.println();
|
||||
|
||||
lastUpdate = millis();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// this function will demonstrate how to convert
|
||||
// the received data to each available type.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
// print out the received count value
|
||||
Serial.println("----- received -----");
|
||||
|
||||
// value() returns char*
|
||||
Serial.print("value: ");
|
||||
Serial.println(data->value());
|
||||
|
||||
// get char* value
|
||||
Serial.print("toChar: ");
|
||||
Serial.println(data->toChar());
|
||||
|
||||
// get String value
|
||||
Serial.print("toString: ");
|
||||
Serial.println(data->toString());
|
||||
|
||||
// get double value
|
||||
Serial.print("toDouble: ");
|
||||
Serial.println(data->toDouble(), 6);
|
||||
|
||||
// get double value
|
||||
Serial.print("toFloat: ");
|
||||
Serial.println(data->toFloat(), 6);
|
||||
|
||||
// get int value
|
||||
Serial.print("toInt: ");
|
||||
Serial.println(data->toInt());
|
||||
|
||||
// get unsigned int value
|
||||
Serial.print("toUnsignedInt: ");
|
||||
Serial.println(data->toUnsignedInt());
|
||||
|
||||
// get long value
|
||||
Serial.print("toLong: ");
|
||||
Serial.println(data->toLong());
|
||||
|
||||
// get unsigned long value
|
||||
Serial.print("toUnsignedLong: ");
|
||||
Serial.println(data->toUnsignedLong());
|
||||
|
||||
// get bool value
|
||||
Serial.print("toBool: ");
|
||||
Serial.println(data->toBool());
|
||||
|
||||
// get isTrue (bool) value
|
||||
Serial.print("isTrue: ");
|
||||
Serial.println(data->isTrue());
|
||||
|
||||
// get isFalse (bool) value
|
||||
Serial.print("isFalse: ");
|
||||
Serial.println(data->isFalse());
|
||||
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,88 @@
|
||||
// Adafruit IO Digital Input Example
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-digital-input
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016 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 *******************************/
|
||||
|
||||
// digital pin 5
|
||||
#define BUTTON_PIN 5
|
||||
|
||||
// button state
|
||||
bool current = false;
|
||||
bool last = false;
|
||||
|
||||
// set up the 'digital' feed
|
||||
AdafruitIO_Feed *digital = io.feed("digital");
|
||||
|
||||
void setup() {
|
||||
|
||||
// set button pin as an input
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// grab the current state of the button.
|
||||
// we have to flip the logic because we are
|
||||
// using a pullup resistor.
|
||||
if(digitalRead(BUTTON_PIN) == LOW)
|
||||
current = true;
|
||||
else
|
||||
current = false;
|
||||
|
||||
// return if the value hasn't changed
|
||||
if(current == last)
|
||||
return;
|
||||
|
||||
// save the current state to the 'digital' feed on adafruit io
|
||||
Serial.print("sending button -> ");
|
||||
Serial.println(current);
|
||||
digital->save(current);
|
||||
|
||||
// store last button state
|
||||
last = current;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,86 @@
|
||||
// Adafruit IO Digital Output Example
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-digital-output
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016 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 *******************************/
|
||||
|
||||
// digital pin 5
|
||||
#define LED_PIN 5
|
||||
|
||||
// set up the 'digital' feed
|
||||
AdafruitIO_Feed *digital = io.feed("digital");
|
||||
|
||||
void setup() {
|
||||
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// set up a message handler for the 'digital' feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io.
|
||||
digital->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
digital->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 'digital' feed message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the 'digital' feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
Serial.print("received <- ");
|
||||
|
||||
if(data->toPinLevel() == HIGH)
|
||||
Serial.println("HIGH");
|
||||
else
|
||||
Serial.println("LOW");
|
||||
|
||||
|
||||
digitalWrite(LED_PIN, data->toPinLevel());
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,85 @@
|
||||
// Adafruit IO Analog In Example
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-analog-input
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016 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 *******************************/
|
||||
|
||||
// analog pin 0
|
||||
#define PHOTOCELL_PIN A0
|
||||
|
||||
// photocell state
|
||||
int current = 0;
|
||||
int last = -1;
|
||||
|
||||
// set up the 'analog' feed
|
||||
AdafruitIO_Feed *analog = io.feed("analog");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// grab the current state of the photocell
|
||||
current = analogRead(PHOTOCELL_PIN);
|
||||
|
||||
// return if the value hasn't changed
|
||||
if(current == last)
|
||||
return;
|
||||
|
||||
// save the current state to the analog feed
|
||||
Serial.print("sending -> ");
|
||||
Serial.println(current);
|
||||
analog->save(current);
|
||||
|
||||
// store last photocell state
|
||||
last = current;
|
||||
|
||||
// wait three seconds (1000 milliseconds == 1 second)
|
||||
//
|
||||
// because there are no active subscriptions, we can use delay()
|
||||
// instead of tracking millis()
|
||||
delay(3000);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,97 @@
|
||||
// Adafruit IO Analog Out Example
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-analog-output
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016 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 *******************************/
|
||||
|
||||
// this should correspond to a pin with PWM capability
|
||||
#define LED_PIN 5
|
||||
|
||||
// set up the 'analog' feed
|
||||
AdafruitIO_Feed *analog = io.feed("analog");
|
||||
|
||||
void setup() {
|
||||
|
||||
// set up led pin as an analog output
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1)
|
||||
// New ESP32 LEDC API
|
||||
ledcAttach(LED_PIN, 12000, 8); // 12 kHz PWM, 8-bit resolution
|
||||
#else
|
||||
// Legacy ESP32 LEDC API
|
||||
ledcAttachPin(LED_PIN, 1);
|
||||
ledcSetup(1, 1200, 8);
|
||||
#endif
|
||||
#else
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
#endif
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// set up a message handler for the 'analog' feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io.
|
||||
analog->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
analog->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 'analog' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the analog feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
// convert the data to integer
|
||||
int reading = data->toInt();
|
||||
|
||||
Serial.print("received <- ");
|
||||
Serial.println(reading);
|
||||
|
||||
// write the current 'reading' to the led
|
||||
analogWrite(LED_PIN, reading);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,165 @@
|
||||
// Adafruit IO Dashboard Setup Example
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016 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 *******************************/
|
||||
|
||||
// set up the 'example' feed
|
||||
AdafruitIO_Feed *feed = io.feed("example");
|
||||
|
||||
// set up the 'example' dashboard
|
||||
AdafruitIO_Dashboard *dashboard = io.dashboard("example");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
// create the example feed if it doesn't exist
|
||||
if(feed->exists()) {
|
||||
Serial.println("Example feed exists.");
|
||||
} else {
|
||||
if(feed->create()) {
|
||||
Serial.println("Example feed created.");
|
||||
} else {
|
||||
Serial.println("Example feed creation failed.");
|
||||
}
|
||||
}
|
||||
|
||||
// create the example dashboard if it doesn't exist
|
||||
if(dashboard->exists()) {
|
||||
Serial.println("Example dashboard exists.");
|
||||
} else {
|
||||
if(dashboard->create()) {
|
||||
Serial.println("Example dashboard created.");
|
||||
// add blocks to the dashboard using the function below
|
||||
addBlocks();
|
||||
} else {
|
||||
Serial.println("Example dashboard creation failed.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
void addBlocks() {
|
||||
|
||||
bool added = false;
|
||||
|
||||
Serial.print("Adding momentary button block... ");
|
||||
MomentaryBlock *button = dashboard->addMomentaryBlock(feed);
|
||||
button->text = "Button";
|
||||
button->value = "1";
|
||||
button->release = "0";
|
||||
added = button->save();
|
||||
Serial.println(added ? "added" : "failed");
|
||||
|
||||
Serial.print("Adding toggle button block... ");
|
||||
ToggleBlock *toggle = dashboard->addToggleBlock(feed);
|
||||
toggle->onText = "1";
|
||||
toggle->offText = "0";
|
||||
added = toggle->save();
|
||||
Serial.println(added ? "added" : "failed");
|
||||
|
||||
Serial.print("Adding slider block... ");
|
||||
SliderBlock *slider = dashboard->addSliderBlock(feed);
|
||||
slider->min = 0;
|
||||
slider->max = 100;
|
||||
slider->step = 10;
|
||||
slider->label = "Value";
|
||||
added = slider->save();
|
||||
Serial.println(added ? "added" : "failed");
|
||||
|
||||
Serial.print("Adding gauge block... ");
|
||||
GaugeBlock *gauge = dashboard->addGaugeBlock(feed);
|
||||
gauge->min = 0;
|
||||
gauge->max = 100;
|
||||
gauge->ringWidth = "thin"; // thin or thick
|
||||
gauge->label = "Value";
|
||||
added = gauge->save();
|
||||
Serial.println(added ? "added" : "failed");
|
||||
|
||||
Serial.print("Adding line chart block... ");
|
||||
ChartBlock *chart = dashboard->addChartBlock(feed);
|
||||
chart->yAxisMin = 0;
|
||||
chart->yAxisMax = 100;
|
||||
chart->xAxisLabel = "X";
|
||||
chart->yAxisLabel = "Y";
|
||||
added = chart->save();
|
||||
Serial.println(added ? "added" : "failed");
|
||||
|
||||
Serial.print("Adding text block... ");
|
||||
TextBlock *text = dashboard->addTextBlock(feed);
|
||||
text->fontSize = "small"; // small, medium, or large
|
||||
added = text->save();
|
||||
Serial.println(added ? "added" : "failed");
|
||||
|
||||
Serial.print("Adding stream block... ");
|
||||
StreamBlock *stream = dashboard->addStreamBlock(feed);
|
||||
stream->fontSize = "small"; // small, medium, or large
|
||||
stream->fontColor = "green"; // green or white
|
||||
stream->showErrors = true;
|
||||
stream->showTimestamp = true;
|
||||
stream->showName = true;
|
||||
added = stream->save();
|
||||
Serial.println(added ? "added" : "failed");
|
||||
|
||||
Serial.print("Adding color picker block... ");
|
||||
ColorBlock *color = dashboard->addColorBlock(feed);
|
||||
added = color->save();
|
||||
Serial.println(added ? "added" : "failed");
|
||||
|
||||
Serial.print("Adding map block... ");
|
||||
MapBlock *map = dashboard->addMapBlock(feed);
|
||||
map->historyHours = 0;
|
||||
map->tile = "contrast"; // street, sat, or contrast
|
||||
added = map->save();
|
||||
Serial.println(added ? "added" : "failed");
|
||||
|
||||
Serial.print("Adding image block... ");
|
||||
ImageBlock *image = dashboard->addImageBlock(feed);
|
||||
added = image->save();
|
||||
Serial.println(added ? "added" : "failed");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,93 @@
|
||||
// Adafruit IO Group Publish Example
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016 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 *******************************/
|
||||
|
||||
// set up the group
|
||||
AdafruitIO_Group *group = io.group("example");
|
||||
|
||||
int count_1 = 0;
|
||||
int count_2 = 0;
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
group->onMessage("count-1", one);
|
||||
group->onMessage("count-2", two);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
group->set("count-1", count_1);
|
||||
group->set("count-2", count_2);
|
||||
group->save();
|
||||
|
||||
Serial.print("sending example.count-1 -> ");
|
||||
Serial.println(count_1);
|
||||
Serial.print("sending example.count-2 -> ");
|
||||
Serial.println(count_2);
|
||||
|
||||
// increment the count_1 by 1
|
||||
count_1 += 1;
|
||||
// increment the count_2 by 2
|
||||
count_2 += 2;
|
||||
|
||||
// wait four seconds (1000 milliseconds == 1 second)
|
||||
delay(4000);
|
||||
}
|
||||
|
||||
// this function is called whenever a 'counter-1' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the counter-1 feed in the setup() function above.
|
||||
void one(AdafruitIO_Data *data) {
|
||||
// do nothing!
|
||||
}
|
||||
|
||||
// this function is called whenever a 'counter-2' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the counter-2 feed in the setup() function above.
|
||||
void two(AdafruitIO_Data *data) {
|
||||
// do nothing!
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,79 @@
|
||||
// Adafruit IO Group Subscribe Example
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2018 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 *******************************/
|
||||
|
||||
// set up the group
|
||||
AdafruitIO_Group *group = io.group("example");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
group->onMessage("count-1", one);
|
||||
group->onMessage("count-2", two);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
// force IO to update our MQTT subscription with the current values of all feeds
|
||||
group->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 a 'counter-1' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the counter-1 feed in the setup() function above.
|
||||
void one(AdafruitIO_Data *data) {
|
||||
Serial.print("received example.count-1 <- ");
|
||||
Serial.println(data->value());
|
||||
}
|
||||
|
||||
// this function is called whenever a 'counter-2' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the counter-2 feed in the setup() function above.
|
||||
void two(AdafruitIO_Data *data) {
|
||||
Serial.print("received example.count-2 <- ");
|
||||
Serial.println(data->value());
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,120 @@
|
||||
// Adafruit IO RGB LED Output Example
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-color
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016-2017 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 *******************************/
|
||||
|
||||
// default PWM pins for ESP8266.
|
||||
// you should change these to match PWM pins on other platforms.
|
||||
#define RED_PIN 4
|
||||
#define GREEN_PIN 5
|
||||
#define BLUE_PIN 2
|
||||
|
||||
// set up the 'color' feed
|
||||
AdafruitIO_Feed *color = io.feed("color");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) // ESP32 pinMode
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1)
|
||||
// New ESP32 LEDC API
|
||||
ledcAttach(RED_PIN, 12000, 8); // 12 kHz PWM, 8-bit resolution
|
||||
ledcAttach(GREEN_PIN, 12000, 8);
|
||||
ledcAttach(BLUE_PIN, 12000, 8);
|
||||
#else
|
||||
// Legacy ESP32 LEDC API
|
||||
ledcAttachPin(RED_PIN, 1);
|
||||
ledcAttachPin(GREEN_PIN, 2);
|
||||
ledcAttachPin(BLUE_PIN, 3);
|
||||
ledcSetup(1, 12000, 8);
|
||||
ledcSetup(2, 12000, 8);
|
||||
ledcSetup(3, 12000, 8);
|
||||
#endif
|
||||
#else
|
||||
pinMode(RED_PIN, OUTPUT);
|
||||
pinMode(GREEN_PIN, OUTPUT);
|
||||
pinMode(BLUE_PIN, OUTPUT);
|
||||
#endif
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// set up a message handler for the 'color' feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io.
|
||||
color->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
color->get();
|
||||
|
||||
// set analogWrite range for ESP8266
|
||||
#ifdef ESP8266
|
||||
analogWriteRange(255);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
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 a 'color' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the color feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
// print RGB values and hex value
|
||||
Serial.println("Received:");
|
||||
Serial.print(" - R: ");
|
||||
Serial.println(data->toRed());
|
||||
Serial.print(" - G: ");
|
||||
Serial.println(data->toGreen());
|
||||
Serial.print(" - B: ");
|
||||
Serial.println(data->toBlue());
|
||||
Serial.print(" - HEX: ");
|
||||
Serial.println(data->value());
|
||||
|
||||
// invert RGB values for common anode LEDs
|
||||
analogWrite(RED_PIN, 255 - data->toRed());
|
||||
analogWrite(GREEN_PIN, 255 - data->toGreen());
|
||||
analogWrite(BLUE_PIN, 255 - data->toBlue());
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,95 @@
|
||||
// Adafruit IO RGB LED Output Example
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016-2017 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 *******************************/
|
||||
|
||||
#include "Adafruit_NeoPixel.h"
|
||||
|
||||
#define PIXEL_PIN 5
|
||||
#define PIXEL_COUNT 24
|
||||
#define PIXEL_TYPE NEO_GRB + NEO_KHZ800
|
||||
|
||||
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
|
||||
|
||||
// set up the 'color' feed
|
||||
AdafruitIO_Feed *color = io.feed("color");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// set up a message handler for the 'color' feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io.
|
||||
color->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
color->get();
|
||||
|
||||
// neopixel init
|
||||
pixels.begin();
|
||||
pixels.show();
|
||||
|
||||
}
|
||||
|
||||
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 a 'color' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the color feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
// print RGB values and hex value
|
||||
Serial.println("Received HEX: ");
|
||||
Serial.println(data->value());
|
||||
|
||||
long color = data->toNeoPixel();
|
||||
|
||||
for(int i=0; i<PIXEL_COUNT; ++i) {
|
||||
pixels.setPixelColor(i, color);
|
||||
}
|
||||
|
||||
pixels.show();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,100 @@
|
||||
// Adafruit IO Temperature & Humidity Example
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-temperature-and-humidity
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016-2017 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 *******************************/
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <DHT.h>
|
||||
#include <DHT_U.h>
|
||||
|
||||
// pin connected to DH22 data line
|
||||
#define DATA_PIN 2
|
||||
|
||||
// create DHT22 instance
|
||||
DHT_Unified dht(DATA_PIN, DHT22);
|
||||
|
||||
// set up the 'temperature' and 'humidity' feeds
|
||||
AdafruitIO_Feed *temperature = io.feed("temperature");
|
||||
AdafruitIO_Feed *humidity = io.feed("humidity");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// initialize dht22
|
||||
dht.begin();
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
sensors_event_t event;
|
||||
dht.temperature().getEvent(&event);
|
||||
|
||||
float celsius = event.temperature;
|
||||
float fahrenheit = (celsius * 1.8) + 32;
|
||||
|
||||
Serial.print("celsius: ");
|
||||
Serial.print(celsius);
|
||||
Serial.println("C");
|
||||
|
||||
Serial.print("fahrenheit: ");
|
||||
Serial.print(fahrenheit);
|
||||
Serial.println("F");
|
||||
|
||||
// save fahrenheit (or celsius) to Adafruit IO
|
||||
temperature->save(fahrenheit);
|
||||
|
||||
dht.humidity().getEvent(&event);
|
||||
|
||||
Serial.print("humidity: ");
|
||||
Serial.print(event.relative_humidity);
|
||||
Serial.println("%");
|
||||
|
||||
// save humidity to Adafruit IO
|
||||
humidity->save(event.relative_humidity);
|
||||
|
||||
// wait 5 seconds (5000 milliseconds == 5 seconds)
|
||||
delay(5000);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,102 @@
|
||||
// Adafruit IO Servo Example
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-servo
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016-2017 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 *******************************/
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// ESP32Servo Library (https://github.com/madhephaestus/ESP32Servo)
|
||||
// installation: library manager -> search -> "ESP32Servo"
|
||||
#include <ESP32Servo.h>
|
||||
#else
|
||||
#include <Servo.h>
|
||||
#endif
|
||||
|
||||
// pin used to control the servo
|
||||
#define SERVO_PIN 2
|
||||
|
||||
// create an instance of the servo class
|
||||
Servo servo;
|
||||
|
||||
// set up the 'servo' feed
|
||||
AdafruitIO_Feed *servo_feed = io.feed("servo");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// tell the servo class which pin we are using
|
||||
servo.attach(SERVO_PIN);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// set up a message handler for the 'servo' feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io.
|
||||
servo_feed->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
servo_feed->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 a 'servo' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the servo feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
// convert the data to integer
|
||||
int angle = data->toInt();
|
||||
|
||||
// make sure we don't exceed the limit
|
||||
// of the servo. the range is from 0
|
||||
// to 180.
|
||||
if(angle < 0)
|
||||
angle = 0;
|
||||
else if(angle > 180)
|
||||
angle = 180;
|
||||
|
||||
servo.write(angle);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,99 @@
|
||||
// Adafruit IO Time Topic Subscription Example
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Adam Bachman, Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 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 *******************************/
|
||||
|
||||
// set up the 'time/seconds' topic
|
||||
AdafruitIO_Time *seconds = io.time(AIO_TIME_SECONDS);
|
||||
|
||||
// set up the 'time/milliseconds' topic
|
||||
AdafruitIO_Time *msecs = io.time(AIO_TIME_MILLIS);
|
||||
|
||||
// set up the 'time/ISO-8601' topic
|
||||
AdafruitIO_Time *iso = io.time(AIO_TIME_ISO);
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
|
||||
// start MQTT connection to io.adafruit.com
|
||||
io.connect();
|
||||
|
||||
// attach message handler for the seconds feed
|
||||
seconds->onMessage(handleSecs);
|
||||
|
||||
// attach a message handler for the msecs feed
|
||||
msecs->onMessage(handleMillis);
|
||||
|
||||
// attach a message handler for the ISO feed
|
||||
iso->onMessage(handleISO);
|
||||
|
||||
// wait for an MQTT connection
|
||||
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
|
||||
// method to check on MQTT connection status specifically
|
||||
while(io.mqttStatus() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// Because this sketch isn't publishing, we don't need
|
||||
// a delay() in the main program loop.
|
||||
|
||||
}
|
||||
|
||||
|
||||
// message handler for the seconds feed
|
||||
void handleSecs(char *data, uint16_t len) {
|
||||
Serial.print("Seconds Feed: ");
|
||||
Serial.println(data);
|
||||
}
|
||||
|
||||
|
||||
// message handler for the milliseconds feed
|
||||
void handleMillis(char *data, uint16_t len) {
|
||||
Serial.print("Millis Feed: ");
|
||||
Serial.println(data);
|
||||
}
|
||||
|
||||
|
||||
// message handler for the ISO-8601 feed
|
||||
void handleISO(char *data, uint16_t len) {
|
||||
Serial.print("ISO Feed: ");
|
||||
Serial.println(data);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,82 @@
|
||||
// Adafruit IO Device Information
|
||||
// desc: Displays Device, WiFi, and Adafruit IO connection information
|
||||
//
|
||||
// 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) 2018 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 *******************************/
|
||||
// device mac address
|
||||
byte mac[6];
|
||||
|
||||
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();
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
// Device Info
|
||||
Serial.println("----DEVICE INFO----");
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC Address: ");
|
||||
for(int i=0;i<6;i++) {
|
||||
Serial.print(mac[i], HEX);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
// Network Info
|
||||
Serial.println("----ROUTER INFO----");
|
||||
Serial.print("WIFI SSID: ");
|
||||
Serial.println(WIFI_SSID);
|
||||
Serial.print("WIFI Pass: ");
|
||||
Serial.println(WIFI_PASS);
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("RSSI:");
|
||||
Serial.println(rssi);
|
||||
|
||||
// Adafruit IO Info
|
||||
Serial.println("----ADAFRUIT IO INFO----");
|
||||
Serial.print("IO User: ");
|
||||
Serial.println(IO_USERNAME);
|
||||
Serial.print("IO Key: ");
|
||||
Serial.println(IO_KEY);
|
||||
Serial.print("IO Status: ");
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,75 @@
|
||||
// Adafruit IO DeepSleep Example (HUZZAH8266)
|
||||
//
|
||||
// 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) 2018 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 *******************************/
|
||||
#define DEEPSLEEP_DURATION 20e6
|
||||
|
||||
void setup() {
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while (!Serial);
|
||||
Serial.println("Adafruit IO + DeepSleep");
|
||||
|
||||
// connect to the Adafruit IO Library
|
||||
connectAIO();
|
||||
|
||||
// set up and write to deepsleep feed
|
||||
feedWrite();
|
||||
|
||||
// let's go back to sleep for DEEPSLEEP_DURATION seconds...
|
||||
Serial.println("sleeping...");
|
||||
// Put the Huzzah into deepsleep for DEEPSLEEP_DURATION
|
||||
// NOTE: Make sure Pin 16 is connected to RST
|
||||
#if defined(ESP8266)
|
||||
ESP.deepSleep(1000000 * 2);
|
||||
#else
|
||||
Serial.println("This example is not compatible with your hardware.");
|
||||
#endif
|
||||
}
|
||||
|
||||
// NOOP
|
||||
void loop() {
|
||||
}
|
||||
|
||||
|
||||
void feedWrite(){
|
||||
// set up `deepsleep` feed
|
||||
AdafruitIO_Feed *deepsleep = io.feed("deepsleep");
|
||||
Serial.println("sending value to feed 'deepsleep");
|
||||
// send data to deepsleep feed
|
||||
deepsleep->save(1);
|
||||
// write data to AIO
|
||||
io.run();
|
||||
}
|
||||
void connectAIO() {
|
||||
Serial.println("Connecting to Adafruit IO...");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while (io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,94 @@
|
||||
// Adafruit IO Shared Feeds Write Example
|
||||
// desc: Example of writing a button value to a shared feed.
|
||||
//
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-feeds/sharing-a-feed
|
||||
//
|
||||
// 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) 2018 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 *******************************/
|
||||
|
||||
// digital pin 5
|
||||
#define BUTTON_PIN 5
|
||||
|
||||
// the Adafruit IO username of whomever owns the feed
|
||||
#define FEED_OWNER "AIO_FEED_OWNER"
|
||||
|
||||
// set up a shared feed between you and the FEED_OWNER
|
||||
// make sure you have both read AND write access to this feed
|
||||
AdafruitIO_Feed *sharedFeed = io.feed("FEED-NAME", FEED_OWNER);
|
||||
|
||||
// button state
|
||||
bool current = false;
|
||||
bool last = false;
|
||||
|
||||
void setup() {
|
||||
|
||||
// set button pin as an input
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// grab the current state of the button.
|
||||
// we have to flip the logic because we are
|
||||
// using a pullup resistor.
|
||||
if(digitalRead(BUTTON_PIN) == LOW)
|
||||
current = true;
|
||||
else
|
||||
current = false;
|
||||
|
||||
// return if the value hasn't changed
|
||||
if(current == last)
|
||||
return;
|
||||
|
||||
// save the current state to the 'sharedFeed' feed on adafruit io
|
||||
Serial.print("sending button -> ");
|
||||
Serial.println(current);
|
||||
sharedFeed->save(current);
|
||||
|
||||
// store last button state
|
||||
last = current;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,78 @@
|
||||
// Adafruit IO Feed Reading
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-feeds/sharing-a-feed
|
||||
//
|
||||
// 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) 2018 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 *******************************/
|
||||
|
||||
// the Adafruit IO username of whomever owns the feed
|
||||
#define FEED_OWNER "AIO_FEED_OWNER"
|
||||
|
||||
// set up the `sharedFeed`
|
||||
AdafruitIO_Feed *sharedFeed = io.feed("FEED-NAME", FEED_OWNER);
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// set up a message handler for the 'sharedFeed' feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io.
|
||||
sharedFeed->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
sharedFeed->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 'sharedFeed' feed message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the 'digital' feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
Serial.print("received <- ");
|
||||
Serial.println(data->toInt());
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,190 @@
|
||||
// Adafruit IO Environmental Data Logger
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-air-quality-monitor
|
||||
//
|
||||
// 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) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Adafruit IO 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"
|
||||
|
||||
/**************************** Sensor Configuration ***************************************/
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_BME280.h>
|
||||
#include "Adafruit_VEML6070.h"
|
||||
#include "Adafruit_SGP30.h"
|
||||
|
||||
// BME280 Sensor Definitions
|
||||
#define BME_SCK 13
|
||||
#define BME_MISO 12
|
||||
#define BME_MOSI 11
|
||||
#define BME_CS 10
|
||||
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||
|
||||
// Instanciate the sensors
|
||||
Adafruit_BME280 bme;
|
||||
Adafruit_VEML6070 uv = Adafruit_VEML6070();
|
||||
Adafruit_SGP30 sgp;
|
||||
|
||||
/**************************** Example ***************************************/
|
||||
// Delay between sensor reads, in seconds
|
||||
#define READ_DELAY 10
|
||||
|
||||
// DHT22 Data
|
||||
int temperatureReading;
|
||||
int pressureReading;
|
||||
|
||||
// SGP30 Data
|
||||
int tvocReading = 0;
|
||||
int ecO2Reading = 0;
|
||||
|
||||
// BME280 Data
|
||||
int altitudeReading = 0;
|
||||
int humidityReading = 0;
|
||||
|
||||
// VEML6070 Data
|
||||
int uvReading = 0;
|
||||
|
||||
// set up the feeds for the BME280
|
||||
AdafruitIO_Feed *temperatureFeed = io.feed("temperature");
|
||||
AdafruitIO_Feed *humidityFeed = io.feed("humidity");
|
||||
AdafruitIO_Feed *pressureFeed = io.feed("pressure");
|
||||
AdafruitIO_Feed *altitudeFeed = io.feed("altitude");
|
||||
|
||||
// set up feed for the VEML6070
|
||||
AdafruitIO_Feed *uvFeed = io.feed("uv");
|
||||
|
||||
// set up feeds for the SGP30
|
||||
AdafruitIO_Feed *tvocFeed = io.feed("tvoc");
|
||||
AdafruitIO_Feed *ecO2Feed = io.feed("ecO2");
|
||||
|
||||
void setup() {
|
||||
// start the serial connection
|
||||
Serial.begin(9600);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("Adafruit IO Environmental Logger");
|
||||
|
||||
// set up BME280
|
||||
setupBME280();
|
||||
// set up SGP30
|
||||
setupSGP30();
|
||||
// setup VEML6070
|
||||
uv.begin(VEML6070_1_T);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while (io.status() < AIO_CONNECTED)
|
||||
{
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
Serial.println("Reading Sensors...");
|
||||
|
||||
// Read the temperature from the BME280
|
||||
temperatureReading = bme.readTemperature();
|
||||
|
||||
// convert from celsius to degrees fahrenheit
|
||||
temperatureReading = temperatureReading * 1.8 + 32;
|
||||
|
||||
Serial.print("Temperature = "); Serial.print(temperatureReading); Serial.println(" *F");
|
||||
|
||||
// Read the pressure from the BME280
|
||||
pressureReading = bme.readPressure() / 100.0F;
|
||||
Serial.print("Pressure = "); Serial.print(pressureReading); Serial.println(" hPa");
|
||||
|
||||
// Read the altitude from the BME280
|
||||
altitudeReading = bme.readAltitude(SEALEVELPRESSURE_HPA);
|
||||
Serial.print("Approx. Altitude = "); Serial.print(altitudeReading); Serial.println(" m");
|
||||
|
||||
// Read the humidity from the BME280
|
||||
humidityReading = bme.readHumidity();
|
||||
Serial.print("Humidity = "); Serial.print(humidityReading); Serial.println("%");
|
||||
|
||||
// VEML6070
|
||||
uvReading = uv.readUV();
|
||||
Serial.print("UV Light Level: "); Serial.println(uvReading);
|
||||
|
||||
if(! sgp.IAQmeasure()){
|
||||
tvocReading = -1;
|
||||
ecO2Reading = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
tvocReading = sgp.TVOC;
|
||||
ecO2Reading = sgp.eCO2;
|
||||
}
|
||||
|
||||
Serial.print("TVOC: "); Serial.print(tvocReading); Serial.print(" ppb\t");
|
||||
Serial.print("eCO2: "); Serial.print(ecO2Reading); Serial.println(" ppm");
|
||||
|
||||
// send data to Adafruit IO feeds
|
||||
temperatureFeed->save(temperatureReading);
|
||||
humidityFeed->save(humidityReading);
|
||||
altitudeFeed->save(altitudeReading);
|
||||
pressureFeed->save(pressureReading);
|
||||
uvFeed->save(uvReading);
|
||||
ecO2Feed->save(ecO2Reading);
|
||||
tvocFeed->save(tvocReading);
|
||||
|
||||
// delay the polled loop
|
||||
delay(READ_DELAY * 1000);
|
||||
}
|
||||
|
||||
// Set up the SGP30 sensor
|
||||
void setupSGP30() {
|
||||
if (!sgp.begin())
|
||||
{
|
||||
Serial.println("Sensor not found :(");
|
||||
while (1);
|
||||
}
|
||||
Serial.print("Found SGP30 serial #");
|
||||
Serial.print(sgp.serialnumber[0], HEX);
|
||||
Serial.print(sgp.serialnumber[1], HEX);
|
||||
Serial.println(sgp.serialnumber[2], HEX);
|
||||
|
||||
// If you previously calibrated the sensor in this environment,
|
||||
// you can assign it to self-calibrate (replace the values with your baselines):
|
||||
// sgp.setIAQBaseline(0x8E68, 0x8F41);
|
||||
}
|
||||
|
||||
// Set up the BME280 sensor
|
||||
void setupBME280() {
|
||||
bool status;
|
||||
status = bme.begin();
|
||||
if (!status)
|
||||
{
|
||||
Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
||||
while (1);
|
||||
}
|
||||
Serial.println("BME Sensor is set up!");
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,109 @@
|
||||
// Adafruit IO IFTTT Example - Gmailbox
|
||||
// Tutorial Link: https://learn.adafruit.com/gmailbox
|
||||
//
|
||||
// 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) 2018 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"
|
||||
|
||||
// Import Servo Libraries
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// ESP32Servo Library (https://github.com/madhephaestus/ESP32Servo)
|
||||
// installation: library manager -> search -> "ESP32Servo"
|
||||
#include <ESP32Servo.h>
|
||||
#else
|
||||
#include <Servo.h>
|
||||
#endif
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// pin used to control the servo
|
||||
#define SERVO_PIN 14
|
||||
|
||||
// Flag's up position, in degrees
|
||||
#define FLAG_UP 0
|
||||
|
||||
// Flag's down position, in degrees
|
||||
#define FLAG_DOWN 180
|
||||
|
||||
// How long to hold the flag up, in seconds
|
||||
#define FLAG_DELAY 2
|
||||
|
||||
// create an instance of the servo class
|
||||
Servo servo;
|
||||
|
||||
// set up the 'servo' feed
|
||||
AdafruitIO_Feed *gmail_feed = io.feed("gmail");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
Serial.print("IFTTT Gmailbox");
|
||||
|
||||
// tell the servo class which pin we are using
|
||||
servo.attach(SERVO_PIN);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// set up a message handler for the 'servo' 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);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
gmail_feed->get();
|
||||
|
||||
// write flag to down position
|
||||
servo.write(FLAG_DOWN);
|
||||
|
||||
}
|
||||
|
||||
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 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("You've got mail!");
|
||||
servo.write(FLAG_UP);
|
||||
// wait FLAG_DELAY seconds
|
||||
delay(FLAG_DELAY * 1000);
|
||||
servo.write(FLAG_DOWN);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/************************ 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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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);
|
||||
@@ -0,0 +1,230 @@
|
||||
// Adafruit IO Time Tracking Cube
|
||||
// Tutorial Link: https://learn.adafruit.com/time-tracking-cube
|
||||
//
|
||||
// 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) 2019 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 *******************************/
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_LIS3DH.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
// Prop-Maker Wing
|
||||
#define NEOPIXEL_PIN 2
|
||||
#define POWER_PIN 15
|
||||
|
||||
// Used for Pizeo
|
||||
#define PIEZO_PIN 0
|
||||
|
||||
// # of Pixels Attached
|
||||
#define NUM_PIXELS 8
|
||||
|
||||
// Adafruit_LIS3DH Setup
|
||||
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
|
||||
|
||||
// NeoPixel Setup
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
// Set up the 'cubeTask' feed
|
||||
AdafruitIO_Feed *cubetask = io.feed("cubetask");
|
||||
|
||||
/* Time Tracking Cube States
|
||||
* 1: Cube Tilted Left
|
||||
* 2: Cube Tilted Right
|
||||
* 3: Cube Neutral, Top
|
||||
*/
|
||||
int cubeState = 0;
|
||||
|
||||
// Previous cube orientation state
|
||||
int prvCubeState = 0;
|
||||
|
||||
// Tasks (change these to what you're currently working on)
|
||||
String taskOne = "Write Learn Guide";
|
||||
String taskTwo = "Write Code";
|
||||
|
||||
// Adafruit IO sending delay, in seconds
|
||||
int sendDelay = 0.5;
|
||||
|
||||
// Time-Keeping
|
||||
unsigned long currentTime;
|
||||
unsigned long prevTime;
|
||||
int seconds = 0;
|
||||
int minutes = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// start the serial connection
|
||||
Serial.begin(9600);
|
||||
// wait for serial monitor to open
|
||||
while (!Serial)
|
||||
;
|
||||
Serial.println("Adafruit IO Time Tracking Cube");
|
||||
|
||||
// disabling low-power mode on the prop-maker wing
|
||||
pinMode(POWER_PIN, OUTPUT);
|
||||
digitalWrite(POWER_PIN, HIGH);
|
||||
|
||||
// Initialize LIS3DH
|
||||
if (!lis.begin(0x18))
|
||||
{
|
||||
Serial.println("Couldnt start");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
Serial.println("LIS3DH found!");
|
||||
lis.setRange(LIS3DH_RANGE_4_G);
|
||||
|
||||
// Initialize NeoPixel Strip
|
||||
strip.begin();
|
||||
Serial.println("Pixels init'd");
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while (io.status() < AIO_CONNECTED)
|
||||
{
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
}
|
||||
|
||||
void updateTime()
|
||||
{
|
||||
// grab the current time from millis()
|
||||
currentTime = millis() / 1000;
|
||||
seconds = currentTime - prevTime;
|
||||
// increase mins.
|
||||
if (seconds == 60)
|
||||
{
|
||||
prevTime = currentTime;
|
||||
minutes++;
|
||||
}
|
||||
}
|
||||
|
||||
void updatePixels(uint8_t red, uint8_t green, uint8_t blue)
|
||||
{
|
||||
for (int p = 0; p < NUM_PIXELS; p++)
|
||||
{
|
||||
strip.setPixelColor(p, red, green, blue);
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// Update the timer
|
||||
updateTime();
|
||||
|
||||
// Get a normalized sensor reading
|
||||
sensors_event_t event;
|
||||
lis.getEvent(&event);
|
||||
|
||||
// Detect cube face orientation
|
||||
if (event.acceleration.x > 9 && event.acceleration.x < 10)
|
||||
{
|
||||
//Serial.println("Cube TILTED: Left");
|
||||
cubeState = 1;
|
||||
}
|
||||
else if (event.acceleration.x < -9)
|
||||
{
|
||||
//Serial.println("Cube TILTED: Right");
|
||||
cubeState = 2;
|
||||
}
|
||||
else if (event.acceleration.y < 0 && event.acceleration.y > -1)
|
||||
{
|
||||
cubeState = 3;
|
||||
}
|
||||
else
|
||||
{ // orientation not specified
|
||||
//Serial.println("Cube Idle...");
|
||||
}
|
||||
|
||||
// return if the orientation hasn't changed
|
||||
if (cubeState == prvCubeState)
|
||||
return;
|
||||
|
||||
// Send to Adafruit IO based off of the orientation of the cube
|
||||
switch (cubeState)
|
||||
{
|
||||
case 1:
|
||||
Serial.println("Switching to Task 1");
|
||||
// update the neopixel strip
|
||||
updatePixels(50, 0, 0);
|
||||
|
||||
// play a sound
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
ledcWriteTone(PIEZO_PIN, 650);
|
||||
#else
|
||||
tone(PIEZO_PIN, 650, 300);
|
||||
#endif
|
||||
|
||||
Serial.print("Sending to Adafruit IO -> ");
|
||||
Serial.println(taskTwo);
|
||||
cubetask->save(taskTwo, minutes);
|
||||
// reset the timer
|
||||
minutes = 0;
|
||||
break;
|
||||
case 2:
|
||||
Serial.println("Switching to Task 2");
|
||||
// update the neopixel strip
|
||||
updatePixels(0, 50, 0);
|
||||
|
||||
// play a sound
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
ledcWriteTone(PIEZO_PIN, 850);
|
||||
#else
|
||||
tone(PIEZO_PIN, 850, 300);
|
||||
#endif
|
||||
|
||||
Serial.print("Sending to Adafruit IO -> ");
|
||||
Serial.println(taskOne);
|
||||
cubetask->save(taskOne, minutes);
|
||||
// reset the timer
|
||||
minutes = 0;
|
||||
break;
|
||||
case 3:
|
||||
updatePixels(0, 0, 50);
|
||||
|
||||
// play a sound
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
ledcWriteTone(PIEZO_PIN, 950);
|
||||
#else
|
||||
tone(PIEZO_PIN, 950, 300);
|
||||
#endif
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// save cube state
|
||||
prvCubeState = cubeState;
|
||||
|
||||
// Delay the send to Adafruit IO
|
||||
delay(sendDelay * 1000);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
@@ -0,0 +1,116 @@
|
||||
// Adafruit IO Publish & Subscribe, Digital Input and Output Example
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Modified 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 *******************************/
|
||||
|
||||
// Button Pin
|
||||
#define BUTTON_PIN 0
|
||||
|
||||
// LED Pin
|
||||
#define LED_PIN LED_BUILTIN
|
||||
|
||||
// button state
|
||||
bool btn_state = false;
|
||||
bool prv_btn_state = false;
|
||||
|
||||
// set up the 'led' feed
|
||||
AdafruitIO_Feed *led = io.feed("led");
|
||||
|
||||
// set up the 'button' feed
|
||||
AdafruitIO_Feed *button = io.feed("button");
|
||||
|
||||
void setup() {
|
||||
|
||||
// set button pin as an input
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
|
||||
// set LED pin as an output
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
|
||||
// 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 count feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io.
|
||||
led->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
led->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();
|
||||
|
||||
// grab the btn_state state of the button.
|
||||
if(digitalRead(BUTTON_PIN) == LOW)
|
||||
btn_state = false;
|
||||
else
|
||||
btn_state = true;
|
||||
|
||||
// return if the btn state hasn't changed
|
||||
if(btn_state == prv_btn_state)
|
||||
return;
|
||||
|
||||
// save the btn_state state to the 'button' feed on adafruit io
|
||||
Serial.print("sending button -> "); Serial.println(btn_state);
|
||||
button->save(btn_state);
|
||||
|
||||
// store last button state
|
||||
prv_btn_state = btn_state;
|
||||
|
||||
}
|
||||
|
||||
// this function is called whenever a 'led' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the counter feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
Serial.print("received <- ");
|
||||
|
||||
if(data->toPinLevel() == HIGH)
|
||||
Serial.println("HIGH");
|
||||
else
|
||||
Serial.println("LOW");
|
||||
|
||||
digitalWrite(LED_PIN, data->toPinLevel());
|
||||
}
|
||||
@@ -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);
|
||||
@@ -0,0 +1,80 @@
|
||||
/* Adafruit IO Example Using WiFiManager
|
||||
*
|
||||
* This is a simple Adafruit feed subscribe example that uses
|
||||
* WiFiManager to handle setup of WiFi credentials and connecting
|
||||
* to the network instead of defining the WiFI SSID and password
|
||||
* explicitly in the code.
|
||||
*
|
||||
* To use this example, add your Adafruit IO Username and Key
|
||||
* and setup a feed called "myfeed". When you manually add data
|
||||
* to the feed on io.adafruit.com, you'll see that data written to
|
||||
* the serial output.
|
||||
*
|
||||
* Brad Black - 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include <WiFiManager.h>
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
char IO_USERNAME[64] = "my username";
|
||||
char IO_KEY[64] = "my key";
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, "", "");
|
||||
AdafruitIO_Feed *myfeed = io.feed("myfeed");
|
||||
|
||||
WiFiManager wifiManager;
|
||||
|
||||
void handleMessage(AdafruitIO_Data *data)
|
||||
{
|
||||
|
||||
Serial.print("received <- ");
|
||||
Serial.println(data->toString());
|
||||
|
||||
} // handleMessage
|
||||
|
||||
void setup()
|
||||
|
||||
{
|
||||
Serial.begin(115200); // Initialize serial port for debugging.
|
||||
delay(500);
|
||||
|
||||
// wifiManager.resetSettings(); //uncomment to reset the WiFi settings
|
||||
|
||||
wifiManager.setClass("invert"); // enable "dark mode" for the config portal
|
||||
wifiManager.setConfigPortalTimeout(120); // auto close configportal after n seconds
|
||||
wifiManager.setAPClientCheck(true); // avoid timeout if client connected to softap
|
||||
|
||||
if (!wifiManager.autoConnect("WiFi Setup")) // connect to wifi with existing setting or start config
|
||||
{
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
}
|
||||
else
|
||||
{
|
||||
// if you get here you have connected to the WiFi
|
||||
Serial.println("Connected to WiFi.");
|
||||
|
||||
Serial.printf("Connecting to Adafruit IO with User: %s Key: %s.\n", IO_USERNAME, IO_KEY);
|
||||
io.connect();
|
||||
|
||||
myfeed->onMessage(handleMessage);
|
||||
|
||||
myfeed->get();
|
||||
|
||||
// wait for a connection
|
||||
|
||||
while ((io.status() < AIO_CONNECTED))
|
||||
{
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
Serial.println("Connected to Adafruit IO.");
|
||||
}
|
||||
|
||||
} // setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
io.run();
|
||||
|
||||
} // loop()
|
||||
@@ -0,0 +1,192 @@
|
||||
/* Adafruit IO Example Using WiFiManager with Custom Adafruit IO parameters
|
||||
*
|
||||
* This is a simple Adafruit feed subscribe example that uses
|
||||
* WiFiManager to handle setup of WiFi credentials and connecting
|
||||
* to the network instead of defining the WiFI SSID and password
|
||||
* explicitly in the code.
|
||||
*
|
||||
* In addition, this example allows you to enter your Adafruit IO username and key
|
||||
* as customer parameters in WiFiManager so that they do not need to be coded into
|
||||
* the sketch.
|
||||
*
|
||||
* This is useful if you want to create projects and share them with others that
|
||||
* may use them on a different WiFi network and use a different Adafruit IO account
|
||||
* for IOT integrations such as collecting sensor data or voice command integration via
|
||||
* IFFT.
|
||||
*
|
||||
* To use this example, setup a feed called "myfeed". When the ESP8266 or ESP32
|
||||
* microcontroller starts, join the "WiFi Setup" SSID and you should be presented
|
||||
* with the config portal. If the config portal does not automatically start you
|
||||
* can browse to http://192.168.4.1 to access it
|
||||
*
|
||||
* Select the SSID and enter the password for WiFi Access in the config portal.
|
||||
* Enter your Adafruit IO username and key in the config portal and select "Save".
|
||||
*
|
||||
* When you manually add data to the feed on io.adafruit.com, you'll see
|
||||
* that data written to the serial output.
|
||||
*
|
||||
* Brad Black - 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include <WiFiManager.h>
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
#include <ArduinoJson.h>
|
||||
#include <LittleFS.h>
|
||||
|
||||
char IO_USERNAME[64] = "";
|
||||
char IO_KEY[64] = "";
|
||||
|
||||
static uint8_t objStorage[sizeof(AdafruitIO_WiFi)]; // RAM for the object
|
||||
AdafruitIO_WiFi *io; // a pointer to the object, once it's constructed
|
||||
|
||||
// create WiFiManager object and define our custom parameters
|
||||
|
||||
WiFiManager wifiManager;
|
||||
WiFiManagerParameter custom_IO_USERNAME("iouser", "Adafruit IO Username", IO_USERNAME, 60);
|
||||
WiFiManagerParameter custom_IO_KEY("iokey", "Adafruit IO Key", IO_KEY, 60);
|
||||
|
||||
void handleMessage(AdafruitIO_Data *data)
|
||||
{
|
||||
|
||||
Serial.print("received <- ");
|
||||
Serial.println(data->toString());
|
||||
|
||||
} // handleMessage
|
||||
|
||||
// callback notifying us of the need to save config
|
||||
void saveConfigCallback()
|
||||
{
|
||||
|
||||
Serial.println("Saving new config");
|
||||
|
||||
strcpy(IO_USERNAME, custom_IO_USERNAME.getValue());
|
||||
strcpy(IO_KEY, custom_IO_KEY.getValue());
|
||||
|
||||
DynamicJsonDocument json(256);
|
||||
|
||||
json["IO_KEY"] = IO_KEY;
|
||||
json["IO_USERNAME"] = IO_USERNAME;
|
||||
|
||||
File configFile = LittleFS.open("/config.json", "w");
|
||||
if (!configFile)
|
||||
{
|
||||
Serial.println("Failed to open config file for writing");
|
||||
}
|
||||
|
||||
serializeJson(json, Serial);
|
||||
|
||||
serializeJson(json, configFile);
|
||||
|
||||
configFile.close();
|
||||
} // end save
|
||||
|
||||
void readParamsFromFS()
|
||||
{
|
||||
if (LittleFS.begin())
|
||||
{
|
||||
|
||||
if (LittleFS.exists("/config.json"))
|
||||
{
|
||||
// file exists, reading and loading
|
||||
Serial.println("Reading config file");
|
||||
|
||||
File configFile = LittleFS.open("/config.json", "r");
|
||||
if (configFile)
|
||||
{
|
||||
size_t size = configFile.size();
|
||||
// Allocate a buffer to store contents of the file.
|
||||
std::unique_ptr<char[]> buf(new char[size]);
|
||||
|
||||
configFile.readBytes(buf.get(), size);
|
||||
|
||||
DynamicJsonDocument json(256);
|
||||
auto deserializeError = deserializeJson(json, buf.get());
|
||||
serializeJson(json, Serial);
|
||||
Serial.println();
|
||||
if (!deserializeError)
|
||||
{
|
||||
|
||||
if (json.containsKey("IO_USERNAME"))
|
||||
strcpy(IO_USERNAME, json["IO_USERNAME"]);
|
||||
if (json.containsKey("IO_KEY"))
|
||||
strcpy(IO_KEY, json["IO_KEY"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Failed to load json config");
|
||||
}
|
||||
configFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Serial.println("Failed to mount FS");
|
||||
}
|
||||
}
|
||||
}
|
||||
void setup()
|
||||
|
||||
{
|
||||
Serial.begin(115200); // Initialize serial port for debugging.
|
||||
delay(500);
|
||||
WiFi.begin();
|
||||
|
||||
readParamsFromFS(); // get parameters from file system
|
||||
|
||||
//wifiManager.resetSettings(); //uncomment to reset the WiFi settings
|
||||
|
||||
wifiManager.setClass("invert"); // enable "dark mode" for the config portal
|
||||
wifiManager.setConfigPortalTimeout(120); // auto close configportal after n seconds
|
||||
wifiManager.setAPClientCheck(true); // avoid timeout if client connected to softap
|
||||
|
||||
wifiManager.addParameter(&custom_IO_USERNAME); // set custom paraeter for IO username
|
||||
wifiManager.addParameter(&custom_IO_KEY); // set custom parameter for IO key
|
||||
|
||||
custom_IO_KEY.setValue(IO_KEY, 64); // set custom parameter value
|
||||
custom_IO_USERNAME.setValue(IO_USERNAME, 64); // set custom parameter value
|
||||
|
||||
wifiManager.setSaveConfigCallback(saveConfigCallback); // set config save notify callback
|
||||
|
||||
if (!wifiManager.autoConnect("WiFi Setup")) // connect to wifi with existing setting or start config
|
||||
{
|
||||
Serial.println("Failed to connect and hit timeout");
|
||||
}
|
||||
else
|
||||
{
|
||||
// if you get here you have connected to the WiFi
|
||||
Serial.println("Connected to WiFi.");
|
||||
|
||||
// connect to Adafruit IO
|
||||
|
||||
io = new (objStorage) AdafruitIO_WiFi(IO_USERNAME, IO_KEY, "", "");
|
||||
|
||||
Serial.printf("Connecting to Adafruit IO with User: %s Key: %s.\n", IO_USERNAME, IO_KEY);
|
||||
|
||||
io->connect();
|
||||
|
||||
AdafruitIO_Feed *myfeed = io->feed("myfeed");
|
||||
|
||||
myfeed->onMessage(handleMessage);
|
||||
|
||||
myfeed->get();
|
||||
|
||||
// wait for a connection
|
||||
|
||||
while ((io->status() < AIO_CONNECTED))
|
||||
{
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
Serial.println("Connected to Adafruit IO.");
|
||||
}
|
||||
|
||||
} // setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
io->run();
|
||||
|
||||
} // loop()
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,305 @@
|
||||
// Adafruit IO House: Security System
|
||||
//
|
||||
// Learn Guide: https://learn.adafruit.com/adafruit-io-home-security
|
||||
//
|
||||
// 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) 2018 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"
|
||||
|
||||
// include the NeoPixel library
|
||||
#include "Adafruit_NeoPixel.h"
|
||||
|
||||
// include the SGP30 library
|
||||
#include <Wire.h>
|
||||
#include "Adafruit_SGP30.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// delay the main `io.run()` loop
|
||||
#define LOOP_DELAY 3000
|
||||
// delay for each sensor send to adafruit io
|
||||
#define SENSOR_DELAY 1000
|
||||
|
||||
// PIR sensor input pin
|
||||
#define pirPin 13
|
||||
// reed switch input pin
|
||||
#define doorPin 2
|
||||
// piezo (alarm) buzzer
|
||||
#define piezoPin 14
|
||||
|
||||
/**** Time Setup ****/
|
||||
// set the hour to start at
|
||||
int startingHour = 1;
|
||||
// set the second to start at
|
||||
int seconds = 56;
|
||||
// set the minutes to start at
|
||||
int minutes = 56;
|
||||
// set the hour at which the motion alarm should trigger
|
||||
int alarmHour = 16;
|
||||
|
||||
unsigned long currentTime = 0;
|
||||
unsigned long prevTime = 0;
|
||||
int currentHour = startingHour;
|
||||
|
||||
|
||||
/*********NeoPixel Setup*********/
|
||||
// pin the NeoPixel strip and jewel are connected to
|
||||
#define NEOPIXEL_PIN 12
|
||||
// amount of neopixels on the NeoPixel strip
|
||||
#define STRIP_PIXEL_COUNT 60
|
||||
#define JEWEL_PIXEL_COUNT 7
|
||||
// type of neopixels used by the NeoPixel strip and jewel.
|
||||
#define PIXEL_TYPE NEO_GRB + NEO_KHZ800
|
||||
// init. neoPixel Strip
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIP_PIXEL_COUNT, NEOPIXEL_PIN, PIXEL_TYPE);
|
||||
|
||||
// sketch starts assuming no motion is detected
|
||||
int pirState = LOW;
|
||||
// sketch starts assuming the the door is closed
|
||||
int doorState = LOW;
|
||||
// alarm state
|
||||
bool isAlarm = false;
|
||||
// variable for reading the pin status
|
||||
int pirRead = 0;
|
||||
// SGP30 Sensor Object
|
||||
Adafruit_SGP30 sgp;
|
||||
|
||||
/*** Adafruit IO Feed Setup ***/
|
||||
// 'indoor-lights' feed
|
||||
AdafruitIO_Feed *indoorLights = io.feed("indoor-lights");
|
||||
// `outdoor-lights` feed
|
||||
AdafruitIO_Feed *outdoorLights = io.feed("outdoor-lights");
|
||||
// `front-door` feed
|
||||
AdafruitIO_Feed *frontDoor = io.feed("front-door");
|
||||
// `motion-detector` feed
|
||||
AdafruitIO_Feed *motionFeed = io.feed("motion-detector");
|
||||
// `home-alarm` feed
|
||||
AdafruitIO_Feed *homeAlarm = io.feed("home-alarm");
|
||||
// 'tvoc' feed
|
||||
AdafruitIO_Feed *tvocFeed = io.feed("tvoc");
|
||||
// 'eco2' feed
|
||||
AdafruitIO_Feed *eco2Feed = io.feed("eco2");
|
||||
|
||||
void setup() {
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
Serial.println("Adafruit IO Home: Security");
|
||||
|
||||
Serial.println("Connecting to Adafruit IO");
|
||||
// start MQTT connection to io.adafruit.com
|
||||
io.connect();
|
||||
|
||||
// attach a message handler for the `home-alarm` feed
|
||||
homeAlarm->onMessage(handleAlarm);
|
||||
// subscribe to lighting feeds and register message handlers
|
||||
indoorLights->onMessage(indoorLightHandler);
|
||||
outdoorLights->onMessage(outdoorLightHandler);
|
||||
|
||||
// wait for an MQTT connection
|
||||
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
|
||||
// method to check on MQTT connection status specifically
|
||||
while(io.mqttStatus() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
// declare PIR sensor as input
|
||||
pinMode(pirPin, INPUT);
|
||||
// declare reed switch as input
|
||||
pinMode(doorPin, INPUT);
|
||||
// set up the SGP30 sensor
|
||||
setupSGP30();
|
||||
// init the neopixel strip and set to `off`
|
||||
strip.begin();
|
||||
strip.show();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
getTime();
|
||||
Serial.println("* read door sensor...");
|
||||
readDoorSensor();
|
||||
Serial.println("* read motion detector");
|
||||
readPIR();
|
||||
Serial.println("* reading SGP30...");
|
||||
readSGP30();
|
||||
|
||||
// check if the alarm toggle is armed from the dashboard
|
||||
if (isAlarm == true) {
|
||||
if (doorState == HIGH || (currentHour>alarmHour && pirState == HIGH)) {
|
||||
playAlarmAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void playAlarmAnimation() {
|
||||
// plays the alarm piezo buzzer and turn on/off neopixels
|
||||
Serial.println("ALARM TRIGGERED!");
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// ESP32 doesn't use native tone() function
|
||||
ledcWriteTone(piezoPin, 220);
|
||||
#else
|
||||
tone(piezoPin, 220, 2);
|
||||
#endif
|
||||
|
||||
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, 255, 0, 0);
|
||||
}
|
||||
strip.show();
|
||||
delay(500);
|
||||
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, 0, 0, 0);
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
|
||||
void readDoorSensor() {
|
||||
// reads the status of the front door and sends to adafruit io
|
||||
doorState = digitalRead(doorPin);
|
||||
if (doorState == LOW) {
|
||||
Serial.println("* Door Closed");
|
||||
frontDoor->save(1);
|
||||
} else {
|
||||
Serial.println("* Door Open");
|
||||
frontDoor->save(3);
|
||||
}
|
||||
delay(SENSOR_DELAY);
|
||||
}
|
||||
|
||||
void readPIR() {
|
||||
// check if motion is detected in front of the home
|
||||
pirRead = digitalRead(pirPin);
|
||||
if (pirRead == HIGH) {
|
||||
if (pirState == LOW) {
|
||||
// we have just turned on
|
||||
Serial.println("* Motion detected in front of home!");
|
||||
motionFeed->save(3);
|
||||
pirState = HIGH;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (pirState == HIGH) {
|
||||
Serial.println("* Motion ended.");
|
||||
motionFeed->save(0);
|
||||
pirState = LOW;
|
||||
}
|
||||
}
|
||||
delay(SENSOR_DELAY);
|
||||
}
|
||||
|
||||
void readSGP30() {
|
||||
// reads the SGP30 sensor and sends data to Adafruit IO
|
||||
if (! sgp.IAQmeasure()) {
|
||||
Serial.println("Measurement failed");
|
||||
return;
|
||||
}
|
||||
Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t");
|
||||
Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm");
|
||||
tvocFeed->save(int(sgp.TVOC));
|
||||
delay(SENSOR_DELAY/2);
|
||||
eco2Feed->save(int(sgp.eCO2));
|
||||
delay(SENSOR_DELAY/2);
|
||||
}
|
||||
|
||||
/*** MQTT messageHandlers ***/
|
||||
void handleAlarm(AdafruitIO_Data *data) {
|
||||
// handle the alarm toggle on the Adafruit IO Dashboard
|
||||
String toggleValue = data->toString();
|
||||
Serial.print("> rcv alarm: ");
|
||||
Serial.println(toggleValue);
|
||||
if(toggleValue == String("ON")) {
|
||||
Serial.println("* Alarm Set: ON");
|
||||
isAlarm = true;
|
||||
} else {
|
||||
Serial.println("* Alarm Set: OFF");
|
||||
isAlarm = false;
|
||||
}
|
||||
}
|
||||
|
||||
// handles the indoor light colorpicker on the Adafruit IO Dashboard
|
||||
void indoorLightHandler(AdafruitIO_Data *data) {
|
||||
Serial.print("-> indoor light HEX: ");
|
||||
Serial.println(data->value());
|
||||
long color = data->toNeoPixel();
|
||||
// set the color of each NeoPixel in the jewel
|
||||
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, color);
|
||||
}
|
||||
// 'set' the neopixel jewel to the new color
|
||||
strip.show();
|
||||
}
|
||||
|
||||
// handles the outdoor light colorpicker on the Adafruit IO Dashboard
|
||||
void outdoorLightHandler(AdafruitIO_Data *data) {
|
||||
Serial.print("-> outdoor light HEX: ");
|
||||
Serial.println(data->value());
|
||||
long color = data->toNeoPixel();
|
||||
// set the color of each NeoPixel in the strip
|
||||
for(int i=JEWEL_PIXEL_COUNT; i<STRIP_PIXEL_COUNT+JEWEL_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, color);
|
||||
}
|
||||
// 'set' the neopixel strip to the new color
|
||||
strip.show();
|
||||
}
|
||||
|
||||
|
||||
void setupSGP30(){
|
||||
// sets up the SGP30 Sensor
|
||||
if (! sgp.begin()) {
|
||||
Serial.println("Sensor not found :(");
|
||||
while (1);
|
||||
}
|
||||
Serial.print("Found SGP30 serial #");
|
||||
Serial.print(sgp.serialnumber[0], HEX);
|
||||
Serial.print(sgp.serialnumber[1], HEX);
|
||||
Serial.println(sgp.serialnumber[2], HEX);
|
||||
}
|
||||
|
||||
void getTime() {
|
||||
currentTime = millis()/1000;
|
||||
seconds = currentTime - prevTime;
|
||||
|
||||
if (seconds == 60) {
|
||||
prevTime = currentTime;
|
||||
minutes += 1;
|
||||
}
|
||||
if (minutes == 60) {
|
||||
minutes = 0;
|
||||
currentHour += 1;
|
||||
}
|
||||
if (currentHour == 24) {
|
||||
currentHour = 0;
|
||||
}
|
||||
|
||||
Serial.print("Time:");
|
||||
Serial.print(currentHour);
|
||||
Serial.print(":");
|
||||
Serial.print(minutes);
|
||||
Serial.print(":");
|
||||
Serial.println(seconds);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ 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
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#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
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// 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 NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_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);
|
||||
@@ -0,0 +1,156 @@
|
||||
// Adafruit IO House: Lights and Temperature
|
||||
//
|
||||
// Learn Guide: https://learn.adafruit.com/adafruit-io-house-lights-and-temperature
|
||||
//
|
||||
// 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) 2018 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"
|
||||
|
||||
// include the NeoPixel library
|
||||
#include "Adafruit_NeoPixel.h"
|
||||
|
||||
// include the si7021 library
|
||||
#include "Adafruit_Si7021.h"
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// pin the NeoPixel strip is connected to
|
||||
#define STRIP_PIN 12
|
||||
// pin the NeoPixel Jewel is connected to
|
||||
#define JEWEL_PIN 2
|
||||
|
||||
// amount of neopixels on the NeoPixel strip
|
||||
#define STRIP_PIXEL_COUNT 34
|
||||
// amount of neopixels on the NeoPixel jewel
|
||||
#define JEWEL_PIXEL_COUNT 7
|
||||
|
||||
// type of neopixels used by the NeoPixel strip and jewel.
|
||||
#define PIXEL_TYPE NEO_GRB + NEO_KHZ800
|
||||
|
||||
// main loop() delay, in seconds
|
||||
#define TEMP_DELAY 7
|
||||
|
||||
// Temperature and Humidity: Si7021 Sensor
|
||||
int temperatureData;
|
||||
int humidityData;
|
||||
|
||||
// initalize neopixel strip
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIP_PIXEL_COUNT, STRIP_PIN, PIXEL_TYPE);
|
||||
// initalize neopixel jewel
|
||||
Adafruit_NeoPixel jewel = Adafruit_NeoPixel(JEWEL_PIXEL_COUNT, JEWEL_PIN, PIXEL_TYPE);
|
||||
|
||||
// initalize the sensor object
|
||||
Adafruit_Si7021 sensor = Adafruit_Si7021();
|
||||
|
||||
// set up the Adafruit IO feeds
|
||||
AdafruitIO_Feed *indoorLights = io.feed("indoor-lights");
|
||||
AdafruitIO_Feed *outdoorLights = io.feed("outdoor-lights");
|
||||
AdafruitIO_Feed *humidity = io.feed("humidity");
|
||||
AdafruitIO_Feed *temperature = io.feed("temperature");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// subscribe to lighting feeds and register message handlers
|
||||
indoorLights->onMessage(indoorLightHandler);
|
||||
outdoorLights->onMessage(outdoorLightHandler);
|
||||
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
// initalize the Si7021 sensor
|
||||
if (!sensor.begin()) {
|
||||
Serial.println("Did not find Si7021 sensor!");
|
||||
while (true);
|
||||
}
|
||||
Serial.println("Si7021 sensor set up!");
|
||||
|
||||
// initalize the neopixel strip and jewel.
|
||||
strip.begin();
|
||||
jewel.begin();
|
||||
|
||||
// set all neopixels on the strip and jewel to `off`.
|
||||
strip.show();
|
||||
jewel.show();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
temperatureData = sensor.readTemperature() * 1.8 + 32;
|
||||
humidityData = sensor.readHumidity();
|
||||
|
||||
|
||||
Serial.print("-> Sending Temperature to Adafruit IO: ");
|
||||
Serial.println(temperatureData);
|
||||
Serial.print("-> Sending Humidity to Adafruit IO: ");
|
||||
Serial.println(humidityData);
|
||||
|
||||
// send the state of the feed to adafruit io
|
||||
temperature->save(temperatureData);
|
||||
humidity->save(humidityData);
|
||||
|
||||
// delay the loop to avoid flooding Adafruit IO
|
||||
delay(1000*TEMP_DELAY);
|
||||
}
|
||||
|
||||
void indoorLightHandler(AdafruitIO_Data *data) {
|
||||
Serial.print("-> indoor light HEX: ");
|
||||
Serial.println(data->value());
|
||||
|
||||
long color = data->toNeoPixel();
|
||||
|
||||
// set the color of each NeoPixel in the jewel
|
||||
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
|
||||
jewel.setPixelColor(i, color);
|
||||
}
|
||||
// 'set' the neopixel jewel to the new color
|
||||
jewel.show();
|
||||
}
|
||||
|
||||
void outdoorLightHandler(AdafruitIO_Data *data) {
|
||||
Serial.print("-> outdoor light HEX: ");
|
||||
Serial.println(data->value());
|
||||
|
||||
long color = data->toNeoPixel();
|
||||
|
||||
// set the color of each NeoPixel in the strip
|
||||
for(int i=0; i<STRIP_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, color);
|
||||
}
|
||||
// 'set' the neopixel strip to the new color
|
||||
strip.show();
|
||||
}
|
||||
Reference in New Issue
Block a user