first commit

This commit is contained in:
Jérôme Delacotte
2025-03-06 11:15:32 +01:00
commit 7b30d6e298
5276 changed files with 2108927 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
arduino {
verify = false
platforms = ["esp8266:esp8266", "esp32:esp32", "adafruit:avr", "arduino:samd", "adafruit:samd"]
libraries = ["Adafruit MQTT Library", "Adafruit FONA Library", "Ethernet", "WiFi101"]
boards = ["ESP8266", "M0_WINC1500", "WICED", "MKR1000", "M0_ETHERNETWING", "FONA_32U4", "ESP32"]
}

View File

@@ -0,0 +1,23 @@
The MIT License (MIT)
Copyright (c) 2015-2021 Adafruit Industries
Authors: Tony DiCola, Todd Treece
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,25 @@
# Adafruit IO Arduino Library
[![Build Status](https://github.com/adafruit/Adafruit_IO_Arduino/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_IO_Arduino/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit_IO_Arduino/html/index.html)
[![Discord](https://img.shields.io/discord/327254708534116352.svg)](https://adafru.it/discord)
![AIOArduino](https://cdn-learn.adafruit.com/assets/assets/000/057/496/original/adafruit_io_AIOA.png?1531335660)
This library provides a simple device independent interface for interacting with [Adafruit IO](https://io.adafruit.com) using Arduino. It allows you to switch between WiFi (ESP8266, ESP32, ESP32-S2, ESP32-S3, ESP32-C3, Airlift, WINC1500, & WICED), Cellular (32u4 FONA), and Ethernet (Ethernet FeatherWing).
## Documentation
The Doxygen documentation is automatically generated from the source files
in this repository, and documents the API exposed by this library.
- [API Documentation](https://adafruit.github.io/Adafruit_IO_Arduino/) (automatically generated via doxygen from source)
## License
This open source code is licensed under the MIT license (see [LICENSE](LICENSE)
for details).
Adafruit invests time and resources providing this open source code, please
support Adafruit and open-source hardware by purchasing products from
[Adafruit](https://www.adafruit.com)!

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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());
}

View File

@@ -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);

View File

@@ -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());
}

View File

@@ -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);

View File

@@ -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());
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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());
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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");
}

View File

@@ -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);

View File

@@ -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!
}

View File

@@ -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);

View File

@@ -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());
}

View File

@@ -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);

View File

@@ -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());
}

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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(){
}

View File

@@ -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);

View File

@@ -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());
}

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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());
}

View File

@@ -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);

View File

@@ -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!");
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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");
}
}

View File

@@ -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);

View File

@@ -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());
}

View File

@@ -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);

View File

@@ -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()

View File

@@ -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()

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -0,0 +1,10 @@
name=Adafruit IO Arduino
version=4.2.9
author=Adafruit
maintainer=Adafruit <adafruitio@adafruit.com>
sentence=Arduino library to access Adafruit IO.
paragraph=Arduino library to access Adafruit IO using the Adafruit AirLift, ESP8266, ESP32, ESP32-S2, M0 WINC1500, WICED, MKR1000, Ethernet, or FONA hardware.
category=Communication
url=https://github.com/adafruit/Adafruit_IO_Arduino
architectures=*
depends=Adafruit MQTT Library, ArduinoHttpClient, Adafruit Unified Sensor, Adafruit NeoPixel, DHT sensor library, Ethernet, Adafruit Si7021 Library, Adafruit SGP30 Sensor, Adafruit BME280 Library, Adafruit LIS3DH, Adafruit VEML6070 Library, ESP32Servo, WiFiManager, ArduinoJson

View File

@@ -0,0 +1,466 @@
/*!
* @file AdafruitIO.cpp
*
* @mainpage Adafruit IO Arduino Client Library
*
* @section intro_sec Introduction
*
* This is the documentation for the Adafruit IO Arduino library. This library
* provides a simple device independent interface for interacting with Adafruit
* IO using Arduino. It allows you to switch between WiFi (ESP8266, ESP32,
* AirLift, WINC1500, & WICED), Cellular (32u4 FONA), and Ethernet (Ethernet
* FeatherWing)
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* @section dependencies Dependencies
*
* This library depends on <a
* href="https://github.com/arduino-libraries/ArduinoHttpClient">
* ArduinoHTTPClient</a> and <a
* href="https://github.com/adafruit/Adafruit_MQTT_Library"> Adafruit MQTT
* Library</a> being present on your system. Please make sure you have installed
* the latest version before using this library.
*
* @section author Author
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* @section license License
*
* MIT license, all text here must be included in any redistribution.
*
*/
#include "AdafruitIO.h"
/**************************************************************************/
/*!
@brief Instantiate the AIO object.
@param user
A pointer to a constant AIO user name.
@param key
A pointer to a constant key for the user name.
*/
/**************************************************************************/
AdafruitIO::AdafruitIO(const char *user, const char *key) {
_mqtt = 0;
_http = 0;
_username = user;
_key = key;
_err_topic = 0;
_throttle_topic = 0;
_err_sub = 0;
_throttle_sub = 0;
_packetread_timeout = 100;
_user_agent = 0;
_init();
}
/**************************************************************************/
/*!
@brief Initialize the AIO object.
*/
/**************************************************************************/
void AdafruitIO::_init() {
// we have never pinged, so set last ping to now
_last_ping = millis();
// dynamically allocate memory for err topic
_err_topic = (char *)malloc(
sizeof(char) * (strlen(_username) + strlen(AIO_ERROR_TOPIC) + 1));
if (_err_topic) {
// build error topic
strcpy(_err_topic, _username);
strcat(_err_topic, AIO_ERROR_TOPIC);
} else {
// malloc failed
_err_topic = 0;
}
// dynamically allocate memory for throttle topic
_throttle_topic = (char *)malloc(
sizeof(char) * (strlen(_username) + strlen(AIO_THROTTLE_TOPIC) + 1));
if (_throttle_topic) {
// build throttle topic
strcpy(_throttle_topic, _username);
strcat(_throttle_topic, AIO_THROTTLE_TOPIC);
} else {
// malloc failed
_throttle_topic = 0;
}
}
/**************************************************************************/
/*!
@brief Destructor to end the AIO object.
*/
/**************************************************************************/
AdafruitIO::~AdafruitIO() {
if (_err_topic)
free(_err_topic);
if (_throttle_topic)
free(_throttle_topic);
if (_err_sub)
delete _err_sub;
if (_throttle_sub)
delete _throttle_sub;
}
/**************************************************************************/
/*!
@brief Prints errors
@param err
An error string to print.
@param len
The length of the error string.
*/
/**************************************************************************/
void errorCallback(char *err, uint16_t len) {
AIO_ERROR_PRINTLN();
AIO_ERROR_PRINT("ERROR: ");
AIO_ERROR_PRINTLN(err);
AIO_ERROR_PRINTLN();
}
/**************************************************************************/
/*!
@brief Connects to AIO, setting up using parameters set when the
class is instantiated.
*/
/**************************************************************************/
void AdafruitIO::connect() {
AIO_DEBUG_PRINTLN("AdafruitIO::connect()");
_last_mqtt_connect = 0; // need to start over fresh
_status = AIO_IDLE;
_last_ping = 0;
if (_err_sub) {
// setup error sub
_err_sub = new Adafruit_MQTT_Subscribe(_mqtt, _err_topic);
_mqtt->subscribe(_err_sub);
_err_sub->setCallback(errorCallback);
}
if (_throttle_sub) {
// setup throttle sub
_throttle_sub = new Adafruit_MQTT_Subscribe(_mqtt, _throttle_topic);
_mqtt->subscribe(_throttle_sub);
_throttle_sub->setCallback(errorCallback);
}
_connect();
}
/**************************************************************************/
/*!
@brief Disconnects from WiFi.
*/
/**************************************************************************/
void AdafruitIO::wifi_disconnect() {
AIO_DEBUG_PRINTLN("AdafruitIO::wifi_disconnect()");
_disconnect();
}
/**************************************************************************/
/*!
@brief Create a new AIO feed.
@param name
The AIO name of the feed.
@return A pointer to the feed.
*/
/**************************************************************************/
AdafruitIO_Feed *AdafruitIO::feed(const char *name) {
return new AdafruitIO_Feed(this, name);
}
/**************************************************************************/
/*!
@brief Create a new AIO feed.
@param name
The AIO name of the feed.
@param owner
The AIO name of the user that owns the feed, if not the current
user.
@return A pointer to the feed.
*/
/**************************************************************************/
AdafruitIO_Feed *AdafruitIO::feed(const char *name, const char *owner) {
return new AdafruitIO_Feed(this, name, owner);
}
/**************************************************************************/
/*!
@brief Create a new AIO time.
@param format
A format specifier.
@return A pointer to the time.
*/
/**************************************************************************/
AdafruitIO_Time *AdafruitIO::time(aio_time_format_t format) {
return new AdafruitIO_Time(this, format);
}
/**************************************************************************/
/*!
@brief Create a new AIO group.
@param name
The AIO name of the group.
@return A pointer to the group.
*/
/**************************************************************************/
AdafruitIO_Group *AdafruitIO::group(const char *name) {
return new AdafruitIO_Group(this, name);
}
/**************************************************************************/
/*!
@brief Create a new AIO dashboard.
@param name
The AIO name of the dashboard.
@return A pointer to the dashboard.
*/
/**************************************************************************/
AdafruitIO_Dashboard *AdafruitIO::dashboard(const char *name) {
return new AdafruitIO_Dashboard(this, name);
}
/**************************************************************************/
/*!
@brief Provide status explanation strings.
@return A pointer to the status string, _status. _status is the AIO status
value
*/
/**************************************************************************/
const __FlashStringHelper *AdafruitIO::statusText() {
switch (_status) {
// CONNECTING
case AIO_IDLE:
return F("Idle. Waiting for connect to be called...");
case AIO_NET_DISCONNECTED:
return F("Network disconnected.");
case AIO_DISCONNECTED:
return F("Disconnected from Adafruit IO.");
// FAILURE
case AIO_NET_CONNECT_FAILED:
return F("Network connection failed.");
case AIO_CONNECT_FAILED:
return F("Adafruit IO connection failed.");
case AIO_FINGERPRINT_INVALID:
return F("Adafruit IO SSL fingerprint verification failed.");
case AIO_AUTH_FAILED:
return F("Adafruit IO authentication failed.");
// SUCCESS
case AIO_NET_CONNECTED:
return F("Network connected.");
case AIO_CONNECTED:
return F("Adafruit IO connected.");
case AIO_CONNECTED_INSECURE:
return F("Adafruit IO connected. **THIS CONNECTION IS INSECURE** SSL/TLS "
"not supported for this platform.");
case AIO_FINGERPRINT_UNSUPPORTED:
return F("Adafruit IO connected over SSL/TLS. Fingerprint verification "
"unsupported.");
case AIO_FINGERPRINT_VALID:
return F("Adafruit IO connected over SSL/TLS. Fingerprint valid.");
default:
return F("Unknown status code");
}
}
/**************************************************************************/
/*!
@brief Must be called frequently to keep AIO connections alive. When
called with no arguments run() will try to repair MQTT and WiFi
connections before returning. To avoid potentially long timeout
delays, sketches can use the busywait_ms and fail_fast arguments
to return an imperfect status quickly. The calling sketch will
then need to respond appropriately to that status.
@param busywait_ms
The packet read timeout, optional.
@param fail_fast
Set true to skip retries and return with status immediately,
optional.
@return AIO status value
*/
/**************************************************************************/
aio_status_t AdafruitIO::run(uint16_t busywait_ms, bool fail_fast) {
uint32_t timeStart = millis();
if (status() < AIO_NET_CONNECTED) { // If we aren't network connected...
if (fail_fast)
return status(); // return status and fail quickly
else { // or try to reconnect from the start
AIO_ERROR_PRINT("run() connection failed -- retrying");
unsigned long started = millis();
connect();
// wait for a full AIO connection then carry on
while (status() < AIO_CONNECTED) {
// or return an error if the reconnection times out
if (millis() - started > AIO_NET_CONNECTION_TIMEOUT)
return status();
delay(500);
}
}
}
// loop until we have a connection
// mqttStatus() will try to reconnect before returning
while (mqttStatus(fail_fast) != AIO_CONNECTED &&
millis() - timeStart < AIO_MQTT_CONNECTION_TIMEOUT) {
}
if (mqttStatus(fail_fast) != AIO_CONNECTED)
return status();
if (busywait_ms > 0)
_packetread_timeout = busywait_ms;
_mqtt->processPackets(_packetread_timeout);
// ping to keep connection alive if needed
if (millis() > (_last_ping + AIO_PING_INTERVAL)) {
_mqtt->ping();
_last_ping = millis();
}
return status();
}
/**************************************************************************/
/*!
@brief Status check.
@return An AIO status value. Lower values represent poorer connection
status.
*/
/**************************************************************************/
aio_status_t AdafruitIO::status() {
aio_status_t net_status = networkStatus();
// if we aren't connected, return network status
if (net_status != AIO_NET_CONNECTED) {
_status = net_status;
return _status;
}
// check mqtt status and return
_status = mqttStatus();
return _status;
}
/**************************************************************************/
/*!
@brief Identify the board.
@return A board ID
*/
/**************************************************************************/
char *AdafruitIO::boardID() { return AdafruitIO_Board::id(); }
/**************************************************************************/
/*!
@brief Identify the board type.
@return A board type
*/
/**************************************************************************/
const char *AdafruitIO::boardType() { return AdafruitIO_Board::type(); }
/**************************************************************************/
/*!
@brief Identify the software version.
@return A pointer to a version number string.
*/
/**************************************************************************/
char *AdafruitIO::version() {
sprintf(_version, "%d.%d.%d", ADAFRUITIO_VERSION_MAJOR,
ADAFRUITIO_VERSION_MINOR, ADAFRUITIO_VERSION_PATCH);
return _version;
}
/**************************************************************************/
/*!
@brief Identify the user agent.
@return A pointer to a user agent string.
*/
/**************************************************************************/
char *AdafruitIO::userAgent() {
if (!_user_agent) {
_user_agent =
(char *)malloc(sizeof(char) * (strlen(version()) + strlen(boardType()) +
strlen(connectionType()) + 24));
strcpy(_user_agent, "AdafruitIO-Arduino/");
strcat(_user_agent, version());
strcat(_user_agent, " (");
strcat(_user_agent, boardType());
strcat(_user_agent, "-");
strcat(_user_agent, connectionType());
strcat(_user_agent, ")");
}
return _user_agent;
}
/**************************************************************************/
/*!
@brief Checks connection status with Adafruit IO's MQTT broker.
@param fail_fast
Set true to skip retries and return with status immediately.
@return True if connected, otherwise False.
*/
/**************************************************************************/
aio_status_t AdafruitIO::mqttStatus(bool fail_fast) {
// if the connection failed,
// return so we don't hammer IO
if (_status == AIO_CONNECT_FAILED) {
AIO_ERROR_PRINT("mqttStatus() failed to connect");
AIO_ERROR_PRINTLN(_mqtt->connectErrorString(_status));
return _status;
}
if (_mqtt->connected())
return AIO_CONNECTED;
// prevent fast reconnect attempts, except for the first time through
if (_last_mqtt_connect == 0 ||
millis() - _last_mqtt_connect > AIO_THROTTLE_RECONNECT_INTERVAL) {
_last_mqtt_connect = millis();
switch (_mqtt->connect(_username, _key)) {
case 0:
return AIO_CONNECTED;
case 1: // invalid mqtt protocol
case 2: // client id rejected
case 4: // malformed user/pass
case 5: // unauthorized
return AIO_CONNECT_FAILED;
case 3: // mqtt service unavailable
case 6: // throttled
case 7: // banned -> all MQTT bans are temporary, so eventual retry is
// permitted
// delay to prevent fast reconnects and fast returns (backward
// compatibility)
if (!fail_fast)
delay(AIO_THROTTLE_RECONNECT_INTERVAL);
return AIO_DISCONNECTED;
default:
return AIO_DISCONNECTED;
}
}
return AIO_DISCONNECTED;
}

View File

