first commit
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
@@ -0,0 +1,305 @@
|
||||
// Adafruit IO House: Security System
|
||||
//
|
||||
// Learn Guide: https://learn.adafruit.com/adafruit-io-home-security
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
// include the NeoPixel library
|
||||
#include "Adafruit_NeoPixel.h"
|
||||
|
||||
// include the SGP30 library
|
||||
#include <Wire.h>
|
||||
#include "Adafruit_SGP30.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// delay the main `io.run()` loop
|
||||
#define LOOP_DELAY 3000
|
||||
// delay for each sensor send to adafruit io
|
||||
#define SENSOR_DELAY 1000
|
||||
|
||||
// PIR sensor input pin
|
||||
#define pirPin 13
|
||||
// reed switch input pin
|
||||
#define doorPin 2
|
||||
// piezo (alarm) buzzer
|
||||
#define piezoPin 14
|
||||
|
||||
/**** Time Setup ****/
|
||||
// set the hour to start at
|
||||
int startingHour = 1;
|
||||
// set the second to start at
|
||||
int seconds = 56;
|
||||
// set the minutes to start at
|
||||
int minutes = 56;
|
||||
// set the hour at which the motion alarm should trigger
|
||||
int alarmHour = 16;
|
||||
|
||||
unsigned long currentTime = 0;
|
||||
unsigned long prevTime = 0;
|
||||
int currentHour = startingHour;
|
||||
|
||||
|
||||
/*********NeoPixel Setup*********/
|
||||
// pin the NeoPixel strip and jewel are connected to
|
||||
#define NEOPIXEL_PIN 12
|
||||
// amount of neopixels on the NeoPixel strip
|
||||
#define STRIP_PIXEL_COUNT 60
|
||||
#define JEWEL_PIXEL_COUNT 7
|
||||
// type of neopixels used by the NeoPixel strip and jewel.
|
||||
#define PIXEL_TYPE NEO_GRB + NEO_KHZ800
|
||||
// init. neoPixel Strip
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIP_PIXEL_COUNT, NEOPIXEL_PIN, PIXEL_TYPE);
|
||||
|
||||
// sketch starts assuming no motion is detected
|
||||
int pirState = LOW;
|
||||
// sketch starts assuming the the door is closed
|
||||
int doorState = LOW;
|
||||
// alarm state
|
||||
bool isAlarm = false;
|
||||
// variable for reading the pin status
|
||||
int pirRead = 0;
|
||||
// SGP30 Sensor Object
|
||||
Adafruit_SGP30 sgp;
|
||||
|
||||
/*** Adafruit IO Feed Setup ***/
|
||||
// 'indoor-lights' feed
|
||||
AdafruitIO_Feed *indoorLights = io.feed("indoor-lights");
|
||||
// `outdoor-lights` feed
|
||||
AdafruitIO_Feed *outdoorLights = io.feed("outdoor-lights");
|
||||
// `front-door` feed
|
||||
AdafruitIO_Feed *frontDoor = io.feed("front-door");
|
||||
// `motion-detector` feed
|
||||
AdafruitIO_Feed *motionFeed = io.feed("motion-detector");
|
||||
// `home-alarm` feed
|
||||
AdafruitIO_Feed *homeAlarm = io.feed("home-alarm");
|
||||
// 'tvoc' feed
|
||||
AdafruitIO_Feed *tvocFeed = io.feed("tvoc");
|
||||
// 'eco2' feed
|
||||
AdafruitIO_Feed *eco2Feed = io.feed("eco2");
|
||||
|
||||
void setup() {
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
Serial.println("Adafruit IO Home: Security");
|
||||
|
||||
Serial.println("Connecting to Adafruit IO");
|
||||
// start MQTT connection to io.adafruit.com
|
||||
io.connect();
|
||||
|
||||
// attach a message handler for the `home-alarm` feed
|
||||
homeAlarm->onMessage(handleAlarm);
|
||||
// subscribe to lighting feeds and register message handlers
|
||||
indoorLights->onMessage(indoorLightHandler);
|
||||
outdoorLights->onMessage(outdoorLightHandler);
|
||||
|
||||
// wait for an MQTT connection
|
||||
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
|
||||
// method to check on MQTT connection status specifically
|
||||
while(io.mqttStatus() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
// declare PIR sensor as input
|
||||
pinMode(pirPin, INPUT);
|
||||
// declare reed switch as input
|
||||
pinMode(doorPin, INPUT);
|
||||
// set up the SGP30 sensor
|
||||
setupSGP30();
|
||||
// init the neopixel strip and set to `off`
|
||||
strip.begin();
|
||||
strip.show();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
getTime();
|
||||
Serial.println("* read door sensor...");
|
||||
readDoorSensor();
|
||||
Serial.println("* read motion detector");
|
||||
readPIR();
|
||||
Serial.println("* reading SGP30...");
|
||||
readSGP30();
|
||||
|
||||
// check if the alarm toggle is armed from the dashboard
|
||||
if (isAlarm == true) {
|
||||
if (doorState == HIGH || (currentHour>alarmHour && pirState == HIGH)) {
|
||||
playAlarmAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void playAlarmAnimation() {
|
||||
// plays the alarm piezo buzzer and turn on/off neopixels
|
||||
Serial.println("ALARM TRIGGERED!");
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// ESP32 doesn't use native tone() function
|
||||
ledcWriteTone(piezoPin, 220);
|
||||
#else
|
||||
tone(piezoPin, 220, 2);
|
||||
#endif
|
||||
|
||||
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, 255, 0, 0);
|
||||
}
|
||||
strip.show();
|
||||
delay(500);
|
||||
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, 0, 0, 0);
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
|
||||
void readDoorSensor() {
|
||||
// reads the status of the front door and sends to adafruit io
|
||||
doorState = digitalRead(doorPin);
|
||||
if (doorState == LOW) {
|
||||
Serial.println("* Door Closed");
|
||||
frontDoor->save(1);
|
||||
} else {
|
||||
Serial.println("* Door Open");
|
||||
frontDoor->save(3);
|
||||
}
|
||||
delay(SENSOR_DELAY);
|
||||
}
|
||||
|
||||
void readPIR() {
|
||||
// check if motion is detected in front of the home
|
||||
pirRead = digitalRead(pirPin);
|
||||
if (pirRead == HIGH) {
|
||||
if (pirState == LOW) {
|
||||
// we have just turned on
|
||||
Serial.println("* Motion detected in front of home!");
|
||||
motionFeed->save(3);
|
||||
pirState = HIGH;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (pirState == HIGH) {
|
||||
Serial.println("* Motion ended.");
|
||||
motionFeed->save(0);
|
||||
pirState = LOW;
|
||||
}
|
||||
}
|
||||
delay(SENSOR_DELAY);
|
||||
}
|
||||
|
||||
void readSGP30() {
|
||||
// reads the SGP30 sensor and sends data to Adafruit IO
|
||||
if (! sgp.IAQmeasure()) {
|
||||
Serial.println("Measurement failed");
|
||||
return;
|
||||
}
|
||||
Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t");
|
||||
Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm");
|
||||
tvocFeed->save(int(sgp.TVOC));
|
||||
delay(SENSOR_DELAY/2);
|
||||
eco2Feed->save(int(sgp.eCO2));
|
||||
delay(SENSOR_DELAY/2);
|
||||
}
|
||||
|
||||
/*** MQTT messageHandlers ***/
|
||||
void handleAlarm(AdafruitIO_Data *data) {
|
||||
// handle the alarm toggle on the Adafruit IO Dashboard
|
||||
String toggleValue = data->toString();
|
||||
Serial.print("> rcv alarm: ");
|
||||
Serial.println(toggleValue);
|
||||
if(toggleValue == String("ON")) {
|
||||
Serial.println("* Alarm Set: ON");
|
||||
isAlarm = true;
|
||||
} else {
|
||||
Serial.println("* Alarm Set: OFF");
|
||||
isAlarm = false;
|
||||
}
|
||||
}
|
||||
|
||||
// handles the indoor light colorpicker on the Adafruit IO Dashboard
|
||||
void indoorLightHandler(AdafruitIO_Data *data) {
|
||||
Serial.print("-> indoor light HEX: ");
|
||||
Serial.println(data->value());
|
||||
long color = data->toNeoPixel();
|
||||
// set the color of each NeoPixel in the jewel
|
||||
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, color);
|
||||
}
|
||||
// 'set' the neopixel jewel to the new color
|
||||
strip.show();
|
||||
}
|
||||
|
||||
// handles the outdoor light colorpicker on the Adafruit IO Dashboard
|
||||
void outdoorLightHandler(AdafruitIO_Data *data) {
|
||||
Serial.print("-> outdoor light HEX: ");
|
||||
Serial.println(data->value());
|
||||
long color = data->toNeoPixel();
|
||||
// set the color of each NeoPixel in the strip
|
||||
for(int i=JEWEL_PIXEL_COUNT; i<STRIP_PIXEL_COUNT+JEWEL_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, color);
|
||||
}
|
||||
// 'set' the neopixel strip to the new color
|
||||
strip.show();
|
||||
}
|
||||
|
||||
|
||||
void setupSGP30(){
|
||||
// sets up the SGP30 Sensor
|
||||
if (! sgp.begin()) {
|
||||
Serial.println("Sensor not found :(");
|
||||
while (1);
|
||||
}
|
||||
Serial.print("Found SGP30 serial #");
|
||||
Serial.print(sgp.serialnumber[0], HEX);
|
||||
Serial.print(sgp.serialnumber[1], HEX);
|
||||
Serial.println(sgp.serialnumber[2], HEX);
|
||||
}
|
||||
|
||||
void getTime() {
|
||||
currentTime = millis()/1000;
|
||||
seconds = currentTime - prevTime;
|
||||
|
||||
if (seconds == 60) {
|
||||
prevTime = currentTime;
|
||||
minutes += 1;
|
||||
}
|
||||
if (minutes == 60) {
|
||||
minutes = 0;
|
||||
currentHour += 1;
|
||||
}
|
||||
if (currentHour == 24) {
|
||||
currentHour = 0;
|
||||
}
|
||||
|
||||
Serial.print("Time:");
|
||||
Serial.print(currentHour);
|
||||
Serial.print(":");
|
||||
Serial.print(minutes);
|
||||
Serial.print(":");
|
||||
Serial.println(seconds);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
//#define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
@@ -0,0 +1,156 @@
|
||||
// Adafruit IO House: Lights and Temperature
|
||||
//
|
||||
// Learn Guide: https://learn.adafruit.com/adafruit-io-house-lights-and-temperature
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
// include the NeoPixel library
|
||||
#include "Adafruit_NeoPixel.h"
|
||||
|
||||
// include the si7021 library
|
||||
#include "Adafruit_Si7021.h"
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// pin the NeoPixel strip is connected to
|
||||
#define STRIP_PIN 12
|
||||
// pin the NeoPixel Jewel is connected to
|
||||
#define JEWEL_PIN 2
|
||||
|
||||
// amount of neopixels on the NeoPixel strip
|
||||
#define STRIP_PIXEL_COUNT 34
|
||||
// amount of neopixels on the NeoPixel jewel
|
||||
#define JEWEL_PIXEL_COUNT 7
|
||||
|
||||
// type of neopixels used by the NeoPixel strip and jewel.
|
||||
#define PIXEL_TYPE NEO_GRB + NEO_KHZ800
|
||||
|
||||
// main loop() delay, in seconds
|
||||
#define TEMP_DELAY 7
|
||||
|
||||
// Temperature and Humidity: Si7021 Sensor
|
||||
int temperatureData;
|
||||
int humidityData;
|
||||
|
||||
// initalize neopixel strip
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIP_PIXEL_COUNT, STRIP_PIN, PIXEL_TYPE);
|
||||
// initalize neopixel jewel
|
||||
Adafruit_NeoPixel jewel = Adafruit_NeoPixel(JEWEL_PIXEL_COUNT, JEWEL_PIN, PIXEL_TYPE);
|
||||
|
||||
// initalize the sensor object
|
||||
Adafruit_Si7021 sensor = Adafruit_Si7021();
|
||||
|
||||
// set up the Adafruit IO feeds
|
||||
AdafruitIO_Feed *indoorLights = io.feed("indoor-lights");
|
||||
AdafruitIO_Feed *outdoorLights = io.feed("outdoor-lights");
|
||||
AdafruitIO_Feed *humidity = io.feed("humidity");
|
||||
AdafruitIO_Feed *temperature = io.feed("temperature");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// subscribe to lighting feeds and register message handlers
|
||||
indoorLights->onMessage(indoorLightHandler);
|
||||
outdoorLights->onMessage(outdoorLightHandler);
|
||||
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
// initalize the Si7021 sensor
|
||||
if (!sensor.begin()) {
|
||||
Serial.println("Did not find Si7021 sensor!");
|
||||
while (true);
|
||||
}
|
||||
Serial.println("Si7021 sensor set up!");
|
||||
|
||||
// initalize the neopixel strip and jewel.
|
||||
strip.begin();
|
||||
jewel.begin();
|
||||
|
||||
// set all neopixels on the strip and jewel to `off`.
|
||||
strip.show();
|
||||
jewel.show();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
temperatureData = sensor.readTemperature() * 1.8 + 32;
|
||||
humidityData = sensor.readHumidity();
|
||||
|
||||
|
||||
Serial.print("-> Sending Temperature to Adafruit IO: ");
|
||||
Serial.println(temperatureData);
|
||||
Serial.print("-> Sending Humidity to Adafruit IO: ");
|
||||
Serial.println(humidityData);
|
||||
|
||||
// send the state of the feed to adafruit io
|
||||
temperature->save(temperatureData);
|
||||
humidity->save(humidityData);
|
||||
|
||||
// delay the loop to avoid flooding Adafruit IO
|
||||
delay(1000*TEMP_DELAY);
|
||||
}
|
||||
|
||||
void indoorLightHandler(AdafruitIO_Data *data) {
|
||||
Serial.print("-> indoor light HEX: ");
|
||||
Serial.println(data->value());
|
||||
|
||||
long color = data->toNeoPixel();
|
||||
|
||||
// set the color of each NeoPixel in the jewel
|
||||
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
|
||||
jewel.setPixelColor(i, color);
|
||||
}
|
||||
// 'set' the neopixel jewel to the new color
|
||||
jewel.show();
|
||||
}
|
||||
|
||||
void outdoorLightHandler(AdafruitIO_Data *data) {
|
||||
Serial.print("-> outdoor light HEX: ");
|
||||
Serial.println(data->value());
|
||||
|
||||
long color = data->toNeoPixel();
|
||||
|
||||
// set the color of each NeoPixel in the strip
|
||||
for(int i=0; i<STRIP_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, color);
|
||||
}
|
||||
// 'set' the neopixel strip to the new color
|
||||
strip.show();
|
||||
}
|
||||
Reference in New Issue
Block a user