@@ -0,0 +1,174 @@
/*!
* @file AdafruitIO.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_H
#define ADAFRUITIO_H
#include "AdafruitIO_Dashboard.h"
#include "AdafruitIO_Data.h"
#include "AdafruitIO_Definitions.h"
#include "AdafruitIO_Feed.h"
#include "AdafruitIO_Group.h"
#include "AdafruitIO_Time.h"
#include "Adafruit_MQTT.h"
#include "Arduino.h"
#include "ArduinoHttpClient.h"
#include "util/AdafruitIO_Board.h"
#ifndef ADAFRUIT_MQTT_VERSION_MAJOR
#error \
"This sketch requires Adafruit MQTT Library v1.0.0 or higher. Please install or upgrade using the Library Manager."
#endif
#if ADAFRUIT_MQTT_VERSION_MAJOR == 1 && ADAFRUIT_MQTT_VERSION_MINOR < 0
#error \
"This sketch requires Adafruit MQTT Library v1.0.0 or higher. Please install or upgrade using the Library Manager."
#endif
/**************************************************************************/
/*!
@brief Class for interacting with Adafruit IO
*/
/**************************************************************************/
class AdafruitIO {
/**
* @brief AdafruitIO_Feed addition.
* @relates AdafruitIO_Feed
*/
friend class AdafruitIO_Feed;
/**
* @brief AdafruitIO_Group addition.
* @relates AdafruitIO_Group
*/
friend class AdafruitIO_Group;
/**
* @brief AdafruitIO_Dashboard addition.
* @relates AdafruitIO_Dashboard
*/
friend class AdafruitIO_Dashboard;
/**
* @brief AdafruitIO_Block addition.
* @relates AdafruitIO_Block
*/
friend class AdafruitIO_Block;
/**
* @brief AdafruitIO_Time addition.
* @relates AdafruitIO_Time
*/
friend class AdafruitIO_Time;
public:
AdafruitIO(const char *user, const char *key);
virtual ~AdafruitIO();
void connect();
void wifi_disconnect();
aio_status_t run(uint16_t busywait_ms = 0, bool fail_fast = false);
AdafruitIO_Feed *feed(const char *name);
AdafruitIO_Feed *feed(const char *name, const char *owner);
AdafruitIO_Group *group(const char *name);
AdafruitIO_Dashboard *dashboard(const char *name);
AdafruitIO_Time *time(aio_time_format_t format);
const __FlashStringHelper *statusText();
aio_status_t status();
/********************************************************************/
/*!
@brief Returns network module status.
@return 0
*/
/*******************************************************************/
virtual aio_status_t networkStatus() = 0;
/********************************************************************/
/*!
@brief Returns MQTT connection status.
*/
/*******************************************************************/
aio_status_t mqttStatus(bool fail_fast = false);
char *boardID();
const char *boardType();
char *version();
char *userAgent();
/********************************************************************/
/*!
@brief Returns the Adafruit IO network module connection type.
@return 0
*/
/*******************************************************************/
virtual const char *connectionType() = 0;
protected:
/********************************************************************/
/*!
@brief Establishes a connection with the Adafruit IO MQTT broker.
@return 0
*/
/*******************************************************************/
virtual void _connect() = 0;
/******************************************************/
/*!
@brief Disconnects from the Adafruit IO MQTT broker.
@return 0
*/
/*****************************************************/
virtual void _disconnect() = 0;
aio_status_t _status = AIO_IDLE; /*!< Adafruit IO Connection Status */
uint32_t _last_ping =
0; /*!< Previous time when client pinged Adafruit IO, in milliseconds */
uint32_t _last_mqtt_connect = 0; /*!< Previous time when client connected to
Adafruit IO, in milliseconds */
Adafruit_MQTT *_mqtt; /*!< Reference to Adafruit_MQTT, _mqtt. */
HttpClient *_http; /*!< Reference to HTTPClient, _http */
char _version[10]; /*!< Adafruit IO Arduino library version */
const char *_host = "io.adafruit.com"; /*!< Adafruit IO URL */
uint16_t _mqtt_port = 8883; /*!< Adafruit IO MQTT SSL port */
uint16_t _mqtt_eth_port =
1883; /*!< Adafruit IO MQTT insecure port, used by ethernet clients. */
uint16_t _http_port = 443; /*!< Adafruit IO HTTP SSL port */
uint16_t _packetread_timeout; /*!< Maximum amount of time to wait before
processing packets. */
const char *_username; /*!< Adafruit IO Username. */
const char *_key; /*!< Adafruit IO Key. */
char *_err_topic; /*!< Adafruit IO MQTT error message topic. */
char *_throttle_topic; /*!< Adafruit IO MQTT throttle message topic. */
char *_user_agent; /*!< Identifies the Adafruit IO client. */
Adafruit_MQTT_Subscribe
*_err_sub; /*!< Subscription to Adafruit IO Error topic. */
Adafruit_MQTT_Subscribe
*_throttle_sub; /*!< Subscription to Adafruit IO Throttle topic. */
private:
void _init();
};
#endif // ADAFRUITIO_H

View File

@@ -0,0 +1,234 @@
/*!
* @file AdafruitIO_Dashboard.cpp
*
*
* Adafruit invests time and resources providing this open source code.
* Please support Adafruit and open source hardware by purchasing
* products from Adafruit!
*
* Copyright (c) 2015-2016 Adafruit Industries
* Authors: Tony DiCola, Todd Treece
* Licensed under the MIT license.
*
* All text above must be included in any redistribution.
*
*/
#include "AdafruitIO_Dashboard.h"
#include "AdafruitIO.h"
/**************************************************************************/
/*!
@brief Sets Adafruit IO Dashboard instance.
@param *io
Reference to Adafruit IO class.
@param *n
Valid username string.
*/
/**************************************************************************/
AdafruitIO_Dashboard::AdafruitIO_Dashboard(AdafruitIO *io, const char *n) {
_io = io;
name = n;
}
AdafruitIO_Dashboard::~AdafruitIO_Dashboard() {}
/**************************************************************************/
/*!
@brief Checks if Adafruit IO Dashboard exists.
https://io.adafruit.com/api/docs/#return-dashboard
@return True if successful, otherwise False.
*/
/**************************************************************************/
bool AdafruitIO_Dashboard::exists() {
String url = "/api/v2/";
url += _io->_username;
url += "/dashboards/";
url += name;
_io->_http->beginRequest();
_io->_http->get(url.c_str());
_io->_http->sendHeader("X-AIO-Key", _io->_key);
_io->_http->endRequest();
int status = _io->_http->responseStatusCode();
_io->_http->responseBody(); // needs to be read even if not used
return status == 200;
}
/**************************************************************************/
/*!
@brief Creates a new dashboard.
https://io.adafruit.com/api/docs/#create-a-dashboard
@return True if successful, otherwise False.
*/
/**************************************************************************/
bool AdafruitIO_Dashboard::create() {
String url = "/api/v2/";
url += _io->_username;
url += "/dashboards";
String body = "name=";
body += name;
_io->_http->beginRequest();
_io->_http->post(url.c_str());
_io->_http->sendHeader("Content-Type", "application/x-www-form-urlencoded");
_io->_http->sendHeader("Content-Length", body.length());
_io->_http->sendHeader("X-AIO-Key", _io->_key);
// the following call to endRequest
// should be replaced by beginBody once the
// Arduino HTTP Client Library is updated
// _io->_http->beginBody();
_io->_http->endRequest();
_io->_http->print(body);
_io->_http->endRequest();
int status = _io->_http->responseStatusCode();
_io->_http->responseBody(); // needs to be read even if not used
return status == 201;
}
/**************************************************************************/
/*!
@brief Returns the dashboard owner.
@return Adafruit IO username.
*/
/**************************************************************************/
const char *AdafruitIO_Dashboard::user() { return _io->_username; }
AdafruitIO *AdafruitIO_Dashboard::io() { return _io; }
/**************************************************************************/
/*!
@brief Creates a new toggle block element on a dashboard connected
to provided feed.
@param *feed
Reference to an Adafruit IO feed.
@return Toggle block dashboard element.
*/
/**************************************************************************/
ToggleBlock *AdafruitIO_Dashboard::addToggleBlock(AdafruitIO_Feed *feed) {
return new ToggleBlock(this, feed);
}
/**************************************************************************/
/*!
@brief Creates a new momentary block element on a dashboard
connected to provided feed.
@param *feed
Reference to an Adafruit IO feed.
@return Momentary block dashboard element.
*/
/**************************************************************************/
MomentaryBlock *AdafruitIO_Dashboard::addMomentaryBlock(AdafruitIO_Feed *feed) {
return new MomentaryBlock(this, feed);
}
/**************************************************************************/
/*!
@brief Creates a new slider block element on a dashboard
connected to provided feed.
@param *feed
Reference to an Adafruit IO feed.
@return Slider block dashboard element.
*/
/**************************************************************************/
SliderBlock *AdafruitIO_Dashboard::addSliderBlock(AdafruitIO_Feed *feed) {
return new SliderBlock(this, feed);
}
/**************************************************************************/
/*!
@brief Creates a new gauge block element on a dashboard
connected to provided feed.
@param *feed
Reference to an Adafruit IO feed.
@return Gauge block dashboard element.
*/
/**************************************************************************/
GaugeBlock *AdafruitIO_Dashboard::addGaugeBlock(AdafruitIO_Feed *feed) {
return new GaugeBlock(this, feed);
}
/**************************************************************************/
/*!
@brief Creates a new momentary block element on a dashboard
connected to provided feed.
@param *feed
Reference to an Adafruit IO feed.
@return Text block dashboard element.
*/
/**************************************************************************/
TextBlock *AdafruitIO_Dashboard::addTextBlock(AdafruitIO_Feed *feed) {
return new TextBlock(this, feed);
}
/**************************************************************************/
/*!
@brief Creates a new chart block element on a dashboard
connected to provided feed.
@param *feed
Reference to an Adafruit IO feed.
@return Chart block dashboard element.
*/
/**************************************************************************/
ChartBlock *AdafruitIO_Dashboard::addChartBlock(AdafruitIO_Feed *feed) {
return new ChartBlock(this, feed);
}
/**************************************************************************/
/*!
@brief Creates a new color block element on a dashboard
connected to provided feed.
@param *feed
Reference to an Adafruit IO feed.
@return Color block dashboard element.
*/
/**************************************************************************/
ColorBlock *AdafruitIO_Dashboard::addColorBlock(AdafruitIO_Feed *feed) {
return new ColorBlock(this, feed);
}
/**************************************************************************/
/*!
@brief Creates a new map block element on a dashboard
connected to provided feed.
@param *feed
Reference to an Adafruit IO feed.
@return Map block dashboard element.
*/
/**************************************************************************/
MapBlock *AdafruitIO_Dashboard::addMapBlock(AdafruitIO_Feed *feed) {
return new MapBlock(this, feed);
}
/**************************************************************************/
/*!
@brief Creates a new stream block element on a dashboard
connected to provided feed.
@param *feed
Reference to an Adafruit IO feed.
@return Stream block dashboard element.
*/
/**************************************************************************/
StreamBlock *AdafruitIO_Dashboard::addStreamBlock(AdafruitIO_Feed *feed) {
return new StreamBlock(this, feed);
}
/**************************************************************************/
/*!
@brief Creates a new image block element on a dashboard
connected to provided feed.
@param *feed
Reference to an Adafruit IO feed.
@return Image block dashboard element.
*/
/**************************************************************************/
ImageBlock *AdafruitIO_Dashboard::addImageBlock(AdafruitIO_Feed *feed) {
return new ImageBlock(this, feed);
}

View File

@@ -0,0 +1,76 @@
/*!
* @file AdafruitIO_Dashboard.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_DASHBOARD_H
#define ADAFRUITIO_DASHBOARD_H
#include "AdafruitIO_Definitions.h"
#include "Arduino.h"
#include "blocks/ChartBlock.h"
#include "blocks/ColorBlock.h"
#include "blocks/GaugeBlock.h"
#include "blocks/ImageBlock.h"
#include "blocks/MapBlock.h"
#include "blocks/MomentaryBlock.h"
#include "blocks/SliderBlock.h"
#include "blocks/StreamBlock.h"
#include "blocks/TextBlock.h"
#include "blocks/ToggleBlock.h"
// forward declaration
class AdafruitIO;
class AdafruitIO_Feed;
/**************************************************************************/
/*!
@brief Class for interacting with Adafruit IO Dashboards.
https://io.adafruit.com/api/docs/#dashboards
*/
/**************************************************************************/
class AdafruitIO_Dashboard {
public:
AdafruitIO_Dashboard(AdafruitIO *io, const char *name);
~AdafruitIO_Dashboard();
const char *name; /*!< Dashboard name. */
const char *user(); /*!< Dashboard owner's Adafruit IO username. */
/**************************************************************************/
/*!
@brief Creates an instance of AdafruitIO.
@return True
*/
/**************************************************************************/
AdafruitIO *io();
bool exists();
bool create();
ToggleBlock *addToggleBlock(AdafruitIO_Feed *feed);
MomentaryBlock *addMomentaryBlock(AdafruitIO_Feed *feed);
SliderBlock *addSliderBlock(AdafruitIO_Feed *feed);
GaugeBlock *addGaugeBlock(AdafruitIO_Feed *feed);
TextBlock *addTextBlock(AdafruitIO_Feed *feed);
ChartBlock *addChartBlock(AdafruitIO_Feed *feed);
ColorBlock *addColorBlock(AdafruitIO_Feed *feed);
MapBlock *addMapBlock(AdafruitIO_Feed *feed);
StreamBlock *addStreamBlock(AdafruitIO_Feed *feed);
ImageBlock *addImageBlock(AdafruitIO_Feed *feed);
private:
AdafruitIO *_io; /*!< Reference to Adafruit IO client */
};
#endif // ADAFRUITIO_DASHBOARD_H

View File

@@ -0,0 +1,915 @@
/*!
* @file AdafruitIO_Data.cpp
*
*
* Adafruit invests time and resources providing this open source code.
* Please support Adafruit and open source hardware by purchasing
* products from Adafruit!
*
* Copyright (c) 2015-2016 Adafruit Industries
* Authors: Tony DiCola, Todd Treece
* Licensed under the MIT license.
*
* All text above must be included in any redistribution.
*
*/
#include "AdafruitIO_Data.h"
#include "AdafruitIO_Feed.h"
/**************************************************************************/
/*!
@brief Sets up an Adafruit IO Data Record.
*/
/**************************************************************************/
AdafruitIO_Data::AdafruitIO_Data() {
_lat = 0;
_lon = 0;
_ele = 0;
next_data = 0;
memset(_feed, 0, AIO_FEED_NAME_LENGTH);
memset(_value, 0, AIO_DATA_LENGTH);
memset(_csv, 0, AIO_CSV_LENGTH);
}
/**************************************************************************/
/*!
@brief Sets up an Adafruit IO Data Record
@param *f
A reference to an Adafruit IO Feed name.
*/
/**************************************************************************/
AdafruitIO_Data::AdafruitIO_Data(AdafruitIO_Feed *f) {
_lat = 0;
_lon = 0;
_ele = 0;
next_data = 0;
memset(_feed, 0, AIO_FEED_NAME_LENGTH);
strcpy(_feed, f->name);
memset(_value, 0, AIO_DATA_LENGTH);
memset(_csv, 0, AIO_CSV_LENGTH);
}
/**************************************************************************/
/*!
@brief Sets up an Adafruit IO Data Record
@param *f
A reference to an Adafruit IO Feed name.
@param *csv
A reference to a comma-separated-value list.
*/
/**************************************************************************/
AdafruitIO_Data::AdafruitIO_Data(AdafruitIO_Feed *f, char *csv) {
_lat = 0;
_lon = 0;
_ele = 0;
next_data = 0;
memset(_feed, 0, AIO_FEED_NAME_LENGTH);
strcpy(_feed, f->name);
memset(_value, 0, AIO_DATA_LENGTH);
memset(_csv, 0, AIO_CSV_LENGTH);
strcpy(_csv, csv);
_parseCSV();
}
/**************************************************************************/
/*!
@brief Sets up an Adafruit IO Data Record
@param *f
A reference to an Adafruit IO Feed name.
@param *csv
A reference to a fixed comma-separated-value list
*/
/**************************************************************************/
AdafruitIO_Data::AdafruitIO_Data(AdafruitIO_Feed *f, const char *csv) {
_lat = 0;
_lon = 0;
_ele = 0;
next_data = 0;
memset(_feed, 0, AIO_FEED_NAME_LENGTH);
strcpy(_feed, f->name);
memset(_value, 0, AIO_DATA_LENGTH);
memset(_csv, 0, AIO_CSV_LENGTH);
strcpy(_csv, csv);
_parseCSV();
}
/**************************************************************************/
/*!
@brief Sets up an Adafruit IO Data Record
@param *f
A reference to a fixed Adafruit IO Feed name.
*/
/**************************************************************************/
AdafruitIO_Data::AdafruitIO_Data(const char *f) {
_lat = 0;
_lon = 0;
_ele = 0;
next_data = 0;
memset(_feed, 0, AIO_FEED_NAME_LENGTH);
strcpy(_feed, f);
memset(_value, 0, AIO_DATA_LENGTH);
}
/**************************************************************************/
/*!
@brief Sets up an Adafruit IO Data Record
@param *f
A reference to a fixed Adafruit IO Feed name.
@param *csv
A reference to a comma-separated-value list
*/
/**************************************************************************/
AdafruitIO_Data::AdafruitIO_Data(const char *f, char *csv) {
_lat = 0;
_lon = 0;
_ele = 0;
next_data = 0;
memset(_feed, 0, AIO_FEED_NAME_LENGTH);
strcpy(_feed, f);
memset(_value, 0, AIO_DATA_LENGTH);
memset(_csv, 0, AIO_CSV_LENGTH);
strcpy(_csv, csv);
_parseCSV();
}
/**************************************************************************/
/*!
@brief Sets data to be returned by AdafruitIO_Feed subCallback.
@param *csv
Data to be appended to csv
@return csv
*/
/**************************************************************************/
bool AdafruitIO_Data::setCSV(char *csv) { return setCSV((const char *)(csv)); }
/**************************************************************************/
/*!
@brief Sets data to be returned by AdafruitIO_Feed subCallback.
@param *csv
Data to be appended to csv
@return True if the CSV was parsed successfully, False if not
*/
/**************************************************************************/
bool AdafruitIO_Data::setCSV(const char *csv) {
memset(_csv, 0, AIO_CSV_LENGTH);
strcpy(_csv, csv);
return _parseCSV();
}
/**************************************************************************/
/*!
@brief Sets Adafruit IO Feed location metadata.
@param lat
Latitude value for feed datum.
@param lon
Longitude value for feed datum.
@param ele
Elevation value for datum.
*/
/**************************************************************************/
void AdafruitIO_Data::setLocation(double lat, double lon, double ele) {
// if lat, lon, ele == 0, don't set them
if ((abs(0 - lat) < 0.000001) && (abs(0 - lon) < 0.000001) &&
(abs(0 - ele) < 0.000001))
return;
_lat = lat;
_lon = lon;
_ele = ele;
}
/**************************************************************************/
/*!
@brief Sets Adafruit IO Feed value field.
@param value
Data record's value field as a char.
@param lat
Data record's latitude field.
@param lon
Data record's longitude field.
@param ele
Data record's elevation field.
*/
/**************************************************************************/
void AdafruitIO_Data::setValue(const char *value, double lat, double lon,
double ele) {
strcpy(_value, value);
setLocation(lat, lon, ele);
}
/**************************************************************************/
/*!
@brief Sets Adafruit IO Feed value field.
@param value
Data record's value field as a char.
@param lat
Data record's latitude field.
@param lon
Data record's longitude field.
@param ele
Data record's elevation field.
*/
/**************************************************************************/
void AdafruitIO_Data::setValue(char *value, double lat, double lon,
double ele) {
strcpy(_value, value);
setLocation(lat, lon, ele);
}
/**************************************************************************/
/*!
@brief Sets Adafruit IO Feed value field.
@param value
Data record's value field, as a boolean.
@param lat
Data record's latitude field.
@param lon
Data record's longitude field.
@param ele
Data record's elevation field.
*/
/**************************************************************************/
void AdafruitIO_Data::setValue(bool value, double lat, double lon, double ele) {
if (value)
strcpy(_value, "1");
else
strcpy(_value, "0");
setLocation(lat, lon, ele);
}
/**************************************************************************/
/*!
@brief Sets Adafruit IO Feed value field.
@param value
Data record's value field as a String.
@param lat
Data record's latitude field.
@param lon
Data record's longitude field.
@param ele
Data record's elevation field.
*/
/**************************************************************************/
void AdafruitIO_Data::setValue(String value, double lat, double lon,
double ele) {
value.toCharArray(_value, value.length() + 1);
setLocation(lat, lon, ele);
}
/**************************************************************************/
/*!
@brief Sets Adafruit IO Feed value field.
@param value
Data record's value field.
@param lat
Data record's latitude field.
@param lon
Data record's longitude field.
@param ele
Data record's elevation field.
*/
/**************************************************************************/
void AdafruitIO_Data::setValue(int value, double lat, double lon, double ele) {
memset(_value, 0, AIO_DATA_LENGTH);
itoa(value, _value, 10);
setLocation(lat, lon, ele);
}
/**************************************************************************/
/*!
@brief Sets Adafruit IO Feed value field.
@param value
Data record's value field.
@param lat
Data record's latitude field.
@param lon
Data record's longitude field.
@param ele
Data record's elevation field.
*/
/**************************************************************************/
void AdafruitIO_Data::setValue(unsigned int value, double lat, double lon,
double ele) {
memset(_value, 0, AIO_DATA_LENGTH);
utoa(value, _value, 10);
setLocation(lat, lon, ele);
}
/**************************************************************************/
/*!
@brief Sets Adafruit IO Feed value field.
@param value
Data record's value field.
@param lat
Data record's latitude field.
@param lon
Data record's longitude field.
@param ele
Data record's elevation field.
*/
/**************************************************************************/
void AdafruitIO_Data::setValue(long value, double lat, double lon, double ele) {
memset(_value, 0, AIO_DATA_LENGTH);
ltoa(value, _value, 10);
setLocation(lat, lon, ele);
}
/**************************************************************************/
/*!
@brief Sets Adafruit IO Feed value field.
@param value
Data record's value field.
@param lat
Data record's latitude field.
@param lon
Data record's longitude field.
@param ele
Data record's elevation field.
*/
/**************************************************************************/
void AdafruitIO_Data::setValue(unsigned long value, double lat, double lon,
double ele) {
memset(_value, 0, AIO_DATA_LENGTH);
ultoa(value, _value, 10);
setLocation(lat, lon, ele);
}
/**************************************************************************/
/*!
@brief Sets Adafruit IO Feed value field.
@param value
Data record's value field.
@param lat
Data record's latitude field.
@param lon
Data record's longitude field.
@param ele
Data record's elevation field.
@param precision
Desired decimals of precision for value.
*/
/**************************************************************************/
void AdafruitIO_Data::setValue(float value, double lat, double lon, double ele,
int precision) {
memset(_value, 0, AIO_DATA_LENGTH);
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
// Use avrlibc dtostre function on AVR platforms.
dtostre(value, _value, precision, 0);
#elif defined(ESP8266)
// ESP8266 Arduino only implements dtostrf and not dtostre. Use dtostrf
// but accept a hint as to how many decimals of precision are desired.
dtostrf(value, 0, precision, _value);
#else
// Otherwise fall back to snprintf on other platforms.
snprintf(_value, sizeof(_value) - 1, "%0.*f", precision, value);
#endif
setLocation(lat, lon, ele);
}
/**************************************************************************/
/*!
@brief Sets Adafruit IO Feed value field.
@param value
Data record's value field.
@param lat
Data record's latitude field.
@param lon
Data record's longitude field.
@param ele
Data record's elevation field.
@param precision
Desired decimals of precision for value.
*/
/**************************************************************************/
void AdafruitIO_Data::setValue(double value, double lat, double lon, double ele,
int precision) {
memset(_value, 0, AIO_DATA_LENGTH);
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
// Use avrlibc dtostre function on AVR platforms.
dtostre(value, _value, precision, 0);
#elif defined(ESP8266)
// ESP8266 Arduino only implements dtostrf and not dtostre. Use dtostrf
// but accept a hint as to how many decimals of precision are desired.
dtostrf(value, 0, precision, _value);
#else
// Otherwise fall back to snprintf on other platforms.
snprintf(_value, sizeof(_value) - 1, "%0.*f", precision, value);
#endif
setLocation(lat, lon, ele);
}
/**************************************************************************/
/*!
@brief Returns existing Adafruit IO feed name.
@return Feed's name if feed exists.
*/
/**************************************************************************/
char *AdafruitIO_Data::feedName() { return _feed; }
/**************************************************************************/
/*!
@brief Converts provided value to char.
@return Char value.
*/
/**************************************************************************/
char *AdafruitIO_Data::value() { return toChar(); }
/**************************************************************************/
/*!
@brief Converts value to char.
@return value.
*/
/**************************************************************************/
char *AdafruitIO_Data::toChar() { return _value; }
/**************************************************************************/
/*!
@brief Converts value to string
@return String of value.
*/
/**************************************************************************/
String AdafruitIO_Data::toString() { return String(_value); }
/**************************************************************************/
/*!
@brief Converts value to Boolean.
@return True if value string equals Boolean True, False if not.
*/
/**************************************************************************/
bool AdafruitIO_Data::toBool() {
if (strcmp(_value, "1") == 0 || _value[0] == 't' || _value[0] == 'T')
return true;
return false;
}
/**************************************************************************/
/*!
@brief Checks if value is True
@return True if value string equals Boolean True, False if not.
*/
/**************************************************************************/
bool AdafruitIO_Data::isTrue() { return toBool(); }
/**************************************************************************/
/*!
@brief Checks if value is False
@return True if value string equals Boolean False, False if not.
*/
/**************************************************************************/
bool AdafruitIO_Data::isFalse() { return !toBool(); }
/**************************************************************************/
/*!
@brief Converts provided String value to Integer.
@return Integer of value, False if no value provided.
*/
/**************************************************************************/
int AdafruitIO_Data::toInt() {
char *endptr;
return (int)strtol(_value, &endptr, 10);
}
/**************************************************************************/
/*!
@brief Checks digital pin level.
@return HIGH if digital pin level is Boolean True, LOW if digital
pin level is False.
*/
/**************************************************************************/
int AdafruitIO_Data::toPinLevel() {
if (isTrue())
return HIGH;
else
return LOW;
}
/**************************************************************************/
/*!
@brief Converts value to to an Unsigned Integer value.
@return Unsigned Integer, False if no value provided.
*/
/**************************************************************************/
unsigned int AdafruitIO_Data::toUnsignedInt() {
char *endptr;
#ifdef ESP8266
// For some reason strtoul is not defined on the ESP8266 platform right now.
// Just use a strtol function and hope for the best.
return (unsigned int)strtol(_value, &endptr, 10);
#else
return (unsigned int)strtoul(_value, &endptr, 10);
#endif
}
/**************************************************************************/
/*!
@brief Converts value to a floating point value.
@return Float value, False if no value provided.
*/
/**************************************************************************/
float AdafruitIO_Data::toFloat() {
char *endptr;
return (float)strtod(_value, &endptr);
}
/**************************************************************************/
/*!
@brief Converts value to to a double value.
@return Double value, False if no value provided.
*/
/**************************************************************************/
double AdafruitIO_Data::toDouble() {
char *endptr;
return strtod(_value, &endptr);
}
/**************************************************************************/
/*!
@brief Converts value to to a long value.
@return long value, False if no value provided.
*/
/**************************************************************************/
long AdafruitIO_Data::toLong() {
char *endptr;
return strtol(_value, &endptr, 10);
}
/**************************************************************************/
/*!
@brief Converts value to to an unsigned long value.
@return Unsigned long value, False if no value provided.
*/
/**************************************************************************/
unsigned long AdafruitIO_Data::toUnsignedLong() {
char *endptr;
#ifdef ESP8266
// For some reason strtoul is not defined on the ESP8266 platform right now.
// Just use a strtol function and hope for the best.
return (unsigned long)strtol(_value, &endptr, 10);
#else
return strtoul(_value, &endptr, 10);
#endif
}
/**************************************************************************/
/*!
@brief Returns RR from 0xRRGGBB value
@return Red hexadecimal value.
*/
/**************************************************************************/
int AdafruitIO_Data::toRed() {
// Convert 0xRRGGBB to red.
char r[5];
strcpy(r, "0x");
strncpy(&r[2], toChar() + 1, 2);
r[4] = '\x00';
return (int)strtol(r, NULL, 0);
}
/**************************************************************************/
/*!
@brief Returns GG from 0xRRGGBB value
@return Green hexadecimal value.
*/
/**************************************************************************/
int AdafruitIO_Data::toGreen() {
// Convert 0xRRGGBB to green.
char g[5];
strcpy(g, "0x");
strncpy(&g[2], toChar() + 3, 2);
g[4] = '\x00';
return (int)strtol(g, NULL, 0);
}
/**************************************************************************/
/*!
@brief Returns BB from 0xRRGGBB value
@return Blue hexadecimal value.
*/
/**************************************************************************/
int AdafruitIO_Data::toBlue() {
// Convert 0xRRGGBB to blue.
char b[5];
strcpy(b, "0x");
strncpy(&b[2], toChar() + 5, 2);
b[4] = '\x00';
return (int)strtol(b, NULL, 0);
}
/**************************************************************************/
/*!
@brief Creates a RGB Tuple usable by Adafruit_NeoPixel's
setPixelColor method
@return RGB tuple as a hexadecimal value.
*/
/**************************************************************************/
long AdafruitIO_Data::toNeoPixel() {
char rgb[9];
strcpy(rgb, "0x");
strncpy(&rgb[2], toChar() + 1, 6);
return strtol(rgb, NULL, 0);
}
/**************************************************************************/
/*!
@brief Creates a list of comma-separated-values for an Adafruit IO
data record.
@return _csv
*/
/**************************************************************************/
char *AdafruitIO_Data::toCSV() {
memset(_csv, 0, AIO_CSV_LENGTH);
strcpy(_csv, "\"");
strcat(_csv, _value);
strcat(_csv, "\",");
strcat(_csv, charFromDouble(_lat));
strcat(_csv, ",");
strcat(_csv, charFromDouble(_lon));
strcat(_csv, ",");
strcat(_csv, charFromDouble(_ele, 2));
return _csv;
}
/**************************************************************************/
/*!
@brief Returns a data record's latitude value
@return _lat
*/
/**************************************************************************/
double AdafruitIO_Data::lat() { return _lat; }
/**************************************************************************/
/*!
@brief Returns a data record's longitude value
@return _lon
*/
/**************************************************************************/
double AdafruitIO_Data::lon() { return _lon; }
/**************************************************************************/
/*!
@brief Returns a data record's elevation value
@return _ele
*/
/**************************************************************************/
double AdafruitIO_Data::ele() { return _ele; }
static char _double_buffer[20];
/**************************************************************************/
/*!
@brief Converts from a character to a double.
@param d
Double value.
@param precision
Desired level of decimal precision.
@return _double_buffer
*/
/**************************************************************************/
char *AdafruitIO_Data::charFromDouble(double d, int precision) {
memset(_double_buffer, 0, sizeof(_double_buffer));
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
// Use avrlibc dtostre function on AVR platforms.
dtostre(d, _double_buffer, 10, 0);
#elif defined(ESP8266)
// ESP8266 Arduino only implements dtostrf and not dtostre. Use dtostrf
// but accept a hint as to how many decimals of precision are desired.
dtostrf(d, 0, precision, _double_buffer);
#else
// Otherwise fall back to snprintf on other platforms.
snprintf(_double_buffer, sizeof(_double_buffer) - 1, "%f", d);
#endif
return _double_buffer;
}
/*
* From the csv_parser project by semitrivial
* https://github.com/semitrivial/csv_parser/blob/93246cac509f85da12c6bb8c641fa75cd863c34f/csv.c
* - retrieved 2017-11-09
*
* MIT License
*
* Copyright 2016 Samuel Alexander
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/
static int count_fields(const char *line) {
const char *ptr;
int cnt, fQuote;
for (cnt = 1, fQuote = 0, ptr = line; *ptr; ptr++) {
if (fQuote) {
if (*ptr == '\"') {
if (ptr[1] == '\"') {
ptr++;
continue;
}
fQuote = 0;
}
continue;
}
switch (*ptr) {
case '\"':
fQuote = 1;
continue;
case ',':
cnt++;
continue;
default:
continue;
}
}
if (fQuote) {
return -1;
}
return cnt;
}
/**************************************************************************/
/*!
@brief Extracts a NULL-terminated array of strings, one for every
cell in the row.
@param line
String containing linebreaks or no linebreaks, escaped by
"double quotes".
@return CSV buffer, buf, NULL otherwise.
*/
/**************************************************************************/
char **parse_csv(const char *line) {
char **buf, **bptr, *tmp, *tptr;
const char *ptr;
int fieldcnt, fQuote, fEnd;
fieldcnt = count_fields(line);
if (fieldcnt == -1) {
return NULL;
}
buf = (char **)malloc(sizeof(char *) * (fieldcnt + 1));
if (!buf) {
return NULL;
}
tmp = (char *)malloc(strlen(line) + 1);
if (!tmp) {
free(buf);
return NULL;
}
bptr = buf;
for (ptr = line, fQuote = 0, *tmp = '\0', tptr = tmp, fEnd = 0;; ptr++) {
if (fQuote) {
if (!*ptr) {
break;
}
if (*ptr == '\"') {
if (ptr[1] == '\"') {
*tptr++ = '\"';
ptr++;
continue;
}
fQuote = 0;
} else {
*tptr++ = *ptr;
}
continue;
}
switch (*ptr) {
case '\"':
fQuote = 1;
continue;
case '\0':
fEnd = 1;
break;
case ',':
*tptr = '\0';
*bptr = strdup(tmp);
if (!*bptr) {
for (bptr--; bptr >= buf; bptr--) {
free(*bptr);
}
free(buf);
free(tmp);
return NULL;
}
bptr++;
tptr = tmp;
if (fEnd) {
break;
} else {
continue;
}
default:
*tptr++ = *ptr;
continue;
}
if (fEnd) {
break;
}
}
*bptr = NULL;
free(tmp);
return buf;
}
//// END simple_csv SECTION
/**************************************************************************/
/*!
@brief Checks if command-separated-value (CSV) is parsable
@return True if CSV is parsable, False if not.
*/
/**************************************************************************/
bool AdafruitIO_Data::_parseCSV() {
int field_count = count_fields(_csv);
if (field_count > 0) {
// this is normal IO data in `value,lat,lon,ele` format
char **fields = parse_csv(_csv);
// first field is handled as string
strcpy(_value, fields[0]);
field_count--;
// locations fields are handled with char * to float conversion
if (field_count > 0) {
_lat = atof(fields[1]);
field_count--;
}
if (field_count > 0) {
_lon = atof(fields[1]);
field_count--;
}
if (field_count > 0) {
_ele = atof(fields[1]);
field_count--;
}
// cleanup to avoid leaks
int i = 0;
while (fields[i] != NULL) {
free(fields[i++]);
}
free(fields);
return field_count == 0;
} else {
return false;
}
return true;
}

View File

@@ -0,0 +1,106 @@
/*!
* @file AdafruitIO_Data.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_DATA_H
#define ADAFRUITIO_DATA_H
#include "AdafruitIO_Definitions.h"
#include "Arduino.h"
// forward decl
class AdafruitIO_Feed;
/**************************************************************************/
/*!
@brief Class for interacting with Adafruit IO Data Records.
https://io.adafruit.com/api/docs/#data
*/
/**************************************************************************/
class AdafruitIO_Data {
public:
AdafruitIO_Data();
AdafruitIO_Data(AdafruitIO_Feed *f);
AdafruitIO_Data(AdafruitIO_Feed *f, char *csv);
AdafruitIO_Data(AdafruitIO_Feed *f, const char *csv);
AdafruitIO_Data(const char *f);
AdafruitIO_Data(const char *f, char *csv);
bool setCSV(char *csv);
bool setCSV(const char *csv);
void setLocation(double lat, double lon, double ele = 0);
void setValue(const char *value, double lat = 0, double lon = 0,
double ele = 0);
void setValue(char *value, double lat = 0, double lon = 0, double ele = 0);
void setValue(bool value, double lat = 0, double lon = 0, double ele = 0);
void setValue(String value, double lat = 0, double lon = 0, double ele = 0);
void setValue(int value, double lat = 0, double lon = 0, double ele = 0);
void setValue(unsigned int value, double lat = 0, double lon = 0,
double ele = 0);
void setValue(long value, double lat = 0, double lon = 0, double ele = 0);
void setValue(unsigned long value, double lat = 0, double lon = 0,
double ele = 0);
void setValue(float value, double lat = 0, double lon = 0, double ele = 0,
int precision = 6);
void setValue(double value, double lat = 0, double lon = 0, double ele = 0,
int precision = 6);
char *feedName();
char *value();
char *toChar();
String toString();
bool toBool();
bool isTrue();
bool isFalse();
int toInt();
int toPinLevel();
unsigned int toUnsignedInt();
double toDouble();
float toFloat();
long toLong();
unsigned long toUnsignedLong();
int toRed();
int toGreen();
int toBlue();
long toNeoPixel();
char *toCSV();
char *charFromDouble(double d, int precision = 6);
double lat();
double lon();
double ele();
AdafruitIO_Data *next_data; /*!< next data value in Adafruit IO data record */
private:
char _feed[AIO_FEED_NAME_LENGTH];
char _csv[AIO_CSV_LENGTH];
char _value[AIO_DATA_LENGTH];
double _lat, _lon, _ele;
bool _parseCSV();
};
#endif // ADAFRUITIO_DATA_H

View File

@@ -0,0 +1,169 @@
/*!
* @file AdafruitIO_Definitions.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_DEFINITIONS_H_
#define ADAFRUITIO_DEFINITIONS_H_
#define ADAFRUITIO_VERSION_MAJOR 4 ///< Adafruit IO Arduino Major Semvar
#define ADAFRUITIO_VERSION_MINOR 2 ///< Adafruit IO Arduino Minor Semvar
#define ADAFRUITIO_VERSION_PATCH 1 ///< Adafruit IO Arduino Patch Semvar
// forward declaration
class AdafruitIO_Data;
typedef void (*AdafruitIODataCallbackType)(
AdafruitIO_Data *data); /*!< Data callback type */
/**************************************************************************/
/*!
@brief Class that contains methods for Adafruit IO MQTT callbacks.
*/
/**************************************************************************/
class AdafruitIOGroupCallback {
public:
/**************************************************************************/
/*!
@brief Sets up MQTT Group callbacks.
@param f
Valid Adafruit IO feed key.
@param cb
Adafruit IO MQTT callback.
*/
/**************************************************************************/
AdafruitIOGroupCallback(const char *f, AdafruitIODataCallbackType cb) {
feed = f;
dataCallback = cb;
next_cb = 0;
}
/**************************************************************************/
/*!
@brief Sets up MQTT Group callbacks.
@param cb
Adafruit IO MQTT callback.
*/
/**************************************************************************/
AdafruitIOGroupCallback(AdafruitIODataCallbackType cb) {
feed = 0;
dataCallback = cb;
next_cb = 0;
}
const char *feed; /*!< Adafruit IO feed name. */
AdafruitIODataCallbackType
dataCallback; /*!< data carried by an AdafruitIOGroupCallback. */
AdafruitIOGroupCallback *next_cb; /*!< Next callback number. */
};
// Uncomment/comment to turn on/off debug output messages.
// #define AIO_DEBUG
// Uncomment/comment to turn on/off error output
// #define AIO_ERROR
// note: if you're using something like Zero or Due, change the below to
// SerialUSB
#define AIO_PRINTER Serial ///< Where debug messages will be printed
// Define actual debug output functions when necessary.
#ifdef AIO_DEBUG
#define AIO_DEBUG_PRINT(...) \
{ AIO_PRINTER.print(__VA_ARGS__); } ///< Prints debug output.
#define AIO_DEBUG_PRINTLN(...) \
{ AIO_PRINTER.println(__VA_ARGS__); } ///< Prints line from debug output.
#else
#define AIO_DEBUG_PRINT(...) \
{} ///< Prints debug output
#define AIO_DEBUG_PRINTLN(...) \
{} ///< Prints line from debug output.
#endif
// Define actual error output functions when necessary.
#ifdef AIO_ERROR
#define AIO_ERROR_PRINT(...) \
{ AIO_PRINTER.print(__VA_ARGS__); } ///< Prints error output
#define AIO_ERROR_PRINTLN(...) \
{ AIO_PRINTER.println(__VA_ARGS__); } ///< Prints line from error output
#else
#define AIO_ERROR_PRINT(...) \
{} ///< Prints error output.
#define AIO_ERROR_PRINTLN(...) \
{} ///< Prints line from error output.
#endif
#define AIO_PING_INTERVAL 60000 ///< Adafruit IO Ping Interval, in milliseconds
#define AIO_THROTTLE_RECONNECT_INTERVAL \
60000 ///< Time to wait between re-connecting to Adafruit IO after throttled
#define AIO_MQTT_CONNECTION_TIMEOUT \
60000 ///< Time to wait for a successful reconnection after MQTT disconnect
#define AIO_NET_CONNECTION_TIMEOUT \
60000 ///< Time to wait for a successful reconnection after network disconnect
#define AIO_NET_DISCONNECT_WAIT \
300 ///< Time to wait for a net disconnect to take effect
#define AIO_ERROR_TOPIC "/errors" ///< Adafruit IO Error MQTT Topic
#define AIO_THROTTLE_TOPIC "/throttle" ///< Adafruit IO Throttle MQTT Topic
// latest fingerprint can be generated with
// echo | openssl s_client -connect io.adafruit.com:443 | openssl x509
// -fingerprint -noout
#define AIO_SSL_FINGERPRINT \
"4E C1 52 73 24 A8 36 D6 7A 4C 67 C7 91 0C 0A 22 B9 2D 5B CA" ///< Latest
///< Adafruit IO
///< SSL
///< Fingerprint
#define AIO_FEED_NAME_LENGTH \
258 ///< Maximum length of an Adafruit IO Feed: Name; 128 + 1 + 128 for the
///< group, a dot, and actual feed name.
#define AIO_DATA_LENGTH \
45 ///< Maximum length of data sent/recieved from Adafruit IO
#define AIO_CSV_LENGTH \
AIO_FEED_NAME_LENGTH + \
4 ///< Maximum comma-separated-value length from Adafruit IO
/** aio_status_t offers 13 status states */
typedef enum {
AIO_IDLE = 0, // Waiting for connection establishement
AIO_NET_DISCONNECTED = 1, // Network disconnected
AIO_DISCONNECTED = 2, // Disconnected from Adafruit IO
AIO_FINGERPRINT_UNKOWN = 3, // Unknown AIO_SSL_FINGERPRINT
AIO_NET_CONNECT_FAILED = 10, // Failed to connect to network
AIO_CONNECT_FAILED = 11, // Failed to connect to Adafruit IO
AIO_FINGERPRINT_INVALID = 12, // Unknown AIO_SSL_FINGERPRINT
AIO_AUTH_FAILED = 13, // Invalid Adafruit IO login credentials provided.
AIO_SSID_INVALID =
14, // SSID is "" or otherwise invalid, connection not attempted
AIO_NET_CONNECTED = 20, // Connected to Adafruit IO
AIO_CONNECTED = 21, // Connected to network
AIO_CONNECTED_INSECURE = 22, // Insecurely (non-SSL) connected to network
AIO_FINGERPRINT_UNSUPPORTED = 23, // Unsupported AIO_SSL_FINGERPRINT
AIO_FINGERPRINT_VALID = 24 // Valid AIO_SSL_FINGERPRINT
} aio_status_t;
/** Three different types of MQTT time feeds from IO */
typedef enum {
AIO_TIME_SECONDS = 0, // Seconds MQTT feed
AIO_TIME_MILLIS = 1, // Milisecond MQTT feed
AIO_TIME_ISO = 2 // ISO8601 MQTT Feed
} aio_time_format_t;
#endif /* ADAFRUITIO_DEFINITIONS_H_ */

View File

@@ -0,0 +1,114 @@
/*!
* @file AdafruitIO_Ethernet.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_ETHERNET_H
#define ADAFRUITIO_ETHERNET_H
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include "Arduino.h"
#include <SPI.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include "AdafruitIO.h"
/**************************************************************************/
/*!
@brief Class for interfacing with the Adafruit Ethernet FeatherWing
*/
/**************************************************************************/
class AdafruitIO_Ethernet : public AdafruitIO {
public:
/**************************************************************************/
/*!
@brief Instanciates an Adafruit Ethernet FeatherWing.
@param *user
Reference to a valid Adafruit IO Username.
@param *key
Reference to a valid Adafruit IO Key.
*/
/**************************************************************************/
AdafruitIO_Ethernet(const char *user, const char *key)
: AdafruitIO(user, key) {
_client = new EthernetClient();
_mqtt = new Adafruit_MQTT_Client(_client, _host, _mqtt_eth_port, _username,
_key);
_http = new HttpClient(*_client, _host, _http_port);
}
/**************************************************************************/
/*!
@brief Checks the connection status between the Ethernet
FeatherWing and Adafruit IO
@return True if connected to Adafruit IO, otherwise False.
*/
/**************************************************************************/
aio_status_t networkStatus() {
if (_status == AIO_NET_CONNECTED)
return _status;
_connect();
return _status;
}
/**************************************************************************/
/*!
@brief Defines network module type.
@return String "ethernet_wing"
*/
/**************************************************************************/
const char *connectionType() { return "ethernet_wing"; }
protected:
byte _mac[6] = {0xDE, 0xAD, 0xBE,
0xEF, 0xFE, 0xED}; /*!< Ethernet FeatherWing MAC Address */
EthernetClient *_client; /*!< Reference to EthernetClient, _client */
/**************************************************************************/
/*!
@brief Attempts to connect Ethernet FeatherWing to Adafruit IO
*/
/**************************************************************************/
void _connect() {
if (Ethernet.begin(_mac) == 0) {
_status = AIO_NET_DISCONNECTED;
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
AIO_DEBUG_PRINTLN("Ethernet FeatherWing not found! Please recheck "
"wiring connections.");
while (true)
delay(1); // do nothing, no point running without Ethernet hardware
}
} else {
_status = AIO_NET_CONNECTED;
}
}
/**************************************************************************/
/*!
@brief Disconnect the ethernet connection.
*/
/**************************************************************************/
void _disconnect() {
_client->stop();
delay(AIO_NET_DISCONNECT_WAIT);
}
};
#endif // ADAFRUITIO_ETHERNET_H

View File

@@ -0,0 +1,140 @@
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Copyright (c) 2015-2016 Adafruit Industries
// Authors: Tony DiCola, Todd Treece
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.
//
#ifndef ADAFRUITIO_FONA_H
#define ADAFRUITIO_FONA_H
#include "AdafruitIO.h"
#include "Adafruit_FONA.h"
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_FONA.h"
#include "Arduino.h"
#include <SoftwareSerial.h>
#define FONA_RX 9
#define FONA_TX 8
#define FONA_RST 4
#define FONA_RI 7
#define FONA_BAUD 4800
/**************************************************************************/
/*!
@brief Class for interfacing with an Adafruit FONA Ceullar Module
*/
/**************************************************************************/
class AdafruitIO_FONA : public AdafruitIO {
public:
/**************************************************************************/
/*!
@brief Initializes a new AdafruitIO_FONA instance.
@param user
GRPS APN username
@param key
GPRS APN password
*/
/**************************************************************************/
AdafruitIO_FONA(const char *user, const char *key) : AdafruitIO(user, key) {
_serial = new SoftwareSerial(FONA_TX, FONA_RX);
_fona = new Adafruit_FONA(FONA_RST);
_mqtt = new Adafruit_MQTT_FONA(_fona, _host, _mqtt_port);
_packetread_timeout = 500;
}
/**************************************************************************/
/*!
@brief Sets Adafruit Fona APN name
@param apn
GPRS APN name.
@param username
GPRS APN username.
@param password
GRPS APN password.
*/
/**************************************************************************/
void setAPN(FONAFlashStringPtr apn, FONAFlashStringPtr username = 0,
FONAFlashStringPtr password = 0) {
_fona->setGPRSNetworkSettings(apn, username, password);
}
/**************************************************************************/
/*!
@brief Returns network connection status.
@return Adafruit IO Network status, aio_status_t
*/
/**************************************************************************/
aio_status_t AdafruitIO_FONA::networkStatus() {
// return if in a failed state
if (_status == AIO_NET_CONNECT_FAILED)
return _status;
// if we are connected, return
if (_fona->GPRSstate())
return AIO_NET_CONNECTED;
// wait for connection to network
if (_fona->getNetworkStatus() != 1)
return AIO_NET_DISCONNECTED;
_fona->enableGPRS(true);
return AIO_NET_CONNECTED;
}
/**************************************************************************/
/*!
@brief Returns network module type.
@return Network module name, "fona"
*/
/**************************************************************************/
const char *connectionType() { return "fona"; }
protected:
uint16_t _mqtt_port = 1883; /*!< Adafruit IO insecure MQTT port. */
SoftwareSerial *_serial; /*!< an instance of SoftwareSerial. */
Adafruit_FONA *_fona; /*!< an instance of Adafruit_FONA. */
/**************************************************************************/
/*!
@brief Establishes a connection to Adafruit IO.
*/
/**************************************************************************/
void _connect() {
// set software serial baud rate
_serial->begin(FONA_BAUD);
// if fona can't be found, bail
if (!_fona->begin(*_serial)) {
_status = AIO_NET_CONNECT_FAILED;
return;
}
// disable cme error reporting
_serial->println("AT+CMEE=2");
_status = AIO_NET_DISCONNECTED;
}
/**************************************************************************/
/*!
@brief Disconnects from Adafruit IO and the cellular network.
*/
/**************************************************************************/
void _disconnect() {
if (!_fona->enableGPRS(false)) {
AIO_DEBUG_PRINTLN("Failed to turn off GPRS.");
}
_status = AIO_NET_DISCONNECTED;
}
};
#endif // ADAFRUITIO_FONA_H

View File

@@ -0,0 +1,489 @@
/*!
* @file AdafruitIO_Feed.cpp
*
*
* Adafruit invests time and resources providing this open source code.
* Please support Adafruit and open source hardware by purchasing
* products from Adafruit!
*
* Copyright (c) 2015-2016 Adafruit Industries
* Authors: Tony DiCola, Todd Treece
* Licensed under the MIT license.
*
* All text above must be included in any redistribution.
*
*/
#include "AdafruitIO_Feed.h"
#include "AdafruitIO.h"
/**************************************************************************/
/*!
@brief Creates a new instance of an Adafruit IO Feed.
@param *io
Reference to AdafruitIO.
@param *n
Valid feed name.
*/
/**************************************************************************/
AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n)
: AdafruitIO_MQTT() {
_io = io;
name = n;
owner = _io->_username;
_init();
}
/**************************************************************************/
/*!
@brief Creates a new instance of an Adafruit IO Feed.
@param *io
Reference to AdafruitIO.
@param *n
Valid feed name.
@param *un
Feed owner's Adafruit IO username.
*/
/**************************************************************************/
AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n, const char *un)
: AdafruitIO_MQTT() {
_io = io;
name = n;
owner = un;
_init();
}
/**************************************************************************/
/*!
@brief Adafruit IO Feed destructor.
*/
/**************************************************************************/
AdafruitIO_Feed::~AdafruitIO_Feed() {
if (_sub)
delete _sub;
if (_pub)
delete _pub;
if (_get_pub)
delete _get_pub;
if (data)
delete data;
if (_topic)
free(_topic);
if (_get_topic)
free(_get_topic);
if (_feed_url)
free(_feed_url);
if (_create_url)
free(_create_url);
}
/**************************************************************************/
/*!
@brief Creates a new onMessage callback.
@param cb
Adafruit IO callback.
*/
/**************************************************************************/
void AdafruitIO_Feed::onMessage(AdafruitIODataCallbackType cb) {
_dataCallback = cb;
}
/**************************************************************************/
/*!
@brief Updates Adafruit IO Feed.
@param value
Value to publish to feed.
@param lat
Latitude metadata.
@param lon
Longitudinal metadata.
@param ele
Elevation metadata.
@return True if data successfully published to feed, False otherwise.
*/
/**************************************************************************/
bool AdafruitIO_Feed::save(char *value, double lat, double lon, double ele) {
data->setValue(value, lat, lon, ele);
return _pub->publish(data->toCSV());
}
/**************************************************************************/
/*!
@brief Updates Adafruit IO Feed.
@param value
Value to publish to feed.
@param lat
Latitude metadata.
@param lon
Longitudinal metadata.
@param ele
Elevation metadata.
@return True if data successfully published to feed, False otherwise.
*/
/**************************************************************************/
bool AdafruitIO_Feed::save(bool value, double lat, double lon, double ele) {
data->setValue(value, lat, lon, ele);
return _pub->publish(data->toCSV());
}
/**************************************************************************/
/*!
@brief Updates Adafruit IO Feed.
@param value
Value to publish to feed.
@param lat
Latitude metadata.
@param lon
Longitudinal metadata.
@param ele
Elevation metadata.
@return True if data successfully published to feed, False otherwise.
*/
/**************************************************************************/
bool AdafruitIO_Feed::save(String value, double lat, double lon, double ele) {
data->setValue(value, lat, lon, ele);
return _pub->publish(data->toCSV());
}
/**************************************************************************/
/*!
@brief Updates Adafruit IO Feed.
@param value
Value to publish to feed.
@param lat
Latitude metadata.
@param lon
Longitudinal metadata.
@param ele
Elevation metadata.
@return True if data successfully published to feed, False otherwise.
*/
/**************************************************************************/
bool AdafruitIO_Feed::save(int value, double lat, double lon, double ele) {
data->setValue(value, lat, lon, ele);
return _pub->publish(data->toCSV());
}
/**************************************************************************/
/*!
@brief Updates Adafruit IO Feed.
@param value
Value to publish to feed.
@param lat
Latitude metadata.
@param lon
Longitudinal metadata.
@param ele
Elevation metadata.
@return True if data successfully published to feed, False otherwise.
*/
/**************************************************************************/
bool AdafruitIO_Feed::save(unsigned int value, double lat, double lon,
double ele) {
data->setValue(value, lat, lon, ele);
return _pub->publish(data->toCSV());
}
/**************************************************************************/
/*!
@brief Updates Adafruit IO Feed.
@param value
Value to publish to feed.
@param lat
Latitude metadata.
@param lon
Longitudinal metadata.
@param ele
Elevation metadata.
@return True if data successfully published to feed, False otherwise.
*/
/**************************************************************************/
bool AdafruitIO_Feed::save(long value, double lat, double lon, double ele) {
data->setValue(value, lat, lon, ele);
return _pub->publish(data->toCSV());
}
/**************************************************************************/
/*!
@brief Updates Adafruit IO Feed.
@param value
Value to publish to feed.
@param lat
Latitude metadata.
@param lon
Longitudinal metadata.
@param ele
Elevation metadata.
@return True if data successfully published to feed, False otherwise.
*/
/**************************************************************************/
bool AdafruitIO_Feed::save(unsigned long value, double lat, double lon,
double ele) {
data->setValue(value, lat, lon, ele);
return _pub->publish(data->toCSV());
}
/**************************************************************************/
/*!
@brief Updates Adafruit IO Feed.
@param value
Value to publish to feed.
@param lat
Latitude metadata.
@param lon
Longitudinal metadata.
@param ele
Elevation metadata.
@param precision
Desired amount of decimal precision.
@return True if data successfully published to feed, False otherwise.
*/
/**************************************************************************/
bool AdafruitIO_Feed::save(float value, double lat, double lon, double ele,
int precision) {
data->setValue(value, lat, lon, ele, precision);
return _pub->publish(data->toCSV());
}
/**************************************************************************/
/*!
@brief Updates Adafruit IO Feed.
@param value
Value to publish to feed.
@param lat
Latitude metadata.
@param lon
Longitudinal metadata.
@param ele
Elevation metadata.
@param precision
Desired amount of decimal precision.
@return True if data successfully published to feed, False otherwise.
*/
/**************************************************************************/
bool AdafruitIO_Feed::save(double value, double lat, double lon, double ele,
int precision) {
data->setValue(value, lat, lon, ele, precision);
return _pub->publish(data->toCSV());
}
/****************************************************************************/
/*!
@brief Publishes a null character to an Adafruit IO /get topic.
https://io.adafruit.com/api/docs/mqtt.html#using-the-get-topic
@return True if successful, otherwise False.
*/
/****************************************************************************/
bool AdafruitIO_Feed::get() { return _get_pub->publish("\0"); }
/****************************************************************************/
/*!
@brief Checks if Adafruit IO Feed exists and belongs to username.
https://io.adafruit.com/api/docs/#get-feed
@return True if successful, otherwise False.
*/
/****************************************************************************/
bool AdafruitIO_Feed::exists() {
_io->_http->beginRequest();
_io->_http->get(_feed_url);
_io->_http->sendHeader("X-AIO-Key", _io->_key);
_io->_http->endRequest();
int status = _io->_http->responseStatusCode();
_io->_http->responseBody(); // needs to be read even if not used
return status == 200;
}
/**************************************************************/
/*!
@brief Creates a new Adafruit IO Feed
https://io.adafruit.com/api/docs/#create-feed
@return True if successful, otherwise False.
*/
/*************************************************************/
bool AdafruitIO_Feed::create() {
String body = "name=";
body += name;
_io->_http->beginRequest();
_io->_http->post(_create_url);
_io->_http->sendHeader("Content-Type", "application/x-www-form-urlencoded");
_io->_http->sendHeader("Content-Length", body.length());
_io->_http->sendHeader("X-AIO-Key", _io->_key);
// the following call to endRequest
// should be replaced by beginBody once the
// Arduino HTTP Client Library is updated
// _io->_http->beginBody();
_io->_http->endRequest();
_io->_http->print(body);
_io->_http->endRequest();
int status = _io->_http->responseStatusCode();
_io->_http->responseBody(); // needs to be read even if not used
return status == 201;
}
/*****************************************************************************/
/*!
@brief Retrieves the most recent value published to a feed.
https://io.adafruit.com/api/docs/mqtt.html#using-the-get-topic
@return NULL
*/
/*****************************************************************************/
AdafruitIO_Data *AdafruitIO_Feed::lastValue() {
// 15 extra for api path, 12 for /data/retain, 1 for null
String url = "/api/v2/";
url += owner;
url += "/feeds/";
url += name;
url += "/data/retain";
AIO_DEBUG_PRINT("lastValue get ");
AIO_DEBUG_PRINTLN(url);
_io->_http->beginRequest();
_io->_http->get(url.c_str());
_io->_http->sendHeader("X-AIO-Key", _io->_key);
_io->_http->endRequest();
int status = _io->_http->responseStatusCode();
String body = _io->_http->responseBody();
if (status >= 200 && status <= 299) {
if (body.length() > 0) {
return new AdafruitIO_Data(this, body.c_str());
}
return NULL;
} else {
AIO_ERROR_PRINT("error retrieving lastValue, status: ");
AIO_ERROR_PRINTLN(status);
AIO_ERROR_PRINT("response body: ");
AIO_ERROR_PRINTLN(_io->_http->responseBody());
return NULL;
}
}
/**************************************************************************/
/*!
@brief Sets Adafruit IO feed location metadata.
@param lat
Latitude metadata.
@param lon
Longitudinal metadata.
@param ele
Elevation metadata.
*/
/**************************************************************************/
void AdafruitIO_Feed::setLocation(double lat, double lon, double ele) {
data->setLocation(lat, lon, ele);
}
/**************************************************************************/
/*!
@brief Calls _datacallback if new data is avaliable on feed.
@param val
Value to publish to Adafruit IO feed.
@param len
Feed length.
*/
/**************************************************************************/
void AdafruitIO_Feed::subCallback(char *val, uint16_t len) {
data->setCSV(val);
// call callback with data
if (_dataCallback)
_dataCallback(data);
}
/**************************************************************************/
/*!
@brief Initialize MQTT topics and REST URLs for Adafruit IO feeds.
*/
/**************************************************************************/
void AdafruitIO_Feed::_init() {
_sub = 0;
_pub = 0;
_get_pub = 0;
_dataCallback = 0;
// dynamically allocate memory for mqtt topic and REST URLs
_topic = (char *)malloc(
sizeof(char) * (strlen(owner) + strlen(name) +
8)); // 8 extra chars for /f/, /csv & null termination
_get_topic = (char *)malloc(
sizeof(char) *
(strlen(owner) + strlen(name) +
12)); // 12 extra chars for /f/, /csv/get & null termination
_feed_url =
(char *)malloc(sizeof(char) * (strlen(owner) + strlen(name) +
16)); // 16 extra for api path & null term
_create_url = (char *)malloc(
sizeof(char) * (strlen(owner) + 15)); // 15 extra for api path & null term
// init feed data
data = new AdafruitIO_Data(this);
if (_topic && _create_url && _feed_url) {
// build topic string
strcpy(_topic, owner);
strcat(_topic, "/f/");
strcat(_topic, name);
strcat(_topic, "/csv");
// build feed url string
strcpy(_feed_url, "/api/v2/");
strcat(_feed_url, owner);
strcat(_feed_url, "/feeds/");
strcat(_feed_url, name);
// build create url string
strcpy(_create_url, "/api/v2/");
strcat(_create_url, owner);
strcat(_create_url, "/feeds");
// build /get topic string
strcpy(_get_topic, owner);
strcat(_get_topic, "/f/");
strcat(_get_topic, name);
strcat(_get_topic, "/csv/get");
// setup subscription
_sub = new Adafruit_MQTT_Subscribe(_io->_mqtt, _topic);
_pub = new Adafruit_MQTT_Publish(_io->_mqtt, _topic);
_get_pub = new Adafruit_MQTT_Publish(_io->_mqtt, _get_topic);
_io->_mqtt->subscribe(_sub);
_sub->setCallback(this, &AdafruitIO_MQTT::subCallback);
} else {
// malloc failed
_topic = 0;
_get_topic = 0;
_create_url = 0;
_feed_url = 0;
_sub = 0;
_pub = 0;
_get_pub = 0;
data = 0;
}
}

View File

@@ -0,0 +1,90 @@
/*!
* @file AdafruitIO_Feed.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_FEED_H
#define ADAFRUITIO_FEED_H
#include "AdafruitIO_Data.h"
#include "AdafruitIO_Definitions.h"
#include "AdafruitIO_MQTT.h"
#include "Adafruit_MQTT.h"
#include "Arduino.h"
// forward declaration
class AdafruitIO;
/**************************************************************************/
/*!
@brief Class that provides methods for interfacing with
Adafruit IO feed topics.
https://io.adafruit.com/api/docs/mqtt.html#mqtt-topics
*/
/**************************************************************************/
class AdafruitIO_Feed : public AdafruitIO_MQTT {
public:
AdafruitIO_Feed(AdafruitIO *io, const char *name);
AdafruitIO_Feed(AdafruitIO *io, const char *name, const char *owner);
~AdafruitIO_Feed();
bool save(char *value, double lat = 0, double lon = 0, double ele = 0);
bool save(bool value, double lat = 0, double lon = 0, double ele = 0);
bool save(String value, double lat = 0, double lon = 0, double ele = 0);
bool save(int value, double lat = 0, double lon = 0, double ele = 0);
bool save(unsigned int value, double lat = 0, double lon = 0, double ele = 0);
bool save(long value, double lat = 0, double lon = 0, double ele = 0);
bool save(unsigned long value, double lat = 0, double lon = 0,
double ele = 0);
bool save(float value, double lat = 0, double lon = 0, double ele = 0,
int precision = 6);
bool save(double value, double lat = 0, double lon = 0, double ele = 0,
int precision = 6);
bool get();
bool exists();
bool create();
void setLocation(double lat, double lon, double ele = 0);
void onMessage(AdafruitIODataCallbackType cb);
void subCallback(char *val, uint16_t len);
const char *name; /*!< Adafruit IO feed name. */
const char *owner; /*!< Adafruit IO feed owner. */
AdafruitIO_Data *lastValue(); /*!< Last value sent to Adafruit IO feed. */
AdafruitIO_Data *data; /*!< Adafruit IO feed data record. */
private:
AdafruitIODataCallbackType
_dataCallback; /*!< Callback from onMessage containing data. */
void _init();
char *_topic; /*!< MQTT Topic URL */
char *_get_topic; /*!< /get topic string */
char *_create_url; /*!< create URL string */
char *_feed_url; /*!< feed URL string */
Adafruit_MQTT_Subscribe *_sub; /*!< MQTT subscription for _topic. */
Adafruit_MQTT_Publish *_pub; /*!< MQTT publish for _topic. */
Adafruit_MQTT_Publish *_get_pub; /*!< MQTT publish to _get_topic. */
AdafruitIO *_io; /*!< An instance of AdafruitIO. */
AdafruitIO_Data *_data; /*!< An instance of AdafruitIO_Data. */
};
#endif // ADAFRUITIO_FEED_H

View File

@@ -0,0 +1,546 @@
/*!
* @file AdafruitIO_Group.cpp
*
*
* Adafruit invests time and resources providing this open source code.
* Please support Adafruit and open source hardware by purchasing
* products from Adafruit!
*
* Copyright (c) 2015-2016 Adafruit Industries
* Authors: Tony DiCola, Todd Treece
* Licensed under the MIT license.
*
* All text above must be included in any redistribution.
*
*/
#include "AdafruitIO_Group.h"
#include "AdafruitIO.h"
/**************************************************************************/
/*!
@brief Creates a new instance of an Adafruit IO Group.
@param *io
Reference to AdafruitIO.
@param *n
Valid group name.
*/
/**************************************************************************/
AdafruitIO_Group::AdafruitIO_Group(AdafruitIO *io, const char *n)
: AdafruitIO_MQTT() {
_io = io;
name = n;
owner = _io->_username;
_init();
}
/**************************************************************************/
/*!
@brief Adafruit IO Group destructor.
*/
/**************************************************************************/
AdafruitIO_Group::~AdafruitIO_Group() {
if (_sub)
delete _sub;
if (_pub)
delete _pub;
if (_get_pub)
delete _get_pub;
if (data)
delete data;
if (_topic)
free(_topic);
if (_get_topic)
free(_get_topic);
if (_group_url)
free(_group_url);
if (_create_url)
free(_create_url);
}
/**************************************************************************/
/*!
@brief Sets value of Adafruit IO Group.
@param feed
Adafruit IO feed name.
@param value
Adafruit IO feed value.
*/
/**************************************************************************/
void AdafruitIO_Group::set(const char *feed, char *value) {
AdafruitIO_Data *f = getFeed(feed);
f->setValue(value);
}
/**************************************************************************/
/*!
@brief Sets value of Adafruit IO Group.
@param feed
Adafruit IO feed name.
@param value
Adafruit IO feed value.
*/
/**************************************************************************/
void AdafruitIO_Group::set(const char *feed, bool value) {
AdafruitIO_Data *f = getFeed(feed);
f->setValue(value);
}
/**************************************************************************/
/*!
@brief Sets value of Adafruit IO Group.
@param feed
Adafruit IO feed name.
@param value
Adafruit IO feed value.
*/
/**************************************************************************/
void AdafruitIO_Group::set(const char *feed, String value) {
AdafruitIO_Data *f = getFeed(feed);
f->setValue(value);
}
/**************************************************************************/
/*!
@brief Sets value of Adafruit IO Group.
@param feed
Adafruit IO feed name.
@param value
Adafruit IO feed value.
*/
/**************************************************************************/
void AdafruitIO_Group::set(const char *feed, int value) {
AdafruitIO_Data *f = getFeed(feed);
f->setValue(value);
}
/**************************************************************************/
/*!
@brief Sets value of Adafruit IO Group.
@param feed
Adafruit IO feed name.
@param value
Adafruit IO feed value.
*/
/**************************************************************************/
void AdafruitIO_Group::set(const char *feed, unsigned int value) {
AdafruitIO_Data *f = getFeed(feed);
f->setValue(value);
}
/**************************************************************************/
/*!
@brief Sets value of Adafruit IO Group.
@param feed
Adafruit IO feed name.
@param value
Adafruit IO feed value.
*/
/**************************************************************************/
void AdafruitIO_Group::set(const char *feed, long value) {
AdafruitIO_Data *f = getFeed(feed);
f->setValue(value);
}
/**************************************************************************/
/*!
@brief Sets value of Adafruit IO Group.
@param feed
Adafruit IO feed name.
@param value
Adafruit IO feed value.
*/
/**************************************************************************/
void AdafruitIO_Group::set(const char *feed, unsigned long value) {
AdafruitIO_Data *f = getFeed(feed);
f->setValue(value);
}
/**************************************************************************/
/*!
@brief Sets value of Adafruit IO Group.
@param feed
Adafruit IO feed name.
@param value
Adafruit IO feed value.
*/
/**************************************************************************/
void AdafruitIO_Group::set(const char *feed, float value) {
AdafruitIO_Data *f = getFeed(feed);
f->setValue(value);
}
/**************************************************************************/
/*!
@brief Sets value of Adafruit IO Group.
@param feed
Adafruit IO feed name.
@param value
Adafruit IO feed value.
*/
/**************************************************************************/
void AdafruitIO_Group::set(const char *feed, double value) {
AdafruitIO_Data *f = getFeed(feed);
f->setValue(value);
}
/**************************************************************************/
/*!
@brief Updates value of Adafruit IO Group.
@return True if successfully published to group, False if data is
NULL or if unable to successfully publish data to group.
*/
/**************************************************************************/
bool AdafruitIO_Group::save() {
if (data == NULL)
return false;
char csv[150];
AdafruitIO_Data *cur_data = data;
strcpy(csv, "");
while (cur_data != NULL) {
strcat(csv, cur_data->feedName());
strcat(csv, ",");
strcat(csv, cur_data->toChar());
strcat(csv, "\n");
cur_data = cur_data->next_data;
}
return _pub->publish(csv);
}
/**************************************************************************/
/*!
@brief Publishes null value ("\0") to Adafruit IO Group
https://io.adafruit.com/api/docs/mqtt.html#retained-values
@return True if successfully published to group, False otherwise.
*/
/**************************************************************************/
bool AdafruitIO_Group::get() { return _get_pub->publish("\0"); }
/**************************************************************************/
/*!
@brief Obtains data from feed within group.
@param feed
Existing Adafruit IO Feed.
@return cur_data Data from feed within group
data Adafruit IO Feed does not exist in group. Data is
the value of a generated feed, feed, within group.
NULL If unable to return data.
*/
/**************************************************************************/
AdafruitIO_Data *AdafruitIO_Group::getFeed(const char *feed) {
if (data == NULL) {
data = new AdafruitIO_Data(feed);
return data;
}
AdafruitIO_Data *cur_data = data;
while (cur_data != NULL) {
if (strcmp(cur_data->feedName(), feed) == 0) {
return cur_data;
}
if (!cur_data->next_data) {
cur_data->next_data = new AdafruitIO_Data(feed);
return cur_data->next_data;
}
cur_data = cur_data->next_data;
}
return NULL;
}
/**************************************************************************/
/*!
@brief Sets up Adafruit IO callback to monitor incoming
new data in group.
@param cb
An function to be called if group receives new data.
*/
/**************************************************************************/
void AdafruitIO_Group::onMessage(AdafruitIODataCallbackType cb) {
if (_groupCallback == NULL) {
_groupCallback = new AdafruitIOGroupCallback(cb);
return;
}
AdafruitIOGroupCallback *cur_cb = _groupCallback;
while (cur_cb != NULL) {
if (!cur_cb->next_cb) {
cur_cb->next_cb = new AdafruitIOGroupCallback(cb);
return;
}
cur_cb = cur_cb->next_cb;
}
}
/**************************************************************************/
/*!
@brief Sets up Adafruit IO callback to monitor incoming
new data in group's feed, feed.
@param feed
An Adafruit IO Feed within Group.
@param cb
An function to be called if group receives new data.
*/
/**************************************************************************/
void AdafruitIO_Group::onMessage(const char *feed,
AdafruitIODataCallbackType cb) {
if (_groupCallback == NULL) {
_groupCallback = new AdafruitIOGroupCallback(feed, cb);
return;
}
AdafruitIOGroupCallback *cur_cb = _groupCallback;
while (cur_cb != NULL) {
if (strcmp(cur_cb->feed, feed) == 0) {
return;
}
if (!cur_cb->next_cb) {
cur_cb->next_cb = new AdafruitIOGroupCallback(feed, cb);
return;
}
cur_cb = cur_cb->next_cb;
}
}
/**************************************************************************/
/*!
@brief Adafruit IO Group subscription function callback.
@param d
Name of feed within group.
*/
/**************************************************************************/
void AdafruitIO_Group::call(AdafruitIO_Data *d) {
// uint8_t i;
if (_groupCallback == NULL) {
return;
}
AdafruitIOGroupCallback *cur_cb = _groupCallback;
while (cur_cb) {
if (cur_cb->feed == NULL || strcmp(cur_cb->feed, d->feedName()) == 0) {
cur_cb->dataCallback(d);
}
cur_cb = cur_cb->next_cb;
}
}
/**************************************************************************/
/*!
@brief Checks for new value within Adafruit IO group.
@param val
Value to send to Adafruit IO group.
@param len
Length of Adafruit IO value.
*/
/**************************************************************************/
void AdafruitIO_Group::subCallback(char *val, uint16_t len) {
char *line;
char *name;
char *value;
if (_groupCallback == NULL)
return;
while ((line = strtok_r(val, "\n", &val)) != NULL) {
name = strtok_r(line, ",", &line);
// couldn't grab name from line, move on
if (!name)
continue;
// don't handle location for now
if (strcmp(name, "location") == 0)
continue;
value = strtok_r(line, ",", &line);
// no value? move on
if (!value)
continue;
AdafruitIO_Data *feed = getFeed(name);
// we couldn't get the data, move on
if (!feed)
continue;
feed->setValue(value);
call(feed);
}
}
/**************************************************************************/
/*!
@brief Sets up locational metadata.
@param lat
Desired latitude.
@param lon
Desired longitude.
@param ele
Desired elevation.
*/
/**************************************************************************/
void AdafruitIO_Group::setLocation(double lat, double lon, double ele) {
// uint8_t i;
if (data == NULL) {
return;
}
AdafruitIO_Data *cur_data = data;
while (cur_data) {
cur_data->setLocation(lat, lon, ele);
cur_data = cur_data->next_data;
}
}
/**************************************************************************/
/*!
@brief Checks if Adafruit IO Group exists.
https://io.adafruit.com/api/docs/#get-group
@return True if successful, otherwise False.
*/
/**************************************************************************/
bool AdafruitIO_Group::exists() {
_io->_http->beginRequest();
_io->_http->get(_group_url);
_io->_http->sendHeader("X-AIO-Key", _io->_key);
_io->_http->endRequest();
int status = _io->_http->responseStatusCode();
_io->_http->responseBody(); // needs to be read even if not used
return status == 200;
}
/**************************************************************************/
/*!
@brief Creates new Adafruit IO Group.
https://io.adafruit.com/api/docs/#create-group
@return True if successful, otherwise False.
*/
/**************************************************************************/
bool AdafruitIO_Group::create() {
String body = "name=";
body += name;
_io->_http->beginRequest();
_io->_http->post(_create_url);
_io->_http->sendHeader("Content-Type", "application/x-www-form-urlencoded");
_io->_http->sendHeader("Content-Length", body.length());
_io->_http->sendHeader("X-AIO-Key", _io->_key);
// the following call to endRequest
// should be replaced by beginBody once the
// Arduino HTTP Client Library is updated
// _io->_http->beginBody();
_io->_http->endRequest();
_io->_http->print(body);
_io->_http->endRequest();
int status = _io->_http->responseStatusCode();
_io->_http->responseBody(); // needs to be read even if not used
return status == 201;
}
/**************************************************************************/
/*!
@brief Initialize MQTT topics and REST URLs for Adafruit IO groups.
*/
/**************************************************************************/
void AdafruitIO_Group::_init() {
// dynamically allocate memory for mqtt topic and REST URLs
_topic = (char *)malloc(
sizeof(char) * (strlen(owner) + strlen(name) +
8)); // 8 extra chars for /g/, /csv & null termination
_get_topic = (char *)malloc(
sizeof(char) *
(strlen(owner) + strlen(name) +
12)); // 12 extra chars for /f/, /csv/get & null termination
_group_url =
(char *)malloc(sizeof(char) * (strlen(owner) + strlen(name) +
16)); // 16 extra for api path & null term
_create_url = (char *)malloc(
sizeof(char) * (strlen(owner) + 15)); // 15 extra for api path & null term
data = 0;
if (_topic && _create_url && _group_url) {
// build topic string
strcpy(_topic, owner);
strcat(_topic, "/g/");
strcat(_topic, name);
strcat(_topic, "/csv");
// build feed url string
strcpy(_group_url, "/api/v2/");
strcat(_group_url, owner);
strcat(_group_url, "/groups/");
strcat(_group_url, name);
// build create url string
strcpy(_create_url, "/api/v2/");
strcat(_create_url, owner);
strcat(_create_url, "/groups");
// build /get topic string
strcpy(_get_topic, owner);
strcat(_get_topic, "/g/");
strcat(_get_topic, name);
strcat(_get_topic, "/csv/get");
// setup subscription
_sub = new Adafruit_MQTT_Subscribe(_io->_mqtt, _topic);
_pub = new Adafruit_MQTT_Publish(_io->_mqtt, _topic);
_get_pub = new Adafruit_MQTT_Publish(_io->_mqtt, _get_topic);
_io->_mqtt->subscribe(_sub);
_sub->setCallback(this, &AdafruitIO_MQTT::subCallback);
} else {
// malloc failed
_topic = 0;
_get_topic = 0;
_create_url = 0;
_group_url = 0;
_sub = 0;
_pub = 0;
_get_pub = 0;
}
}

View File

@@ -0,0 +1,85 @@
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Copyright (c) 2015-2016 Adafruit Industries
// Author: Todd Treece
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.
//
#ifndef ADAFRUITIO_GROUP_H
#define ADAFRUITIO_GROUP_H
#include "AdafruitIO_Data.h"
#include "AdafruitIO_Definitions.h"
#include "AdafruitIO_MQTT.h"
#include "Adafruit_MQTT.h"
#include "Arduino.h"
// forward declaration
class AdafruitIO;
/**************************************************************************/
/*!
@brief Class for interacting with Adafruit IO Grouped Feeds
https://io.adafruit.com/api/docs/mqtt.html#group-topics
*/
/**************************************************************************/
class AdafruitIO_Group : public AdafruitIO_MQTT {
public:
AdafruitIO_Group(AdafruitIO *io, const char *name);
~AdafruitIO_Group();
void set(const char *feed, char *value);
void set(const char *feed, bool value);
void set(const char *feed, String value);
void set(const char *feed, int value);
void set(const char *feed, unsigned int value);
void set(const char *feed, long value);
void set(const char *feed, unsigned long value);
void set(const char *feed, float value);
void set(const char *feed, double value);
bool save();
bool get();
void setLocation(double lat = 0, double lon = 0, double ele = 0);
bool exists();
bool create();
void onMessage(AdafruitIODataCallbackType cb);
void onMessage(const char *feed, AdafruitIODataCallbackType cb);
void subCallback(char *val, uint16_t len);
void call(AdafruitIO_Data *d);
const char *name; /*!< Adafruit IO group name. */
const char *owner; /*!< Adafruit IO username of group owner. */
AdafruitIO_Data *data; /*!< Adafruit IO data record. */
AdafruitIO_Data *getFeed(const char *feed);
private:
void _init();
char *_topic; /*!< MQTT topic URL.. */
char *_get_topic; /*!< /get topic string. */
char *_create_url; /*!< Create URL string. */
char *_group_url; /*!< Group URL string. */
Adafruit_MQTT_Subscribe *_sub; /*!< MQTT subscription for _topic. */
Adafruit_MQTT_Publish *_pub; /*!< MQTT publish for _topic. */
Adafruit_MQTT_Publish *_get_pub; /*!< MQTT publish to _get_topic. */
AdafruitIO *_io; /*!< An instance of AdafruitIO. */
AdafruitIOGroupCallback *_groupCallback =
NULL; /*!< An instance of AdafruitIOGroupCallback */
double _lat, _lon, _ele; /*!< latitude, longitude, elevation metadata. */
};
#endif // ADAFRUITIO_GROUP_H

View File

@@ -0,0 +1,42 @@
/*!
* @file AdafruitIO_MQTT.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_MQTT_H
#define ADAFRUITIO_MQTT_H
#include "Arduino.h"
/**************************************************************************/
/*!
@brief Class that contains MQTT subscription callbacks.
*/
/**************************************************************************/
class AdafruitIO_MQTT {
public:
AdafruitIO_MQTT() {}
/**************************************************************************/
/*!
@brief Creates an instance of a MQTT subscription callback.
@param val
Value from the MQTT subscription callback.
@param len
Length of returned value.
@return True
*/
/**************************************************************************/
virtual void subCallback(char *val, uint16_t len) = 0;
};
#endif // ADAFRUITIO_MQTT_H

View File

@@ -0,0 +1,131 @@
/*!
* @file AdafruitIO_Time.cpp
*
*
* Adafruit invests time and resources providing this open source code.
* Please support Adafruit and open source hardware by purchasing
* products from Adafruit!
*
* Copyright (c) 2015-2016 Adafruit Industries
* Authors: Tony DiCola, Todd Treece
* Licensed under the MIT license.
*
* All text above must be included in any redistribution.
*
*/
#include "AdafruitIO_Time.h"
#include "AdafruitIO.h"
/**************************************************************************/
/*!
@brief Sets up a Adafruit IO Time Service helper.
@param io
Reference to AdafruitIO.
@param f
Adafruit IO time format, either AIO_TIME_SECONDS,
AIO_TIME_MILLIS, or AIO_TIME_ISO.
*/
/**************************************************************************/
AdafruitIO_Time::AdafruitIO_Time(AdafruitIO *io, aio_time_format_t f)
: AdafruitIO_MQTT() {
_io = io;
_sub = 0;
_dataCallback = 0;
format = f;
_init();
}
/**************************************************************************/
/*!
@brief Deconstructor for Adafruit IO time service.
*/
/**************************************************************************/
AdafruitIO_Time::~AdafruitIO_Time() {
if (_sub)
delete _sub;
if (data)
delete data;
if (_topic)
free(_topic);
}
/**************************************************************************/
/*!
@brief Sets up a MQTT message callback.
@param cb
MQTT callback type.
*/
/**************************************************************************/
void AdafruitIO_Time::onMessage(AdafruitIOTimeCallbackType cb) {
_dataCallback = cb;
}
/**************************************************************************/
/*!
@brief Sets up a MQTT subscription callback. Calls data callback
with data.
@param val
Data from MQTT topic.
@param len
Length of MQTT topic data.
*/
/**************************************************************************/
void AdafruitIO_Time::subCallback(char *val, uint16_t len) {
data = val;
// call callback with data
if (_dataCallback)
_dataCallback(data, len);
}
/**************************************************************************/
/*!
@brief Initializes AdafruitIO Time MQTT topic and REST URLs.
*/
/**************************************************************************/
void AdafruitIO_Time::_init() {
// dynamically allocate memory for mqtt topic and REST URLs
const char *formatString;
switch (format) {
case AIO_TIME_SECONDS:
formatString = "seconds";
break;
case AIO_TIME_MILLIS:
formatString = "millis";
break;
case AIO_TIME_ISO:
formatString = "ISO-8601";
break;
default:
formatString = "seconds";
break;
}
_topic = (char *)malloc(
sizeof(char) * (strlen(formatString) +
6)); // 6 extra chars for "time/" and null termination
if (_topic) {
// build topic string
strcpy(_topic, "time/");
strcat(_topic, formatString);
// setup subscription
_sub = new Adafruit_MQTT_Subscribe(_io->_mqtt, _topic);
_io->_mqtt->subscribe(_sub);
_sub->setCallback(this, &AdafruitIO_MQTT::subCallback);
} else {
// malloc failed
_topic = 0;
_sub = 0;
data = 0;
}
}

View File

@@ -0,0 +1,55 @@
/*!
* @file AdafruitIO_Time.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_TIME_H
#define ADAFRUITIO_TIME_H
#include "AdafruitIO_Definitions.h"
#include "AdafruitIO_MQTT.h"
#include "Adafruit_MQTT.h"
#include "Arduino.h"
// forward declaration
class AdafruitIO;
typedef void (*AdafruitIOTimeCallbackType)(
char *value,
uint16_t len); /*!< an instance of Adafruit IO's time callback. */
/**************************************************************************/
/*!
@brief Class that contains functions for interacting with
the Adafruit IO Time Service.
*/
/**************************************************************************/
class AdafruitIO_Time : public AdafruitIO_MQTT {
public:
AdafruitIO_Time(AdafruitIO *io, aio_time_format_t f);
~AdafruitIO_Time();
void onMessage(AdafruitIOTimeCallbackType cb);
void subCallback(char *val, uint16_t len);
char *data; /*!< Data sent by Adafruit IO's time service. */
aio_time_format_t format; /*!< Adafruit IO time format,
TIME_SECONDS/TIME_MILLIS/TIME_ISO. */
private:
AdafruitIOTimeCallbackType _dataCallback;
void _init();
char *_topic;
Adafruit_MQTT_Subscribe *_sub;
AdafruitIO *_io;
};
#endif // ADAFRUITIO_FEED_H

View File

@@ -0,0 +1,60 @@
/*!
* @file AdafruitIO_WiFi.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_WIFI_H
#define ADAFRUITIO_WIFI_H
#if defined(ARDUINO_SAMD_MKR1000)
#include "wifi/AdafruitIO_MKR1000.h"
typedef AdafruitIO_MKR1000 AdafruitIO_WiFi;
#elif defined(ARDUINO_SAMD_MKR1010)
#include "wifi/AdafruitIO_MKR1010.h"
typedef AdafruitIO_MKR1010 AdafruitIO_WiFi;
#elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || defined(ADAFRUIT_PYPORTAL) || \
defined(USE_AIRLIFT)
#include "wifi/AdafruitIO_AIRLIFT.h"
typedef AdafruitIO_AIRLIFT AdafruitIO_WiFi;
#elif defined(USE_WINC1500)
#include "wifi/AdafruitIO_WINC1500.h"
typedef AdafruitIO_WINC1500 AdafruitIO_WiFi;
#elif defined(ARDUINO_ARCH_ESP32)
#include "wifi/AdafruitIO_ESP32.h"
typedef AdafruitIO_ESP32 AdafruitIO_WiFi;
#elif defined(ESP8266)
#include "wifi/AdafruitIO_ESP8266.h"
typedef AdafruitIO_ESP8266 AdafruitIO_WiFi;
#elif defined(ARDUINO_STM32_FEATHER)
#include "wifi/AdafruitIO_WICED.h"
typedef AdafruitIO_WICED AdafruitIO_WiFi;
#else
#warning "Must define USE_AIRLIFT or USE_WINC1500 before including this file."
#endif
#endif // ADAFRUITIO_WIFI_H

View File

@@ -0,0 +1,129 @@
/*!
* @file AdafruitIO_Block.cpp
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#include "AdafruitIO_Block.h"
#include "AdafruitIO.h"
#include "AdafruitIO_Dashboard.h"
/**************************************************************************/
/*!
@brief Creates a new Block on an Adafruit IO Dashboard.
@param d
Adafruit IO Dashboard name.
@param f
Adafruit IO Feed to display on the block.
*/
/**************************************************************************/
AdafruitIO_Block::AdafruitIO_Block(AdafruitIO_Dashboard *d,
AdafruitIO_Feed *f) {
_dashboard = d;
_feed = f;
}
AdafruitIO_Block::~AdafruitIO_Block() {}
/**************************************************************************/
/*!
@brief Sets block properties.
@return String containing block's properties.
*/
/**************************************************************************/
String AdafruitIO_Block::properties() {
String props = "{}";
return props;
}
/**************************************************************************/
/*!
@brief Sets block dimensions, provided block size (width, height)
and block location on dashboard (row, column).
@return String containing block's dimensions.
*/
/**************************************************************************/
String AdafruitIO_Block::dimensions() {
String dim = "\",\"size_x\":\"";
dim += _width();
dim += "\",\"size_y\":\"";
dim += _height();
if (_row() > 0) {
dim += "\",\"row\":\"";
dim += _row();
}
if (_column() > 0) {
dim += "\",\"column\":\"";
dim += _column();
}
return dim;
}
/**************************************************************************/
/*!
@brief Returns type of Adafruit IO Block.
@return Block type
*/
/**************************************************************************/
const char *AdafruitIO_Block::type() { return _visual_type; }
/**************************************************************************/
/*!
@brief Creates a new block on an Adafruit IO dashboard.
@return True if successful, False otherwise.
*/
/**************************************************************************/
bool AdafruitIO_Block::save() {
HttpClient *http = _dashboard->io()->_http;
String url = "/api/v2/";
url += _dashboard->user();
url += "/dashboards/";
url += _dashboard->name;
url += "/blocks";
String block_feeds = "[{\"feed_id\":\"";
block_feeds += _feed->name;
block_feeds += "\"}]";
String body = "{\"visual_type\":\"";
body += type();
body += dimensions();
body += "\",\"properties\":";
body += properties();
body += ",\"block_feeds\":";
body += block_feeds;
body += "}";
http->beginRequest();
http->post(url.c_str());
http->sendHeader("Content-Type", "application/json");
http->sendHeader("Content-Length", body.length());
http->sendHeader("X-AIO-Key", _dashboard->io()->_key);
// the following call to endRequest
// should be replaced by beginBody once the
// Arduino HTTP Client Library is updated
// http->beginBody();
http->endRequest();
http->print(body);
http->endRequest();
int status = http->responseStatusCode();
http->responseBody(); // needs to be read even if not used
return status == 200;
}

View File

@@ -0,0 +1,90 @@
/*!
* @file AdafruitIO_Block.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_BLOCK_H
#define ADAFRUITIO_BLOCK_H
#include "AdafruitIO_Definitions.h"
#include "Arduino.h"
class AdafruitIO_Dashboard;
class AdafruitIO_Feed;
/**************************************************************************/
/*!
@brief Class for interacting with and creating Adafruit IO Dashboard
blocks.
*/
/**************************************************************************/
class AdafruitIO_Block {
public:
AdafruitIO_Block(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
~AdafruitIO_Block();
int width = 2; /*!< Dashboard block width. */
int height = 2; /*!< Dashboard block height. */
int row = 0; /*!< Row location of block on dashboard. */
int column = 0; /*!< Column location of block on dashboard. */
virtual String properties();
String dimensions();
virtual const char *type();
bool save();
protected:
AdafruitIO_Dashboard
*_dashboard; /*!< Instance of an Adafruit IO Dashboard. */
AdafruitIO_Feed *_feed; /*!< Instance of an Adafruit IO Feed. */
const char *_visual_type; /*!< Block type. */
/******************************************/
/*!
@brief Returns width of block.
@return Block width.
*/
/******************************************/
virtual int _width() { return width; }
/******************************************/
/*!
@brief Returns height of block.
@return Block height.
*/
/******************************************/
virtual int _height() { return height; }
/******************************************/
/*!
@brief Returns block's row location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard row.
*/
/******************************************/
virtual int _row() { return row; }
/******************************************/
/*!
@brief Returns block's column location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard column
*/
/******************************************/
virtual int _column() { return column; }
};
#endif // ADAFRUITIO_BLOCK_H

View File

@@ -0,0 +1,58 @@
/*!
* @file ChartBlock.cpp
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#include "ChartBlock.h"
/**************************************************************************/
/*!
@brief Creates a new Chart Block on an Adafruit IO Dashboard.
@param d
Adafruit IO Dashboard name.
@param f
Adafruit IO Feed to display on the chart.
*/
/**************************************************************************/
ChartBlock::ChartBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
: AdafruitIO_Block(d, f) {
historyHours = 0;
xAxisLabel = "X";
yAxisLabel = "Y";
yAxisMin = 0;
yAxisMax = 100;
}
ChartBlock::~ChartBlock() {}
/**************************************************************************/
/*!
@brief Sets chart block properties.
@return String containing properties of the chart block.
*/
/**************************************************************************/
String ChartBlock::properties() {
String props = "{\"historyHours\":\"";
props += historyHours;
props += "\",\"xAxisLabel\":\"";
props += xAxisLabel;
props += "\",\"yAxisLabel\":\"";
props += yAxisLabel;
props += "\",\"yAxisMin\":\"";
props += yAxisMin;
props += "\",\"yAxisMax\":\"";
props += yAxisMax;
props += "\"}";
return props;
}

View File

@@ -0,0 +1,89 @@
/*!
* @file ChartBlock.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_CHARTBLOCK_H
#define ADAFRUITIO_CHARTBLOCK_H
#include "AdafruitIO_Block.h"
/**************************************************************************/
/*!
@brief Class for interacting with the Adafruit IO Dashboard
Chart Block.
*/
/**************************************************************************/
class ChartBlock : public AdafruitIO_Block {
public:
ChartBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
~ChartBlock();
/******************************************/
/*!
@brief Returns block type
@return Block type.
*/
/******************************************/
const char *type() { return _visual_type; }
int historyHours; /*!< Amount of hours to store the chart's history for. */
const char *xAxisLabel; /*!< Chart's x-axis label. */
const char *yAxisLabel; /*!< Chart's y-axis label. */
int yAxisMin; /*!< Chart's y-axis minimum. */
int yAxisMax; /*!< Chart's y-axis maximum. */
int width = 6; /*!< Dashboard block width. */
int height = 4; /*!< Dashboard block height. */
String properties();
protected:
const char *_visual_type = "line_chart"; /*!< Block type. */
/******************************************/
/*!
@brief Returns width of block.
@return Block width.
*/
/******************************************/
int _width() { return width; }
/******************************************/
/*!
@brief Returns height of block.
@return Block height.
*/
/******************************************/
int _height() { return height; }
/******************************************/
/*!
@brief Returns block's row location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard row.
*/
/******************************************/
int _row() { return row; }
/******************************************/
/*!
@brief Returns block's column location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard column
*/
/******************************************/
int _column() { return column; }
};
#endif // ADAFRUITIO_CHARTBLOCK_H

View File

@@ -0,0 +1,91 @@
/*!
* @file ColorBlock.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_COLORBLOCK_H
#define ADAFRUITIO_COLORBLOCK_H
#include "AdafruitIO_Block.h"
/**************************************************************************/
/*!
@brief Class for interacting with the Adafruit IO Dashboard
Color Block.
*/
/**************************************************************************/
class ColorBlock : public AdafruitIO_Block {
public:
/**************************************************************************/
/*!
@brief Creates a new color block on an Adafruit IO Dashboard.
@param d
Adafruit IO Dashboard name.
@param f
Adafruit IO Feed to display on the block.
*/
/**************************************************************************/
ColorBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
: AdafruitIO_Block(d, f) {}
~ColorBlock() {}
int width = 4; /*!< Dashboard block width. */
int height = 4; /*!< Dashboard block height. */
/******************************************/
/*!
@brief Returns block type
@return Block type.
*/
/******************************************/
const char *type() { return _visual_type; }
protected:
const char *_visual_type = "color_picker"; /*!< Block type. */
/******************************************/
/*!
@brief Returns width of block.
@return Block width.
*/
/******************************************/
int _width() { return width; }
/******************************************/
/*!
@brief Returns height of block.
@return Block height.
*/
/******************************************/
int _height() { return height; }
/******************************************/
/*!
@brief Returns block's row location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard row.
*/
/******************************************/
int _row() { return row; }
/******************************************/
/*!
@brief Returns block's column location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard column
*/
/******************************************/
int _column() { return column; }
};
#endif // ADAFRUITIO_COLORBLOCK_H

View File

@@ -0,0 +1,62 @@
/*!
* @file GaugeBlock.cpp
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#include "GaugeBlock.h"
/**************************************************************************/
/*!
@brief Creates a new Gauge Block on an Adafruit IO Dashboard.
@param d
Adafruit IO Dashboard name.
@param f
Adafruit IO Feed to display on the Gauge.
*/
/**************************************************************************/
GaugeBlock::GaugeBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
: AdafruitIO_Block(d, f) {
min = 0;
max = 100;
ringWidth = "thin";
label = "Value";
}
GaugeBlock::~GaugeBlock() {}
/**************************************************************************/
/*!
@brief Sets Gauge block properties.
@return String containing properties of the Gauge block.
*/
/**************************************************************************/
String GaugeBlock::properties() {
int w = 0;
if (strcmp(ringWidth, "thin")) {
w = 25;
} else {
w = 50;
}
String props = "{\"minValue\":\"";
props += min;
props += "\",\"maxValue\":\"";
props += max;
props += "\",\"ringWidth\":\"";
props += w;
props += "\",\"label\":\"";
props += label;
props += "\"}";
return props;
}

View File

@@ -0,0 +1,89 @@
/*!
* @file GaugeBlock.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_GAUGEBLOCK_H
#define ADAFRUITIO_GAUGEBLOCK_H
#include "AdafruitIO_Block.h"
/**************************************************************************/
/*!
@brief Class for interacting with the Adafruit IO Dashboard
Gauge Block.
*/
/**************************************************************************/
class GaugeBlock : public AdafruitIO_Block {
public:
GaugeBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
~GaugeBlock();
int min; /*!< Min. value displayed on gauge. */
int max; /*!< Max. value displayed on gauge. */
const char *ringWidth; /*!< Width of gauge's ring. */
const char *label; /*!< Gauge text label. */
int width = 4; /*!< Dashboard block width. */
int height = 4; /*!< Dashboard block height. */
String properties();
/******************************************/
/*!
@brief Returns block type
@return Block type.
*/
/******************************************/
const char *type() { return _visual_type; }
protected:
const char *_visual_type = "gauge"; /*!< Block type. */
/******************************************/
/*!
@brief Returns width of block.
@return Block width.
*/
/******************************************/
int _width() { return width; }
/******************************************/
/*!
@brief Returns height of block.
@return Block height.
*/
/******************************************/
int _height() { return height; }
/******************************************/
/*!
@brief Returns block's row location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard row.
*/
/******************************************/
int _row() { return row; }
/******************************************/
/*!
@brief Returns block's column location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard column
*/
/******************************************/
int _column() { return column; }
};
#endif // ADAFRUITIO_GAUGEBLOCK_H

View File

@@ -0,0 +1,91 @@
/*!
* @file ImageBlock.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_IMAGEBLOCK_H
#define ADAFRUITIO_IMAGEBLOCK_H
#include "AdafruitIO_Block.h"
/**************************************************************************/
/*!
@brief Class for interacting with the Adafruit IO Dashboard
Image Block.
*/
/**************************************************************************/
class ImageBlock : public AdafruitIO_Block {
public:
/**************************************************************************/
/*!
@brief Creates a new Image Block on an Adafruit IO Dashboard.
@param d
Adafruit IO Dashboard name.
@param f
Adafruit IO Feed to display on the image block.
*/
/**************************************************************************/
ImageBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
: AdafruitIO_Block(d, f) {}
~ImageBlock() {}
int height = 6; /*!< Dashboard block height. */
int width = 4; /*!< Dashboard block width. */
/******************************************/
/*!
@brief Returns block type
@return Block type.
*/
/******************************************/
const char *type() { return _visual_type; }
protected:
const char *_visual_type = "image"; /*!< Block type. */
/******************************************/
/*!
@brief Returns width of block.
@return Block width.
*/
/******************************************/
int _width() { return width; }
/******************************************/
/*!
@brief Returns height of block.
@return Block height.
*/
/******************************************/
int _height() { return height; }
/******************************************/
/*!
@brief Returns block's row location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard row.
*/
/******************************************/
int _row() { return row; }
/******************************************/
/*!
@brief Returns block's column location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard column
*/
/******************************************/
int _column() { return column; }
};
#endif // ADAFRUITIO_IMAGEBLOCK_H

View File

@@ -0,0 +1,54 @@
/*!
* @file MapBlock.cpp
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#include "MapBlock.h"
/**************************************************************************/
/*!
@brief Creates a new map Block on an Adafruit IO Dashboard.
@param d
Adafruit IO Dashboard name.
@param f
Adafruit IO Feed to display on the map.
*/
/**************************************************************************/
MapBlock::MapBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
: AdafruitIO_Block(d, f) {
historyHours = 0;
tile = "contrast";
}
MapBlock::~MapBlock() {}
/**************************************************************************/
/*!
@brief Sets map block properties.
@return String containing properties of the map block.
*/
/**************************************************************************/
String MapBlock::properties() {
if ((strcmp(tile, "contrast") != 0) && (strcmp(tile, "street") != 0) &&
(strcmp(tile, "sat") != 0)) {
tile = "contrast";
}
props = "{\"historyHours\":\"";
props += historyHours;
props += "\",\"tile\":\"";
props += tile;
props += "\"}";
return props;
}

View File

@@ -0,0 +1,87 @@
/*!
* @file MapBlock.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_MAPBLOCK_H
#define ADAFRUITIO_MAPBLOCK_H
#include "AdafruitIO_Block.h"
/**************************************************************************/
/*!
@brief Class for interacting with the Adafruit IO Dashboard
Map Block.
*/
/**************************************************************************/
class MapBlock : public AdafruitIO_Block {
public:
MapBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
~MapBlock();
String props; /*!< Map block properties. */
int historyHours; /*!< Time displayed by map block in hours. */
const char *tile; /*!< Map block title. */
int width = 4; /*!< Dashboard block width. */
int height = 4; /*!< Dashboard block height. */
String properties();
/******************************************/
/*!
@brief Returns block type
@return Block type.
*/
/******************************************/
const char *type() { return _visual_type; }
protected:
const char *_visual_type = "map"; /*!< Block type. */
/******************************************/
/*!
@brief Returns width of block.
@return Block width.
*/
/******************************************/
int _width() { return width; }
/******************************************/
/*!
@brief Returns height of block.
@return Block height.
*/
/******************************************/
int _height() { return height; }
/******************************************/
/*!
@brief Returns block's row location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard row.
*/
/******************************************/
int _row() { return row; }
/******************************************/
/*!
@brief Returns block's column location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard column
*/
/******************************************/
int _column() { return column; }
};
#endif // ADAFRUITIO_MAPBLOCK_H

View File

@@ -0,0 +1,51 @@
/*!
* @file MomentaryBlock.cpp
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#include "MomentaryBlock.h"
/**************************************************************************/
/*!
@brief Creates a new Momentary Block on an Adafruit IO Dashboard.
@param d
Adafruit IO Dashboard name.
@param f
Adafruit IO Feed to display on the momentary.
*/
/**************************************************************************/
MomentaryBlock::MomentaryBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
: AdafruitIO_Block(d, f) {
text = "RESET";
value = "1";
release = "0";
}
MomentaryBlock::~MomentaryBlock() {}
/**************************************************************************/
/*!
@brief Sets momentary block properties.
@return String containing properties of the momentary block.
*/
/**************************************************************************/
String MomentaryBlock::properties() {
String props = "{\"text\":\"";
props += text;
props += "\",\"value\":\"";
props += value;
props += "\",\"release\":\"";
props += release;
props += "\"}";
return props;
}

View File

@@ -0,0 +1,87 @@
/*!
* @file MomentaryBlock.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_MOMENTARYBLOCK_H
#define ADAFRUITIO_MOMENTARYBLOCK_H
#include "AdafruitIO_Block.h"
/**************************************************************************/
/*!
@brief Class for interacting with the Adafruit IO Dashboard
Momentary Block.
*/
/**************************************************************************/
class MomentaryBlock : public AdafruitIO_Block {
public:
MomentaryBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
~MomentaryBlock();
const char *text; /*!< Text displayed by block. */
const char *value; /*!< Value displayed by block. */
const char *release; /*!< Release value text. */
int width = 2; /*!< Dashboard block width. */
int height = 2; /*!< Dashboard block height. */
String properties();
/******************************************/
/*!
@brief Returns block type
@return Block type.
*/
/******************************************/
const char *type() { return _visual_type; }
protected:
const char *_visual_type = "momentary_button"; /*!< Block type. */
/******************************************/
/*!
@brief Returns width of block.
@return Block width.
*/
/******************************************/
int _width() { return width; }
/******************************************/
/*!
@brief Returns height of block.
@return Block height.
*/
/******************************************/
int _height() { return height; }
/******************************************/
/*!
@brief Returns block's row location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard row.
*/
/******************************************/
int _row() { return row; }
/******************************************/
/*!
@brief Returns block's column location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard column
*/
/******************************************/
int _column() { return column; }
};
#endif // ADAFRUITIO_MOMENTARYBLOCK_H

View File

@@ -0,0 +1,54 @@
/*!
* @file SliderBlock.cpp
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#include "SliderBlock.h"
/**************************************************************************/
/*!
@brief Creates a new Slider Block on an Adafruit IO Dashboard.
@param d
Adafruit IO Dashboard name.
@param f
Adafruit IO Feed to display on the slider.
*/
/**************************************************************************/
SliderBlock::SliderBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
: AdafruitIO_Block(d, f) {
min = 0;
max = 100;
step = 10;
label = "Value";
}
SliderBlock::~SliderBlock() {}
/**************************************************************************/
/*!
@brief Sets slider block properties.
@return String containing properties of the slider block.
*/
/**************************************************************************/
String SliderBlock::properties() {
String props = "{\"min\":\"";
props += min;
props += "\",\"max\":\"";
props += max;
props += "\",\"step\":\"";
props += step;
props += "\",\"label\":\"";
props += label;
props += "\"}";
return props;
}

View File

@@ -0,0 +1,88 @@
/*!
* @file SliderBlock.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_SLIDERBLOCK_H
#define ADAFRUITIO_SLIDERBLOCK_H
#include "AdafruitIO_Block.h"
/**************************************************************************/
/*!
@brief Class for interacting with the Adafruit IO Dashboard
Slider Block.
*/
/**************************************************************************/
class SliderBlock : public AdafruitIO_Block {
public:
SliderBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
~SliderBlock();
int min; /*!< Minimum slider data value. */
int max; /*!< Maximum slider data value. */
int step; /*!< Slider data step value. */
const char *label; /*!< Slider title. */
int width = 4; /*!< Dashboard block width. */
int height = 2; /*!< Dashboard block height. */
String properties();
/******************************************/
/*!
@brief Returns block type
@return Block type.
*/
/******************************************/
const char *type() { return _visual_type; }
protected:
const char *_visual_type = "slider"; /*!< Block type. */
/******************************************/
/*!
@brief Returns width of block.
@return Block width.
*/
/******************************************/
int _width() { return width; }
/******************************************/
/*!
@brief Returns height of block.
@return Block height.
*/
/******************************************/
int _height() { return height; }
/******************************************/
/*!
@brief Returns block's row location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard row.
*/
/******************************************/
int _row() { return row; }
/******************************************/
/*!
@brief Returns block's column location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard column
*/
/******************************************/
int _column() { return column; }
};
#endif // ADAFRUITIO_SLIDERBLOCK_H

View File

@@ -0,0 +1,68 @@
/*!
* @file StreamBlock.cpp
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#include "StreamBlock.h"
/**************************************************************************/
/*!
@brief Creates a new Stream Block on an Adafruit IO Dashboard.
@param d
Adafruit IO Dashboard name.
@param f
Adafruit IO Feed to display on the stream block.
*/
/**************************************************************************/
StreamBlock::StreamBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
: AdafruitIO_Block(d, f) {
fontSize = "small";
fontColor = "green";
showErrors = true;
showTimestamp = true;
showName = true;
}
StreamBlock::~StreamBlock() {}
/**************************************************************************/
/*!
@brief Sets stream block properties.
@return String containing properties of the stream block.
*/
/**************************************************************************/
String StreamBlock::properties() {
int s = 0;
if (strcmp(fontSize, "small") == 0) {
s = 12;
}
if (strcmp(fontSize, "medium") == 0) {
s = 18;
} else {
s = 24;
}
String props = "{\"fontSize\":\"";
props += s;
props += "\",\"fontColor\":\"";
props += (strcmp(fontColor, "white") == 0) ? "#ffffff" : "#63de00";
props += "\",\"errors\":\"";
props += showErrors ? "yes" : "no";
props += "\",\"showTimestamp\":\"";
props += showTimestamp ? "yes" : "no";
props += "\",\"showName\":\"";
props += showName ? "yes" : "no";
props += "\"}";
return props;
}

View File

@@ -0,0 +1,89 @@
/*!
* @file StreamBlock.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_STREAMBLOCK_H
#define ADAFRUITIO_STREAMBLOCK_H
#include "AdafruitIO_Block.h"
/**************************************************************************/
/*!
@brief Class for interacting with the Adafruit IO Dashboard
Stream Block.
*/
/**************************************************************************/
class StreamBlock : public AdafruitIO_Block {
public:
StreamBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
~StreamBlock();
const char *fontSize; /*!< Block's text font size. */
const char *fontColor; /*!< Block's text font color. */
bool showErrors; /*!< Display Adafruit IO errors .*/
bool showTimestamp; /*!< Display timestamp metadata. */
bool showName; /*!< Display value name.. */
int width = 6; /*!< Dashboard block width. */
int height = 4; /*!< Dashboard block height. */
String properties();
/******************************************/
/*!
@brief Returns block type
@return Block type.
*/
/******************************************/
const char *type() { return _visual_type; }
protected:
const char *_visual_type = "stream"; /*!< Block type. */
/******************************************/
/*!
@brief Returns width of block.
@return Block width.
*/
/******************************************/
int _width() { return width; }
/******************************************/
/*!
@brief Returns height of block.
@return Block height.
*/
/******************************************/
int _height() { return height; }
/******************************************/
/*!
@brief Returns block's row location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard row.
*/
/******************************************/
int _row() { return row; }
/******************************************/
/*!
@brief Returns block's column location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard column
*/
/******************************************/
int _column() { return column; }
};
#endif // ADAFRUITIO_STREAMBLOCK_H

View File

@@ -0,0 +1,55 @@
/*!
* @file TextBlock.cpp
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#include "TextBlock.h"
/**************************************************************************/
/*!
@brief Creates a new Text Block on an Adafruit IO Dashboard.
@param d
Adafruit IO Dashboard name.
@param f
Adafruit IO Feed to display on the Text.
*/
/**************************************************************************/
TextBlock::TextBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
: AdafruitIO_Block(d, f) {
fontSize = "small";
}
TextBlock::~TextBlock() {}
/**************************************************************************/
/*!
@brief Sets Text block properties.
@return String containing properties of the Text block.
*/
/**************************************************************************/
String TextBlock::properties() {
int s = 0;
if ((strcmp(fontSize, "small") == 0)) {
s = 12;
} else if ((strcmp(fontSize, "medium") == 0)) {
s = 18;
} else {
s = 24;
}
String props = "{\"fontSize\":\"";
props += s;
props += "\"}";
return props;
}

View File

@@ -0,0 +1,85 @@
/*!
* @file TextBlock.h
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#ifndef ADAFRUITIO_TEXTBLOCK_H
#define ADAFRUITIO_TEXTBLOCK_H
#include "AdafruitIO_Block.h"
/**************************************************************************/
/*!
@brief Class for interacting with the Adafruit IO Dashboard
Slider Block.
*/
/**************************************************************************/
class TextBlock : public AdafruitIO_Block {
public:
TextBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
~TextBlock();
const char *fontSize; /*!< Dashboard block text font size. */
int width = 2; /*!< Dashboard block width. */
int height = 1; /*!< Dashboard block height. */
String properties();
/******************************************/
/*!
@brief Returns block type
@return Block type.
*/
/******************************************/
const char *type() { return _visual_type; }
protected:
const char *_visual_type = "text"; /*!< Block type. */
/******************************************/
/*!
@brief Returns width of block.
@return Block width.
*/
/******************************************/
int _width() { return width; }
/******************************************/
/*!
@brief Returns height of block.
@return Block height.
*/
/******************************************/
int _height() { return height; }
/******************************************/
/*!
@brief Returns block's row location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard row.
*/
/******************************************/
int _row() { return row; }
/******************************************/
/*!
@brief Returns block's column location
on an Adafruit IO dashboard.
@return Adafruit IO dashboard column
*/
/******************************************/
int _column() { return column; }
};
#endif // ADAFRUITIO_TEXTBLOCK_H

View File

@@ -0,0 +1,48 @@
/*!
* @file ToggleBlock.cpp
*
* This is part of the Adafruit IO library for the Arduino platform.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Tony DiCola, Todd Treece for Adafruit Industries
*
* MIT license, all text here must be included in any redistribution.
*
*/
#include "ToggleBlock.h"
/**************************************************************************/
/*!
@brief Creates a new Toggle Block on an Adafruit IO Dashboard.
@param d
Adafruit IO Dashboard name.
@param f
Adafruit IO Feed to display on the toggle block.
*/
/**************************************************************************/
ToggleBlock::ToggleBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
: AdafruitIO_Block(d, f) {
onText = "1";
offText = "0";
}
ToggleBlock::~ToggleBlock() {}
/**************************************************************************/
/*!
@brief Sets toggle block properties.
@return String containing properties of the toggle block.
*/
/**************************************************************************/
String ToggleBlock::properties() {
String props = "{\"onText\":\"";
props += onText;
props += "\",\"offText\":\"";
props += offText;
props += "\"}";
return props;
}

Some files were not shown because too many files have changed in this diff Show More