update
This commit is contained in:
parent
9b13d274c3
commit
e9c94ebfff
164
gemma_fire_v3/gemma_fire_v3.ino
Normal file
164
gemma_fire_v3/gemma_fire_v3.ino
Normal file
@ -0,0 +1,164 @@
|
||||
// Low power NeoPixel earrings example. Makes a nice blinky display
|
||||
// with just a few LEDs on at any time...uses MUCH less juice than
|
||||
// rainbow display!
|
||||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PIN 0
|
||||
#define FIRE_SIZE 15
|
||||
#define RED_SIZE 12
|
||||
#define LIGHTNING_SIZE 14
|
||||
|
||||
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, PIN);
|
||||
|
||||
uint8_t mode = 0, // Current animation effect
|
||||
offset = 0; // Position of spinny eyes
|
||||
uint32_t color = 0xffffff; // Start red
|
||||
uint32_t prevTime;
|
||||
uint32_t prevChange;
|
||||
uint8_t m = 0;
|
||||
uint32_t waiting = 8000;
|
||||
uint32_t changeTime = 120000;
|
||||
uint8_t colourMode = 0;
|
||||
|
||||
|
||||
const uint32_t mix[] = { 0xff00ff, 0x8f00ff, 0xf000ff };
|
||||
const uint32_t breathe[] = {7, 7, 15, 23, 30, 38, 45, 52, 58, 64, 70, 76, 80, 85, 89, 92, 95, 97, 98, 99, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 99, 98, 97, 95, 92, 89, 85, 80, 76, 70, 64, 58, 52, 45, 38, 30, 23, 15, 7 };
|
||||
const uint32_t fire[] = { 0xff2426, 0xfe3223, 0xfe4121, 0xfd4f1f, 0xfd5e1d, 0xfc6d1b, 0xfc7b18, 0xfb8a16, 0xfb9814, 0xfaa712, 0xfab610, 0xffc20d, 0xffd30b, 0xffe309, 0xfff407, 0xf7ff05 };
|
||||
const uint32_t lightning[] = { 0xffffff, 0x2436ff, 0x2e43fe, 0x3950fe, 0x4354fe, 0x4e6bfe, 0xffffff, 0x5879fe, 0x6386fe, 0x6d93fe, 0x78a1fe, 0x82aefe, 0x8dbcfe, 0x97c9fe, 0xa2d6fe, 0xace4fe }; // ,0xc2fffe, , , , , , , , , , };
|
||||
const uint32_t reds[] = { 0xf4c262, 0xff6961 , 0xff5c5c, 0xff1c00, 0xff0800, 0xff0000, 0xcd5c5c, 0xe34234, 0xd73b3e, 0xce1620, 0xcc0000, 0xb22222 }; //, , , , , , , , , , , 0xb31b1b};
|
||||
|
||||
const uint32_t clu_red_yellow[] = { 0xff0000, 0xff1100, 0xff2200, 0xff3300, 0xff4400, 0xff5500, 0xff6600, 0xff7700, 0xff8800, 0xff9900, 0xffaa00, 0xffbb00, 0xffcc00, 0xffdd00, 0xffee00, 0xffff00 };
|
||||
const uint32_t clu_blue_red[] = {0x0000ff, 0x2200ff, 0x4400ff, 0x6600ff, 0x8800ff, 0xaa00ff, 0xcc00ff, 0xee00ff, 0xff00ee, 0xff00cc, 0xff00aa, 0xff0088, 0xff0066, 0xff0044, 0xff0022, 0xff0000};
|
||||
const uint32_t clu_teal_purple[] = {0x00ffff, 0x00ddff, 0x00bbff, 0x0099ff, 0x0077ff, 0x0055ff, 0x0033ff, 0x0011ff, 0x1100ff, 0x3300ff, 0x5500ff, 0x7700ff, 0x9900ff, 0xbb00ff, 0xdd00ff, 0xff00ff};
|
||||
const uint32_t clu_red_orange[] = { 0xff0000, 0xff0c00, 0xff1700, 0xff2300, 0xff2f00, 0xff3a00, 0xff4600, 0xff5200, 0xff5d00, 0xff6900, 0xff7500, 0xff8000, 0xff8c00, 0xff9800, 0xffa300, 0xffaf00 };
|
||||
const uint32_t clu_teal_blue[] = { 0x00ffff, 0x00eeff, 0x00ddff, 0x00ccff, 0x00bbff, 0x00aaff, 0x0099ff, 0x0088ff, 0x0077ff, 0x0066ff, 0x0055ff, 0x0044ff, 0x0033ff, 0x0022ff, 0x0011ff, 0x0000ff };
|
||||
const uint32_t clu_red_black[] = { 0xff0000, 0xee0000, 0xdd0000, 0xcc0000, 0xbb0000, 0xaa0000, 0x990000, 0x880000, 0x770000, 0x660000, 0x550000, 0x440000, 0x330000, 0x220000, 0x080000, 0x000000 };
|
||||
const uint32_t clu_purple_yellow[] = { 0xff00ff, 0xff00dd, 0xff00bb, 0xff0099, 0xff0077, 0xff0055, 0xff0033, 0xff0011, 0xff1100, 0xff3300, 0xff5500, 0xff7700, 0xff9900, 0xffbb00, 0xffdd00, 0xffff00};
|
||||
const uint32_t clu_yellow_green[] = { 0xffff00, 0xeeff00, 0xddff00, 0xccff00, 0xbbff00, 0xaaff00, 0x99ff00, 0x88ff00, 0x77ff00, 0x66ff00, 0x55ff00, 0x44ff00, 0x33ff00, 0x22ff00, 0x11ff00, 0x00ff00 };
|
||||
const uint32_t clu_orange_green[] = { 0xff5300, 0xff6f00, 0xff8c00, 0xffa800, 0xffc500, 0xffe100, 0xfffe00, 0xe4ff00, 0xc7ff00, 0xabff00, 0x8eff00, 0x72ff00, 0x55ff00, 0x39ff00, 0x1cff00, 0x00ff00 };
|
||||
|
||||
const uint32_t clu[32];
|
||||
|
||||
|
||||
void setup() {
|
||||
pixels.begin();
|
||||
pixels.setBrightness(10); // 1/3 brightness
|
||||
prevTime = millis();
|
||||
prevChange = millis();
|
||||
|
||||
// colourMode = 1;
|
||||
// initclu();
|
||||
}
|
||||
|
||||
void initclu() {
|
||||
|
||||
memcpy(clu, clu_blue_red, sizeof clu_blue_red );
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
uint8_t i;
|
||||
uint32_t t;
|
||||
uint8_t B;
|
||||
|
||||
|
||||
|
||||
switch (mode) {
|
||||
|
||||
case 0: // Random sparks - just one LED on at a time!
|
||||
|
||||
//
|
||||
pixels.setPixelColor(0, color);
|
||||
pixels.show();
|
||||
delay(1000);
|
||||
break;
|
||||
|
||||
case 1: // Spinny wheels (8 LEDs on at a time)
|
||||
B = breathe[m];
|
||||
|
||||
// color = fire[random(FIRE_SIZE)];
|
||||
// color = lightning[random(LIGHTNING_SIZE)];
|
||||
color = 0xff0000;
|
||||
pixels.setPixelColor(0, color);
|
||||
pixels.setBrightness(B);
|
||||
pixels.show();
|
||||
|
||||
m++;
|
||||
if (m > 49) {
|
||||
m = 0;
|
||||
}
|
||||
|
||||
delay(60);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (colourMode == 0) {
|
||||
color = clu_red_yellow[random(FIRE_SIZE)];
|
||||
}
|
||||
if (colourMode == 1) {
|
||||
color = clu_blue_red[random(FIRE_SIZE)];
|
||||
}
|
||||
if (colourMode == 2) {
|
||||
color = clu_teal_purple[random(FIRE_SIZE)];
|
||||
}
|
||||
if (colourMode == 3) {
|
||||
color = clu_red_orange[random(FIRE_SIZE)];
|
||||
}
|
||||
if (colourMode == 4) {
|
||||
color = clu_purple_yellow[random(FIRE_SIZE)];
|
||||
}
|
||||
|
||||
// color = lightning[random(LIGHTNING_SIZE)];
|
||||
|
||||
pixels.setPixelColor(0, color);
|
||||
|
||||
pixels.show();
|
||||
|
||||
delay(120);
|
||||
break;
|
||||
}
|
||||
|
||||
t = millis();
|
||||
|
||||
|
||||
|
||||
if ((t - prevTime) > waiting) {
|
||||
|
||||
// color = fire[random(FIRE_SIZE)];
|
||||
mode++;
|
||||
m = 0;
|
||||
|
||||
if (mode > 2) {
|
||||
mode = 0;
|
||||
}
|
||||
switch (mode) {
|
||||
case 0:
|
||||
waiting = 8000;
|
||||
color = 0xff0000;
|
||||
// color = 0x007fff;
|
||||
break;
|
||||
case 1:
|
||||
waiting = 30000;
|
||||
break;
|
||||
case 2:
|
||||
waiting = 30000;
|
||||
pixels.setBrightness(60);
|
||||
break;
|
||||
}
|
||||
|
||||
if (mode == 2) {
|
||||
//++colourMode;
|
||||
//if (colourMode > 3) {
|
||||
// colourMode = 0;
|
||||
//}
|
||||
}
|
||||
//color = rgb[random(3)];
|
||||
prevTime = millis();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
name=Adafruit Circuit Playground
|
||||
version=1.8.0
|
||||
version=1.8.1
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=All in one library to control Adafruit's Circuit Playground board.
|
||||
|
@ -431,3 +431,8 @@ fmuls_f:
|
||||
.endfunc
|
||||
|
||||
#endif // __AVR__
|
||||
|
||||
#ifdef __SAMD21G18A__
|
||||
.cpu cortex-m0plus
|
||||
.fpu softvfp
|
||||
#endif
|
@ -4,7 +4,7 @@
|
||||
|
||||
![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, M0 WINC1500, & WICED), Cellular (32u4 FONA), and Ethernet (Ethernet FeatherWing)
|
||||
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, M0 WINC1500, & WICED), Cellular (32u4 FONA), and Ethernet (Ethernet FeatherWing)
|
||||
|
||||
|
||||
## Documentation
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -69,7 +69,7 @@ void loop() {
|
||||
// increment the count_1 by 1
|
||||
count_1 += 1;
|
||||
// increment the count_2 by 2
|
||||
count_2 *= 2;
|
||||
count_2 += 2;
|
||||
|
||||
// wait four seconds (1000 milliseconds == 1 second)
|
||||
delay(4000);
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2016 Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
@ -34,8 +34,8 @@ void setup() {
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
group->onMessage("count-1", one);
|
||||
group->onMessage("count-2", two);
|
||||
group->onMessage("example.count-1", one);
|
||||
group->onMessage("example.count-2", two);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
@ -47,6 +47,8 @@ void setup() {
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
// force IO to update our MQTT subscription with the current values of all feeds
|
||||
group->get();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
// 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
|
||||
|
||||
|
@ -0,0 +1,82 @@
|
||||
// Adafruit IO Device Information
|
||||
// desc: Displays Device, WiFi, and Adafruit IO connection information
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
// device mac address
|
||||
byte mac[6];
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
Serial.print("Connecting to Adafruit IO...");
|
||||
|
||||
// connect to io.adafruit.com
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
// Device Info
|
||||
Serial.println("----DEVICE INFO----");
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC Address: ");
|
||||
for(int i=0;i<6;i++) {
|
||||
Serial.print(mac[i], HEX);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
// Network Info
|
||||
Serial.println("----ROUTER INFO----");
|
||||
Serial.print("WIFI SSID: ");
|
||||
Serial.println(WIFI_SSID);
|
||||
Serial.print("WIFI Pass: ");
|
||||
Serial.println(WIFI_PASS);
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("RSSI:");
|
||||
Serial.println(rssi);
|
||||
|
||||
// Adafruit IO Info
|
||||
Serial.println("----ADAFRUIT IO INFO----");
|
||||
Serial.print("IO User: ");
|
||||
Serial.println(IO_USERNAME);
|
||||
Serial.print("IO Key: ");
|
||||
Serial.println(IO_KEY);
|
||||
Serial.print("IO Status: ");
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
/************************ 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 "AIO_USERNAME"
|
||||
#define IO_KEY "AIO_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
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
|
||||
|
||||
/******************************* 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 @@
|
||||
|
@ -0,0 +1,71 @@
|
||||
// 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
|
||||
ESP.deepSleep(1000000 * 2);
|
||||
}
|
||||
|
||||
// NOOP
|
||||
void loop() {
|
||||
}
|
||||
|
||||
|
||||
void feedWrite(){
|
||||
// set up `deepsleep` feed
|
||||
AdafruitIO_Feed *deepsleep = io.feed("deepsleep");
|
||||
Serial.println("sending value to feed 'deepsleep");
|
||||
// send data to deepsleep feed
|
||||
deepsleep->save(1);
|
||||
// write data to AIO
|
||||
io.run();
|
||||
}
|
||||
void connectAIO() {
|
||||
Serial.println("Connecting to Adafruit IO...");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while (io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/************************ 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 "AIO_USERNAME"
|
||||
#define IO_KEY "AIO_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 M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
@ -0,0 +1,94 @@
|
||||
// Adafruit IO Shared Feeds Write Example
|
||||
// desc: Example of writing a button value to a shared feed.
|
||||
//
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-feeds/sharing-a-feed
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// digital pin 5
|
||||
#define BUTTON_PIN 5
|
||||
|
||||
// the Adafruit IO username of whomever owns the feed
|
||||
#define FEED_OWNER "AIO_FEED_OWNER"
|
||||
|
||||
// set up a shared feed between you and the FEED_OWNER
|
||||
// make sure you have both read AND write access to this feed
|
||||
AdafruitIO_Feed *sharedFeed = io.feed("FEED-NAME", FEED_OWNER);
|
||||
|
||||
// button state
|
||||
bool current = false;
|
||||
bool last = false;
|
||||
|
||||
void setup() {
|
||||
|
||||
// set button pin as an input
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
// grab the current state of the button.
|
||||
// we have to flip the logic because we are
|
||||
// using a pullup resistor.
|
||||
if(digitalRead(BUTTON_PIN) == LOW)
|
||||
current = true;
|
||||
else
|
||||
current = false;
|
||||
|
||||
// return if the value hasn't changed
|
||||
if(current == last)
|
||||
return;
|
||||
|
||||
// save the current state to the 'sharedFeed' feed on adafruit io
|
||||
Serial.print("sending button -> ");
|
||||
Serial.println(current);
|
||||
sharedFeed->save(current);
|
||||
|
||||
// store last button state
|
||||
last = current;
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/************************ 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
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
@ -0,0 +1,78 @@
|
||||
// Adafruit IO Feed Reading
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-feeds/sharing-a-feed
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// the Adafruit IO username of whomever owns the feed
|
||||
#define FEED_OWNER "AIO_FEED_OWNER"
|
||||
|
||||
// set up the `sharedFeed`
|
||||
AdafruitIO_Feed *sharedFeed = io.feed("FEED-NAME", FEED_OWNER);
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// set up a message handler for the 'sharedFeed' feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io.
|
||||
sharedFeed->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
sharedFeed->get();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
}
|
||||
|
||||
// this function is called whenever an 'sharedFeed' feed message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the 'digital' feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
Serial.print("received <- ");
|
||||
Serial.println(data->toInt());
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/************************ 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
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
|
||||
|
||||
/******************************* 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 @@
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1,190 @@
|
||||
// Adafruit IO Environmental Data Logger
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-air-quality-monitor
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Adafruit IO Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
/**************************** Sensor Configuration ***************************************/
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_BME280.h>
|
||||
#include "Adafruit_VEML6070.h"
|
||||
#include "Adafruit_SGP30.h"
|
||||
|
||||
// BME280 Sensor Definitions
|
||||
#define BME_SCK 13
|
||||
#define BME_MISO 12
|
||||
#define BME_MOSI 11
|
||||
#define BME_CS 10
|
||||
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||
|
||||
// Instanciate the sensors
|
||||
Adafruit_BME280 bme;
|
||||
Adafruit_VEML6070 uv = Adafruit_VEML6070();
|
||||
Adafruit_SGP30 sgp;
|
||||
|
||||
/**************************** Example ***************************************/
|
||||
// Delay between sensor reads, in seconds
|
||||
#define READ_DELAY 10
|
||||
|
||||
// DHT22 Data
|
||||
int temperatureReading;
|
||||
int pressureReading;
|
||||
|
||||
// SGP30 Data
|
||||
int tvocReading = 0;
|
||||
int ecO2Reading = 0;
|
||||
|
||||
// BME280 Data
|
||||
int altitudeReading = 0;
|
||||
int humidityReading = 0;
|
||||
|
||||
// VEML6070 Data
|
||||
int uvReading = 0;
|
||||
|
||||
// set up the feeds for the BME280
|
||||
AdafruitIO_Feed *temperatureFeed = io.feed("temperature");
|
||||
AdafruitIO_Feed *humidityFeed = io.feed("humidity");
|
||||
AdafruitIO_Feed *pressureFeed = io.feed("pressure");
|
||||
AdafruitIO_Feed *altitudeFeed = io.feed("altitude");
|
||||
|
||||
// set up feed for the VEML6070
|
||||
AdafruitIO_Feed *uvFeed = io.feed("uv");
|
||||
|
||||
// set up feeds for the SGP30
|
||||
AdafruitIO_Feed *tvocFeed = io.feed("tvoc");
|
||||
AdafruitIO_Feed *ecO2Feed = io.feed("ecO2");
|
||||
|
||||
void setup() {
|
||||
// start the serial connection
|
||||
Serial.begin(9600);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("Adafruit IO Environmental Logger");
|
||||
|
||||
// set up BME280
|
||||
setupBME280();
|
||||
// set up SGP30
|
||||
setupSGP30();
|
||||
// setup VEML6070
|
||||
uv.begin(VEML6070_1_T);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while (io.status() < AIO_CONNECTED)
|
||||
{
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
Serial.println("Reading Sensors...");
|
||||
|
||||
// Read the temperature from the BME280
|
||||
temperatureReading = bme.readTemperature();
|
||||
|
||||
// convert from celsius to degrees fahrenheit
|
||||
temperatureReading = temperatureReading * 1.8 + 32;
|
||||
|
||||
Serial.print("Temperature = "); Serial.print(temperatureReading); Serial.println(" *F");
|
||||
|
||||
// Read the pressure from the BME280
|
||||
pressureReading = bme.readPressure() / 100.0F;
|
||||
Serial.print("Pressure = "); Serial.print(pressureReading); Serial.println(" hPa");
|
||||
|
||||
// Read the altitude from the BME280
|
||||
altitudeReading = bme.readAltitude(SEALEVELPRESSURE_HPA);
|
||||
Serial.print("Approx. Altitude = "); Serial.print(altitudeReading); Serial.println(" m");
|
||||
|
||||
// Read the humidity from the BME280
|
||||
humidityReading = bme.readHumidity();
|
||||
Serial.print("Humidity = "); Serial.print(humidityReading); Serial.println("%");
|
||||
|
||||
// VEML6070
|
||||
uvReading = uv.readUV();
|
||||
Serial.print("UV Light Level: "); Serial.println(uvReading);
|
||||
|
||||
if(! sgp.IAQmeasure()){
|
||||
tvocReading = -1;
|
||||
ecO2Reading = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
tvocReading = sgp.TVOC;
|
||||
ecO2Reading = sgp.eCO2;
|
||||
}
|
||||
|
||||
Serial.print("TVOC: "); Serial.print(tvocReading); Serial.print(" ppb\t");
|
||||
Serial.print("eCO2: "); Serial.print(ecO2Reading); Serial.println(" ppm");
|
||||
|
||||
// send data to Adafruit IO feeds
|
||||
temperatureFeed->save(temperatureReading);
|
||||
humidityFeed->save(humidityReading);
|
||||
altitudeFeed->save(altitudeReading);
|
||||
pressureFeed->save(pressureReading);
|
||||
uvFeed->save(uvReading);
|
||||
ecO2Feed->save(ecO2Reading);
|
||||
tvocFeed->save(tvocReading);
|
||||
|
||||
// delay the polled loop
|
||||
delay(READ_DELAY * 1000);
|
||||
}
|
||||
|
||||
// Set up the SGP30 sensor
|
||||
void setupSGP30() {
|
||||
if (!sgp.begin())
|
||||
{
|
||||
Serial.println("Sensor not found :(");
|
||||
while (1);
|
||||
}
|
||||
Serial.print("Found SGP30 serial #");
|
||||
Serial.print(sgp.serialnumber[0], HEX);
|
||||
Serial.print(sgp.serialnumber[1], HEX);
|
||||
Serial.println(sgp.serialnumber[2], HEX);
|
||||
|
||||
// If you previously calibrated the sensor in this environment,
|
||||
// you can assign it to self-calibrate (replace the values with your baselines):
|
||||
// sgp.setIAQBaseline(0x8E68, 0x8F41);
|
||||
}
|
||||
|
||||
// Set up the BME280 sensor
|
||||
void setupBME280() {
|
||||
bool status;
|
||||
status = bme.begin();
|
||||
if (!status)
|
||||
{
|
||||
Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
||||
while (1);
|
||||
}
|
||||
Serial.println("BME Sensor is set up!");
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/************************ 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
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
@ -0,0 +1,109 @@
|
||||
// Adafruit IO IFTTT Example - Gmailbox
|
||||
// Tutorial Link: https://learn.adafruit.com/gmailbox
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
// Import Servo Libraries
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// ESP32Servo Library (https://github.com/madhephaestus/ESP32Servo)
|
||||
// installation: library manager -> search -> "ESP32Servo"
|
||||
#include <ESP32Servo.h>
|
||||
#else
|
||||
#include <Servo.h>
|
||||
#endif
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// pin used to control the servo
|
||||
#define SERVO_PIN 14
|
||||
|
||||
// Flag's up position, in degrees
|
||||
#define FLAG_UP 0
|
||||
|
||||
// Flag's down position, in degrees
|
||||
#define FLAG_DOWN 180
|
||||
|
||||
// How long to hold the flag up, in seconds
|
||||
#define FLAG_DELAY 2
|
||||
|
||||
// create an instance of the servo class
|
||||
Servo servo;
|
||||
|
||||
// set up the 'servo' feed
|
||||
AdafruitIO_Feed *gmail_feed = io.feed("gmail");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
Serial.print("IFTTT Gmailbox");
|
||||
|
||||
// tell the servo class which pin we are using
|
||||
servo.attach(SERVO_PIN);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// set up a message handler for the 'servo' feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io.
|
||||
gmail_feed->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
gmail_feed->get();
|
||||
|
||||
// write flag to down position
|
||||
servo.write(FLAG_DOWN);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
}
|
||||
|
||||
// this function is called whenever a 'gmail' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the gmail feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
Serial.println("You've got mail!");
|
||||
servo.write(FLAG_UP);
|
||||
// wait FLAG_DELAY seconds
|
||||
delay(FLAG_DELAY * 1000);
|
||||
servo.write(FLAG_DOWN);
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/************************ 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
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
|
||||
|
||||
/******************************* 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,43 @@
|
||||
/************************ 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_AIO_USERNAME"
|
||||
#define IO_KEY "YOUR_AIO_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 M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
|
||||
#define WIFI_SSID "YOUR_WIFI_SSID"
|
||||
#define WIFI_PASS "YOUR_WIFI_PASS"
|
||||
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
|
||||
|
||||
/******************************* 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,298 @@
|
||||
// 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 *alarm = 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
|
||||
alarm->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!");
|
||||
tone(piezoPin, 220, 2);
|
||||
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 @@
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1,44 @@
|
||||
/************************ 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
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
|
||||
|
||||
/******************************* 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();
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
name=Adafruit IO Arduino
|
||||
version=2.7.7
|
||||
version=2.7.19
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
maintainer=Adafruit <adafruitio@adafruit.com>
|
||||
sentence=Arduino library to access Adafruit IO.
|
||||
paragraph=Arduino library to access Adafruit IO using the Adafruit ESP8266, ESP32, M0 WINC1500, WICED, MKR1000, Ethernet, or FONA hardware.
|
||||
category=Communication
|
||||
|
@ -78,6 +78,11 @@ AdafruitIO_Feed* AdafruitIO::feed(const char* name)
|
||||
return new AdafruitIO_Feed(this, name);
|
||||
}
|
||||
|
||||
AdafruitIO_Feed* AdafruitIO::feed(const char* name, const char* owner)
|
||||
{
|
||||
return new AdafruitIO_Feed(this, name, owner);
|
||||
}
|
||||
|
||||
AdafruitIO_Time* AdafruitIO::time(aio_time_format_t format)
|
||||
{
|
||||
return new AdafruitIO_Time(this, format);
|
||||
|
@ -49,6 +49,7 @@ class AdafruitIO {
|
||||
void run(uint16_t busywait_ms = 0);
|
||||
|
||||
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);
|
||||
|
@ -337,46 +337,56 @@ unsigned long AdafruitIO_Data::toUnsignedLong()
|
||||
|
||||
int AdafruitIO_Data::toRed()
|
||||
{
|
||||
if(! _value)
|
||||
// Convert 0xRRGGBB to red.
|
||||
if (! _value)
|
||||
{
|
||||
return 0;
|
||||
|
||||
char r[] = "0x";
|
||||
strncat(r, toChar() + 1, 2);
|
||||
|
||||
}
|
||||
char r[5];
|
||||
strcpy(r, "0x");
|
||||
strncpy(&r[2], toChar() + 1, 2);
|
||||
r[4] = '\x00';
|
||||
return (int)strtol(r, NULL, 0);
|
||||
}
|
||||
|
||||
int AdafruitIO_Data::toGreen()
|
||||
{
|
||||
if(! _value)
|
||||
// Convert 0xRRGGBB to green.
|
||||
if (! _value)
|
||||
{
|
||||
return 0;
|
||||
|
||||
char g[] = "0x";
|
||||
strncat(g, toChar() + 3, 2);
|
||||
|
||||
}
|
||||
char g[5];
|
||||
strcpy(g, "0x");
|
||||
strncpy(&g[2], toChar() + 3, 2);
|
||||
g[4] = '\x00';
|
||||
return (int)strtol(g, NULL, 0);
|
||||
}
|
||||
|
||||
int AdafruitIO_Data::toBlue()
|
||||
{
|
||||
if(! _value)
|
||||
// Convert 0xRRGGBB to blue.
|
||||
if (! _value)
|
||||
{
|
||||
return 0;
|
||||
|
||||
char b[] = "0x";
|
||||
strncat(b, toChar() + 5, 2);
|
||||
|
||||
}
|
||||
char b[5];
|
||||
strcpy(b, "0x");
|
||||
strncpy(&b[2], toChar() + 5, 2);
|
||||
b[4] = '\x00';
|
||||
return (int)strtol(b, NULL, 0);
|
||||
}
|
||||
|
||||
long AdafruitIO_Data::toNeoPixel()
|
||||
{
|
||||
if(! _value)
|
||||
if (! _value)
|
||||
{
|
||||
return 0;
|
||||
|
||||
char rgb_string[9] = "0x";
|
||||
strncat(rgb_string, toChar() + 1, 6);
|
||||
|
||||
return strtol(rgb_string, NULL, 0);
|
||||
}
|
||||
char rgb[9];
|
||||
strcpy(rgb, "0x");
|
||||
strncpy(&rgb[2], toChar() + 1, 6);
|
||||
return strtol(rgb, NULL, 0);
|
||||
}
|
||||
|
||||
char* AdafruitIO_Data::toCSV()
|
||||
|
@ -16,10 +16,16 @@ AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n):AdafruitIO_MQTT(
|
||||
{
|
||||
_io = io;
|
||||
name = n;
|
||||
_sub = 0;
|
||||
_pub = 0;
|
||||
_get_pub = 0;
|
||||
_dataCallback = 0;
|
||||
owner = _io->_username;
|
||||
|
||||
_init();
|
||||
}
|
||||
|
||||
AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n, const char *un):AdafruitIO_MQTT()
|
||||
{
|
||||
_io = io;
|
||||
name = n;
|
||||
owner = un;
|
||||
|
||||
_init();
|
||||
}
|
||||
@ -33,7 +39,7 @@ AdafruitIO_Feed::~AdafruitIO_Feed()
|
||||
delete _pub;
|
||||
|
||||
if(_get_pub)
|
||||
delete _pub;
|
||||
delete _get_pub;
|
||||
|
||||
if(data)
|
||||
delete data;
|
||||
@ -159,7 +165,7 @@ AdafruitIO_Data* AdafruitIO_Feed::lastValue()
|
||||
{
|
||||
// 15 extra for api path, 12 for /data/retain, 1 for null
|
||||
String url = "/api/v2/";
|
||||
url += _io->_username;
|
||||
url += owner;
|
||||
url += "/feeds/";
|
||||
url += name;
|
||||
url += "/data/retain";
|
||||
@ -181,6 +187,8 @@ AdafruitIO_Data* AdafruitIO_Feed::lastValue()
|
||||
return new AdafruitIO_Data(this, body.c_str());
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
} else {
|
||||
|
||||
AIO_ERROR_PRINT("error retrieving lastValue, status: ");
|
||||
@ -209,12 +217,16 @@ void AdafruitIO_Feed::subCallback(char *val, uint16_t len)
|
||||
|
||||
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(_io->_username) + strlen(name) + 8)); // 8 extra chars for /f/, /csv & null termination
|
||||
_get_topic = (char *) malloc(sizeof(char) * (strlen(_io->_username) + strlen(name) + 12)); // 12 extra chars for /f/, /csv/get & null termination
|
||||
_feed_url = (char *) malloc(sizeof(char) * (strlen(_io->_username) + strlen(name) + 16)); // 16 extra for api path & null term
|
||||
_create_url = (char *) malloc(sizeof(char) * (strlen(_io->_username) + 15)); // 15 extra for api path & null term
|
||||
_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);
|
||||
@ -222,24 +234,24 @@ void AdafruitIO_Feed::_init()
|
||||
if(_topic && _create_url && _feed_url) {
|
||||
|
||||
// build topic string
|
||||
strcpy(_topic, _io->_username);
|
||||
strcpy(_topic, owner);
|
||||
strcat(_topic, "/f/");
|
||||
strcat(_topic, name);
|
||||
strcat(_topic, "/csv");
|
||||
|
||||
// build feed url string
|
||||
strcpy(_feed_url, "/api/v2/");
|
||||
strcat(_feed_url, _io->_username);
|
||||
strcat(_feed_url, owner);
|
||||
strcat(_feed_url, "/feeds/");
|
||||
strcat(_feed_url, name);
|
||||
|
||||
// build create url string
|
||||
strcpy(_create_url, "/api/v2/");
|
||||
strcat(_create_url, _io->_username);
|
||||
strcat(_create_url, owner);
|
||||
strcat(_create_url, "/feeds");
|
||||
|
||||
// build /get topic string
|
||||
strcpy(_get_topic, _io->_username);
|
||||
strcpy(_get_topic, owner);
|
||||
strcat(_get_topic, "/f/");
|
||||
strcat(_get_topic, name);
|
||||
strcat(_get_topic, "/csv/get");
|
||||
@ -256,6 +268,7 @@ void AdafruitIO_Feed::_init()
|
||||
|
||||
// malloc failed
|
||||
_topic = 0;
|
||||
_get_topic = 0;
|
||||
_create_url = 0;
|
||||
_feed_url = 0;
|
||||
_sub = 0;
|
||||
|
@ -25,6 +25,8 @@ 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);
|
||||
@ -48,6 +50,7 @@ class AdafruitIO_Feed : public AdafruitIO_MQTT {
|
||||
void subCallback(char *val, uint16_t len);
|
||||
|
||||
const char *name;
|
||||
const char *owner;
|
||||
|
||||
AdafruitIO_Data *lastValue();
|
||||
AdafruitIO_Data *data;
|
||||
|
@ -16,6 +16,7 @@ AdafruitIO_Group::AdafruitIO_Group(AdafruitIO *io, const char *n):AdafruitIO_MQT
|
||||
{
|
||||
_io = io;
|
||||
name = n;
|
||||
owner = _io->_username;
|
||||
|
||||
_init();
|
||||
}
|
||||
@ -28,12 +29,18 @@ AdafruitIO_Group::~AdafruitIO_Group()
|
||||
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);
|
||||
|
||||
@ -121,9 +128,14 @@ bool AdafruitIO_Group::save()
|
||||
|
||||
}
|
||||
|
||||
bool AdafruitIO_Group::get()
|
||||
{
|
||||
return _get_pub->publish("\0");
|
||||
}
|
||||
|
||||
AdafruitIO_Data* AdafruitIO_Group::getFeed(const char *feed)
|
||||
{
|
||||
uint8_t i;
|
||||
// uint8_t i;
|
||||
|
||||
if(data == NULL) {
|
||||
data = new AdafruitIO_Data(feed);
|
||||
@ -147,11 +159,13 @@ AdafruitIO_Data* AdafruitIO_Group::getFeed(const char *feed)
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
void AdafruitIO_Group::onMessage(AdafruitIODataCallbackType cb)
|
||||
{
|
||||
uint8_t i;
|
||||
// uint8_t i;
|
||||
|
||||
if(_groupCallback == NULL) {
|
||||
_groupCallback = new AdafruitIOGroupCallback(cb);
|
||||
@ -175,7 +189,7 @@ void AdafruitIO_Group::onMessage(AdafruitIODataCallbackType cb)
|
||||
|
||||
void AdafruitIO_Group::onMessage(const char *feed, AdafruitIODataCallbackType cb)
|
||||
{
|
||||
uint8_t i;
|
||||
// uint8_t i;
|
||||
|
||||
if(_groupCallback == NULL) {
|
||||
_groupCallback = new AdafruitIOGroupCallback(feed, cb);
|
||||
@ -203,7 +217,7 @@ void AdafruitIO_Group::onMessage(const char *feed, AdafruitIODataCallbackType cb
|
||||
|
||||
void AdafruitIO_Group::call(AdafruitIO_Data *d)
|
||||
{
|
||||
uint8_t i;
|
||||
// uint8_t i;
|
||||
|
||||
if(_groupCallback == NULL) {
|
||||
return;
|
||||
@ -266,7 +280,7 @@ void AdafruitIO_Group::subCallback(char *val, uint16_t len)
|
||||
|
||||
void AdafruitIO_Group::setLocation(double lat, double lon, double ele)
|
||||
{
|
||||
uint8_t i;
|
||||
// uint8_t i;
|
||||
|
||||
if(data == NULL) {
|
||||
return;
|
||||
@ -323,34 +337,42 @@ void AdafruitIO_Group::_init()
|
||||
{
|
||||
|
||||
// dynamically allocate memory for mqtt topic and REST URLs
|
||||
_topic = (char *) malloc(sizeof(char) * (strlen(_io->_username) + strlen(name) + 8)); // 8 extra chars for /g/, /csv & null termination
|
||||
_group_url = (char *) malloc(sizeof(char) * (strlen(_io->_username) + strlen(name) + 16)); // 16 extra for api path & null term
|
||||
_create_url = (char *) malloc(sizeof(char) * (strlen(_io->_username) + 15)); // 15 extra for api path & null term
|
||||
_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, _io->_username);
|
||||
strcpy(_topic, owner);
|
||||
strcat(_topic, "/g/");
|
||||
strcat(_topic, name);
|
||||
strcat(_topic, "/csv");
|
||||
|
||||
// build feed url string
|
||||
strcpy(_group_url, "/api/v2/");
|
||||
strcat(_group_url, _io->_username);
|
||||
strcat(_group_url, owner);
|
||||
strcat(_group_url, "/groups/");
|
||||
strcat(_group_url, name);
|
||||
|
||||
// build create url string
|
||||
strcpy(_create_url, "/api/v2/");
|
||||
strcat(_create_url, _io->_username);
|
||||
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);
|
||||
@ -359,10 +381,12 @@ void AdafruitIO_Group::_init()
|
||||
|
||||
// malloc failed
|
||||
_topic = 0;
|
||||
_get_topic = 0;
|
||||
_create_url = 0;
|
||||
_group_url = 0;
|
||||
_sub = 0;
|
||||
_pub = 0;
|
||||
_get_pub = 0;
|
||||
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ class AdafruitIO_Group : public AdafruitIO_MQTT {
|
||||
void set(const char *feed, double value);
|
||||
|
||||
bool save();
|
||||
bool get();
|
||||
|
||||
void setLocation(double lat=0, double lon=0, double ele=0);
|
||||
|
||||
@ -51,6 +52,7 @@ class AdafruitIO_Group : public AdafruitIO_MQTT {
|
||||
void call(AdafruitIO_Data *d);
|
||||
|
||||
const char *name;
|
||||
const char *owner;
|
||||
|
||||
AdafruitIO_Data *data;
|
||||
AdafruitIO_Data* getFeed(const char *feed);
|
||||
@ -59,11 +61,13 @@ class AdafruitIO_Group : public AdafruitIO_MQTT {
|
||||
void _init();
|
||||
|
||||
char *_topic;
|
||||
char *_get_topic;
|
||||
char *_create_url;
|
||||
char *_group_url;
|
||||
|
||||
Adafruit_MQTT_Subscribe *_sub;
|
||||
Adafruit_MQTT_Publish *_pub;
|
||||
Adafruit_MQTT_Publish *_get_pub;
|
||||
|
||||
AdafruitIO *_io;
|
||||
AdafruitIOGroupCallback *_groupCallback;
|
||||
|
@ -53,6 +53,7 @@ void AdafruitIO_Time::_init()
|
||||
|
||||
// dynamically allocate memory for mqtt topic and REST URLs
|
||||
const char *formatString;
|
||||
|
||||
switch (format) {
|
||||
case AIO_TIME_SECONDS:
|
||||
formatString = "seconds";
|
||||
@ -63,6 +64,9 @@ void AdafruitIO_Time::_init()
|
||||
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
|
||||
|
@ -25,7 +25,7 @@ String GaugeBlock::properties()
|
||||
{
|
||||
int w = 0;
|
||||
|
||||
if(ringWidth == "thin") {
|
||||
if (strcmp(ringWidth, "thin")) {
|
||||
w = 25;
|
||||
} else {
|
||||
w = 50;
|
||||
|
@ -17,16 +17,17 @@ MapBlock::MapBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f) : AdafruitIO_Blo
|
||||
tile = "contrast";
|
||||
}
|
||||
|
||||
MapBlock::~MapBlock(){}
|
||||
MapBlock::~MapBlock() {}
|
||||
|
||||
String MapBlock::properties()
|
||||
{
|
||||
|
||||
if(tile != "contrast" && tile != "street" && tile != "sat") {
|
||||
if ((strcmp(tile, "contrast") != 0) && (strcmp(tile, "street") != 0) && (strcmp(tile, "sat") != 0))
|
||||
{
|
||||
tile = "contrast";
|
||||
}
|
||||
|
||||
String props = "{\"historyHours\":\"";
|
||||
props = "{\"historyHours\":\"";
|
||||
props += historyHours;
|
||||
props += "\",\"tile\":\"";
|
||||
props += tile;
|
||||
|
@ -20,6 +20,7 @@ class MapBlock : public AdafruitIO_Block {
|
||||
MapBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
|
||||
~MapBlock();
|
||||
|
||||
String props;
|
||||
int historyHours;
|
||||
const char *tile;
|
||||
|
||||
|
@ -20,24 +20,26 @@ StreamBlock::StreamBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f) : Adafruit
|
||||
showName = true;
|
||||
}
|
||||
|
||||
StreamBlock::~StreamBlock(){}
|
||||
StreamBlock::~StreamBlock() {}
|
||||
|
||||
String StreamBlock::properties()
|
||||
{
|
||||
int s = 0;
|
||||
|
||||
if(fontSize == "small") {
|
||||
if (strcmp(fontSize, "small") == 0) {
|
||||
s = 12;
|
||||
} else if(fontSize == "medium") {
|
||||
}
|
||||
if (strcmp(fontSize, "medium") == 0) {
|
||||
s = 18;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
s = 24;
|
||||
}
|
||||
|
||||
String props = "{\"fontSize\":\"";
|
||||
props += s;
|
||||
props += "\",\"fontColor\":\"";
|
||||
props += fontColor == "white" ? "#ffffff" : "#63de00";
|
||||
props += (strcmp(fontColor, "white") == 0) ? "#ffffff" : "#63de00";
|
||||
props += "\",\"errors\":\"";
|
||||
props += showErrors ? "yes" : "no";
|
||||
props += "\",\"showTimestamp\":\"";
|
||||
|
@ -16,17 +16,22 @@ TextBlock::TextBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f) : AdafruitIO_B
|
||||
fontSize = "small";
|
||||
}
|
||||
|
||||
TextBlock::~TextBlock(){}
|
||||
TextBlock::~TextBlock() {}
|
||||
|
||||
String TextBlock::properties()
|
||||
{
|
||||
int s = 0;
|
||||
|
||||
if(fontSize == "small") {
|
||||
if ((strcmp(fontSize, "small") == 0))
|
||||
{
|
||||
s = 12;
|
||||
} else if(fontSize == "medium") {
|
||||
}
|
||||
else if ((strcmp(fontSize, "medium") == 0))
|
||||
{
|
||||
s = 18;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
s = 24;
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,6 @@ int8_t Adafruit_MQTT::connect() {
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
//Serial.println("\t**failed, retrying!");
|
||||
}
|
||||
if (! success) return -2; // failed to sub for some reason
|
||||
}
|
||||
@ -206,15 +205,20 @@ int8_t Adafruit_MQTT::connect(const char *user, const char *pass)
|
||||
|
||||
uint16_t Adafruit_MQTT::processPacketsUntil(uint8_t *buffer, uint8_t waitforpackettype, uint16_t timeout) {
|
||||
uint16_t len;
|
||||
while (len = readFullPacket(buffer, MAXBUFFERSIZE, timeout)) {
|
||||
|
||||
//DEBUG_PRINT("Packet read size: "); DEBUG_PRINTLN(len);
|
||||
// TODO: add subscription reading & call back processing here
|
||||
while(true) {
|
||||
len = readFullPacket(buffer, MAXBUFFERSIZE, timeout);
|
||||
|
||||
if ((buffer[0] >> 4) == waitforpackettype) {
|
||||
//DEBUG_PRINTLN(F("Found right packet"));
|
||||
if(len == 0){
|
||||
break;
|
||||
}
|
||||
|
||||
if ((buffer[0] >> 4) == waitforpackettype)
|
||||
{
|
||||
return len;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_PRINTLN(F("Dropped a packet"));
|
||||
}
|
||||
}
|
||||
@ -407,7 +411,6 @@ bool Adafruit_MQTT::unsubscribe(Adafruit_MQTT_Subscribe *sub) {
|
||||
}
|
||||
|
||||
void Adafruit_MQTT::processPackets(int16_t timeout) {
|
||||
uint16_t len;
|
||||
|
||||
uint32_t elapsed = 0, endtime, starttime = millis();
|
||||
|
||||
@ -482,7 +485,7 @@ Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) {
|
||||
if (i==MAXSUBSCRIPTIONS) return NULL; // matching sub not found ???
|
||||
|
||||
uint8_t packet_id_len = 0;
|
||||
uint16_t packetid;
|
||||
uint16_t packetid = 0;
|
||||
// Check if it is QoS 1, TODO: we dont support QoS 2
|
||||
if ((buffer[0] & 0x6) == 0x2) {
|
||||
packet_id_len = 2;
|
||||
|
@ -105,14 +105,13 @@
|
||||
#define MQTT_CONN_WILLFLAG 0x04
|
||||
#define MQTT_CONN_CLEANSESSION 0x02
|
||||
|
||||
// how many subscriptions we want to be able to track
|
||||
#define MAXSUBSCRIPTIONS 5
|
||||
|
||||
// how much data we save in a subscription object
|
||||
// eg max-subscription-payload-size
|
||||
// and how many subscriptions we want to be able to track.
|
||||
#if defined (__AVR_ATmega32U4__) || defined(__AVR_ATmega328P__)
|
||||
#define MAXSUBSCRIPTIONS 5
|
||||
#define SUBSCRIPTIONDATALEN 20
|
||||
#else
|
||||
#define MAXSUBSCRIPTIONS 15
|
||||
#define SUBSCRIPTIONDATALEN 100
|
||||
#endif
|
||||
|
||||
|
@ -53,6 +53,7 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen,
|
||||
uint16_t len = 0;
|
||||
int16_t t = timeout;
|
||||
|
||||
|
||||
while (client->connected() && (timeout >= 0)) {
|
||||
//DEBUG_PRINT('.');
|
||||
while (client->available()) {
|
||||
@ -62,6 +63,11 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen,
|
||||
buffer[len] = c;
|
||||
//DEBUG_PRINTLN((uint8_t)c, HEX);
|
||||
len++;
|
||||
|
||||
if (maxlen == 0) { // handle zero-length packets
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (len == maxlen) { // we read all we want, bail
|
||||
DEBUG_PRINT(F("Read data:\t"));
|
||||
DEBUG_PRINTBUFFER(buffer, len);
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=Adafruit MQTT Library
|
||||
version=0.20.1
|
||||
version=0.20.3
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=MQTT library that supports the FONA, ESP8266, Yun, and generic Arduino Client hardware.
|
||||
|
@ -2069,6 +2069,32 @@ void Adafruit_NeoPixel::setPixelColor(uint16_t n, uint32_t c) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fills all or a given start+length of strip. Arguments:
|
||||
// Packed RGB color (0 if unspecified, effectively a strip clear operation).
|
||||
// Index if first pixel (0 if unspecified - beginning of strip).
|
||||
// Pixel count (if unspecified, fills to end of strip).
|
||||
void Adafruit_NeoPixel::fill(uint32_t c, uint16_t first, uint16_t count) {
|
||||
uint16_t i, end;
|
||||
|
||||
if(first >= numLEDs) {
|
||||
return; // If first LED is past end of strip, nothing to do
|
||||
}
|
||||
|
||||
// Calculate the index ONE AFTER the last pixel to fill
|
||||
if(count == 0) {
|
||||
// Fill to end of strip
|
||||
end = numLEDs;
|
||||
} else {
|
||||
// Ensure that the loop won't go past the last pixel
|
||||
end = first + count;
|
||||
if(end > numLEDs) end = numLEDs;
|
||||
}
|
||||
|
||||
for(i = first; i < end; i++) {
|
||||
this->setPixelColor(i, c);
|
||||
}
|
||||
}
|
||||
|
||||
// Convert separate R,G,B into packed 32-bit RGB color.
|
||||
// Packed format is always RGB, regardless of LED strand color order.
|
||||
uint32_t Adafruit_NeoPixel::Color(uint8_t r, uint8_t g, uint8_t b) {
|
||||
|
@ -50,43 +50,43 @@
|
||||
// 0bRRRRGGBB for RGB
|
||||
|
||||
// RGB NeoPixel permutations; white and red offsets are always same
|
||||
// Offset: W R G B
|
||||
#define NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2))
|
||||
#define NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1))
|
||||
#define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2))
|
||||
#define NEO_GBR ((2 << 6) | (2 << 4) | (0 << 2) | (1))
|
||||
#define NEO_BRG ((1 << 6) | (1 << 4) | (2 << 2) | (0))
|
||||
#define NEO_BGR ((2 << 6) | (2 << 4) | (1 << 2) | (0))
|
||||
// Offset: W R G B // HEX representation
|
||||
#define NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2)) // 0x06
|
||||
#define NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1)) // 0x09
|
||||
#define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2)) // 0x52
|
||||
#define NEO_GBR ((2 << 6) | (2 << 4) | (0 << 2) | (1)) // 0xA1
|
||||
#define NEO_BRG ((1 << 6) | (1 << 4) | (2 << 2) | (0)) // 0x58
|
||||
#define NEO_BGR ((2 << 6) | (2 << 4) | (1 << 2) | (0)) // 0xA4
|
||||
|
||||
// RGBW NeoPixel permutations; all 4 offsets are distinct
|
||||
// Offset: W R G B
|
||||
#define NEO_WRGB ((0 << 6) | (1 << 4) | (2 << 2) | (3))
|
||||
#define NEO_WRBG ((0 << 6) | (1 << 4) | (3 << 2) | (2))
|
||||
#define NEO_WGRB ((0 << 6) | (2 << 4) | (1 << 2) | (3))
|
||||
#define NEO_WGBR ((0 << 6) | (3 << 4) | (1 << 2) | (2))
|
||||
#define NEO_WBRG ((0 << 6) | (2 << 4) | (3 << 2) | (1))
|
||||
#define NEO_WBGR ((0 << 6) | (3 << 4) | (2 << 2) | (1))
|
||||
// Offset: W R G B // HEX representation
|
||||
#define NEO_WRGB ((0 << 6) | (1 << 4) | (2 << 2) | (3)) // 0x1B
|
||||
#define NEO_WRBG ((0 << 6) | (1 << 4) | (3 << 2) | (2)) // 0x1E
|
||||
#define NEO_WGRB ((0 << 6) | (2 << 4) | (1 << 2) | (3)) // 0x27
|
||||
#define NEO_WGBR ((0 << 6) | (3 << 4) | (1 << 2) | (2)) // 0x36
|
||||
#define NEO_WBRG ((0 << 6) | (2 << 4) | (3 << 2) | (1)) // 0x2D
|
||||
#define NEO_WBGR ((0 << 6) | (3 << 4) | (2 << 2) | (1)) // 0x39
|
||||
|
||||
#define NEO_RWGB ((1 << 6) | (0 << 4) | (2 << 2) | (3))
|
||||
#define NEO_RWBG ((1 << 6) | (0 << 4) | (3 << 2) | (2))
|
||||
#define NEO_RGWB ((2 << 6) | (0 << 4) | (1 << 2) | (3))
|
||||
#define NEO_RGBW ((3 << 6) | (0 << 4) | (1 << 2) | (2))
|
||||
#define NEO_RBWG ((2 << 6) | (0 << 4) | (3 << 2) | (1))
|
||||
#define NEO_RBGW ((3 << 6) | (0 << 4) | (2 << 2) | (1))
|
||||
#define NEO_RWGB ((1 << 6) | (0 << 4) | (2 << 2) | (3)) // 0x4B
|
||||
#define NEO_RWBG ((1 << 6) | (0 << 4) | (3 << 2) | (2)) // 0x4E
|
||||
#define NEO_RGWB ((2 << 6) | (0 << 4) | (1 << 2) | (3)) // 0x87
|
||||
#define NEO_RGBW ((3 << 6) | (0 << 4) | (1 << 2) | (2)) // 0xC6
|
||||
#define NEO_RBWG ((2 << 6) | (0 << 4) | (3 << 2) | (1)) // 0x8D
|
||||
#define NEO_RBGW ((3 << 6) | (0 << 4) | (2 << 2) | (1)) // 0xC9
|
||||
|
||||
#define NEO_GWRB ((1 << 6) | (2 << 4) | (0 << 2) | (3))
|
||||
#define NEO_GWBR ((1 << 6) | (3 << 4) | (0 << 2) | (2))
|
||||
#define NEO_GRWB ((2 << 6) | (1 << 4) | (0 << 2) | (3))
|
||||
#define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2))
|
||||
#define NEO_GBWR ((2 << 6) | (3 << 4) | (0 << 2) | (1))
|
||||
#define NEO_GBRW ((3 << 6) | (2 << 4) | (0 << 2) | (1))
|
||||
#define NEO_GWRB ((1 << 6) | (2 << 4) | (0 << 2) | (3)) // 0x63
|
||||
#define NEO_GWBR ((1 << 6) | (3 << 4) | (0 << 2) | (2)) // 0x72
|
||||
#define NEO_GRWB ((2 << 6) | (1 << 4) | (0 << 2) | (3)) // 0x93
|
||||
#define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2)) // 0xD2
|
||||
#define NEO_GBWR ((2 << 6) | (3 << 4) | (0 << 2) | (1)) // 0xB1
|
||||
#define NEO_GBRW ((3 << 6) | (2 << 4) | (0 << 2) | (1)) // 0xE1
|
||||
|
||||
#define NEO_BWRG ((1 << 6) | (2 << 4) | (3 << 2) | (0))
|
||||
#define NEO_BWGR ((1 << 6) | (3 << 4) | (2 << 2) | (0))
|
||||
#define NEO_BRWG ((2 << 6) | (1 << 4) | (3 << 2) | (0))
|
||||
#define NEO_BRGW ((3 << 6) | (1 << 4) | (2 << 2) | (0))
|
||||
#define NEO_BGWR ((2 << 6) | (3 << 4) | (1 << 2) | (0))
|
||||
#define NEO_BGRW ((3 << 6) | (2 << 4) | (1 << 2) | (0))
|
||||
#define NEO_BWRG ((1 << 6) | (2 << 4) | (3 << 2) | (0)) // 0x6C
|
||||
#define NEO_BWGR ((1 << 6) | (3 << 4) | (2 << 2) | (0)) // 0x78
|
||||
#define NEO_BRWG ((2 << 6) | (1 << 4) | (3 << 2) | (0)) // 0x9C
|
||||
#define NEO_BRGW ((3 << 6) | (1 << 4) | (2 << 2) | (0)) // 0xD8
|
||||
#define NEO_BGWR ((2 << 6) | (3 << 4) | (1 << 2) | (0)) // 0xB4
|
||||
#define NEO_BGRW ((3 << 6) | (2 << 4) | (1 << 2) | (0)) // 0xE4
|
||||
|
||||
// Add NEO_KHZ400 to the color order value to indicate a 400 KHz
|
||||
// device. All but the earliest v1 NeoPixels expect an 800 KHz data
|
||||
@ -129,6 +129,7 @@ class Adafruit_NeoPixel {
|
||||
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b),
|
||||
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w),
|
||||
setPixelColor(uint16_t n, uint32_t c),
|
||||
fill(uint32_t c=0, uint16_t first=0, uint16_t count=0),
|
||||
setBrightness(uint8_t),
|
||||
clear(),
|
||||
updateLength(uint16_t n),
|
||||
|
@ -43,8 +43,7 @@ Things I'd Like To Do But There's No Official Timeline So Please Don't Count On
|
||||
|
||||
* For the show() function (with all the delicate pixel timing stuff), break out each architecture into separate source files rather than the current unmaintainable tangle of #ifdef statements!
|
||||
* Really the only reason I've never incorporated an HSV color function is that I haven't settled on a type and range for the hue element (mathematically an integer from 0 to 1529 yields a "most correct" approach but it's weird to use and would probably annoy people).
|
||||
* Add a fill function with the arguments: (color, first, count). Count, if unspecified, fills to end of strip. First, if unspecified, is zero. Color, if unspecified, is zero (effectively a strip clear operation). Do NOT then implement fifty billion minor variations (such as first, last). No. This argument sequence was very specifically chosen because reasons, and equivalents to such variations are trivially made in one's call. Just one fill function, please.
|
||||
* At such time that the prior two items are settled, revisit the DotStar library (and maybe even LPD8806 or anything else we've got) and add the same functions and behaviors so there's a good degree of sketch compatibility across different pixel types.
|
||||
* At such time that the prior item is settled (along with the recently-added fill() function in Adafruit_NeoPixel), revisit the DotStar library (and maybe even LPD8806 or anything else we've got) and add the same functions and behaviors so there's a good degree of sketch compatibility across different pixel types.
|
||||
* I wouldn't mind paring down strandtest a bit. More diagnostic, less Amiga demo.
|
||||
* Please don't use updateLength() or updateType() in new code. They should not have been implemented this way (use the C++ 'new' operator with the regular constructor instead) and are only sticking around because of the Prime Directive. setPin() is OK for now though, it's a trick we can use to 'recycle' pixel memory across multiple strips.
|
||||
* In the M0 and M4 code, use the hardware systick counter for bit timing rather than hand-tweaked NOPs (a temporary kludge at the time because I wasn't reading systick correctly).
|
||||
|
@ -0,0 +1,55 @@
|
||||
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
|
||||
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
|
||||
// This sketch show how to use "new" operator with Adafruit_NeoPixel library
|
||||
// It's helpful if you don't know NeoPixel settings at compile time or
|
||||
// you just want to store this settings in EEPROM
|
||||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#ifdef __AVR__
|
||||
#include <avr/power.h>
|
||||
#endif
|
||||
|
||||
// Which pin on the Arduino is connected to the NeoPixels?
|
||||
// On a Trinket or Gemma we suggest changing this to 1
|
||||
#define PIN 6
|
||||
|
||||
// How many NeoPixels are attached to the Arduino?
|
||||
int numPixel = 16;
|
||||
|
||||
// Color order, for more information see https://github.com/adafruit/Adafruit_NeoPixel/blob/master/Adafruit_NeoPixel.h
|
||||
uint8_t colorOrder = 0x52; //or just use NEO_GBR
|
||||
|
||||
// Define new pointer for NeoPixel
|
||||
Adafruit_NeoPixel *pixels;
|
||||
|
||||
|
||||
int delayval = 500; // delay for half a second
|
||||
|
||||
void setup() {
|
||||
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
|
||||
#if defined (__AVR_ATtiny85__)
|
||||
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
|
||||
#endif
|
||||
// End of trinket special code
|
||||
|
||||
// Here is a good place to read numPixel & colorOrder from EEPROM or what ever.
|
||||
// create a new NeoPixel instance with new values
|
||||
pixels = new Adafruit_NeoPixel(numPixel, PIN, colorOrder);
|
||||
pixels->begin(); // This initializes the NeoPixel library.
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
|
||||
|
||||
for(int i=0;i<numPixel;i++){
|
||||
|
||||
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
|
||||
pixels->setPixelColor(i, pixels->Color(0,150,0)); // Moderately bright green color.
|
||||
|
||||
pixels->show(); // This sends the updated pixel color to the hardware.
|
||||
|
||||
delay(delayval); // Delay for a period of time (in milliseconds).
|
||||
|
||||
}
|
||||
}
|
@ -35,6 +35,34 @@ NEO_COLMASK LITERAL1
|
||||
NEO_SPDMASK LITERAL1
|
||||
NEO_KHZ800 LITERAL1
|
||||
NEO_KHZ400 LITERAL1
|
||||
NEO_GRB LITERAL1
|
||||
NEO_RGB LITERAL1
|
||||
NEO_RBG LITERAL1
|
||||
NEO_GRB LITERAL1
|
||||
NEO_GBR LITERAL1
|
||||
NEO_BRG LITERAL1
|
||||
NEO_BGR LITERAL1
|
||||
NEO_WRGB LITERAL1
|
||||
NEO_WRBG LITERAL1
|
||||
NEO_WGRB LITERAL1
|
||||
NEO_WGBR LITERAL1
|
||||
NEO_WBRG LITERAL1
|
||||
NEO_WBGR LITERAL1
|
||||
NEO_RWGB LITERAL1
|
||||
NEO_RWBG LITERAL1
|
||||
NEO_RGWB LITERAL1
|
||||
NEO_RGBW LITERAL1
|
||||
NEO_RBWG LITERAL1
|
||||
NEO_RBGW LITERAL1
|
||||
NEO_GWRB LITERAL1
|
||||
NEO_GWBR LITERAL1
|
||||
NEO_GRWB LITERAL1
|
||||
NEO_GRBW LITERAL1
|
||||
NEO_GBWR LITERAL1
|
||||
NEO_GBRW LITERAL1
|
||||
NEO_BWRG LITERAL1
|
||||
NEO_BWGR LITERAL1
|
||||
NEO_BRWG LITERAL1
|
||||
NEO_BRGW LITERAL1
|
||||
NEO_BGWR LITERAL1
|
||||
NEO_BGRW LITERAL1
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=Adafruit NeoPixel
|
||||
version=1.1.6
|
||||
version=1.1.7
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library for controlling single-wire-based LED pixels and strip.
|
||||
|
@ -1,10 +1,96 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
v6.2.0-beta
|
||||
v6.5.0-beta (2018-10-13)
|
||||
-----------
|
||||
|
||||
* Added implicit conversion from `JsonArray` and `JsonObject` to `JsonVariant`
|
||||
* Allow mixed configuration in compilation units (issue #809)
|
||||
* Fixed object keys not being duplicated
|
||||
* `JsonPair::key()` now returns a `JsonKey`
|
||||
* Increased the default capacity of `DynamicJsonDocument`
|
||||
* Fixed `JsonVariant::is<String>()` (closes #763)
|
||||
* Added `JsonArrayConst`, `JsonObjectConst`, and `JsonVariantConst`
|
||||
* Added copy-constructor and copy-assignment-operator for `JsonDocument` (issue #827)
|
||||
|
||||
v6.4.0-beta (2018-09-11)
|
||||
-----------
|
||||
|
||||
* Copy `JsonArray` and `JsonObject`, instead of storing pointers (issue #780)
|
||||
* Added `JsonVariant::to<JsonArray>()` and `JsonVariant::to<JsonObject>()`
|
||||
|
||||
v6.3.0-beta (2018-08-31)
|
||||
-----------
|
||||
|
||||
* Implemented reference semantics for `JsonVariant`
|
||||
* Replaced `JsonPair`'s `key` and `value` with `key()` and `value()`
|
||||
* Fixed `serializeJson(obj[key], dst)` (issue #794)
|
||||
|
||||
> ### BREAKING CHANGES
|
||||
>
|
||||
> #### JsonVariant
|
||||
>
|
||||
> `JsonVariant` now has a semantic similar to `JsonObject` and `JsonArray`.
|
||||
> It's a reference to a value stored in the `JsonDocument`.
|
||||
> As a consequence, a `JsonVariant` cannot be used as a standalone variable anymore.
|
||||
>
|
||||
> Old code:
|
||||
>
|
||||
> ```c++
|
||||
> JsonVariant myValue = 42;
|
||||
> ```
|
||||
>
|
||||
> New code:
|
||||
>
|
||||
> ```c++
|
||||
> DynamicJsonDocument doc;
|
||||
> JsonVariant myValue = doc.to<JsonVariant>();
|
||||
> myValue.set(42);
|
||||
> ```
|
||||
>
|
||||
> #### JsonPair
|
||||
>
|
||||
> Old code:
|
||||
>
|
||||
> ```c++
|
||||
> for(JsonPair p : myObject) {
|
||||
> Serial.println(p.key);
|
||||
> Serial.println(p.value.as<int>());
|
||||
> }
|
||||
> ```
|
||||
>
|
||||
> New code:
|
||||
>
|
||||
> ```c++
|
||||
> for(JsonPair p : myObject) {
|
||||
> Serial.println(p.key());
|
||||
> Serial.println(p.value().as<int>());
|
||||
> }
|
||||
> ```
|
||||
>
|
||||
> CAUTION: the key is now read only!
|
||||
|
||||
v6.2.3-beta (2018-07-19)
|
||||
-----------
|
||||
|
||||
* Fixed exception when using Flash strings as object keys (issue #784)
|
||||
|
||||
v6.2.2-beta (2018-07-18)
|
||||
-----------
|
||||
|
||||
* Fixed `invalid application of 'sizeof' to incomplete type '__FlashStringHelper'` (issue #783)
|
||||
* Fixed `char[]` not duplicated when passed to `JsonVariant::operator[]`
|
||||
|
||||
v6.2.1-beta (2018-07-17)
|
||||
-----------
|
||||
|
||||
* Fixed `JsonObject` not inserting keys of type `String` (issue #782)
|
||||
|
||||
v6.2.0-beta (2018-07-12)
|
||||
-----------
|
||||
|
||||
* Disabled lazy number deserialization (issue #772)
|
||||
* Fixed `JsonVariant::is<int>()` that returned true for empty strings
|
||||
* Improved float serialization when `-fsingle-precision-constant` is used
|
||||
* Renamed function `RawJson()` to `serialized()`
|
||||
* `serializeMsgPack()` now supports values marked with `serialized()`
|
||||
@ -30,7 +116,7 @@ v6.2.0-beta
|
||||
> object["values"] = serialized("[1,2,3,4]");
|
||||
> ```
|
||||
|
||||
v6.1.0-beta
|
||||
v6.1.0-beta (2018-07-02)
|
||||
-----------
|
||||
|
||||
* Return `JsonArray` and `JsonObject` by value instead of reference (issue #309)
|
||||
@ -60,12 +146,12 @@ v6.1.0-beta
|
||||
> }
|
||||
> ```
|
||||
|
||||
v6.0.1-beta
|
||||
v6.0.1-beta (2018-06-11)
|
||||
-----------
|
||||
|
||||
* Fixed conflicts with `isnan()` and `isinf()` macros (issue #752)
|
||||
|
||||
v6.0.0-beta
|
||||
v6.0.0-beta (2018-06-07)
|
||||
-----------
|
||||
|
||||
* Added `DynamicJsonDocument` and `StaticJsonDocument`
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
---
|
||||
|
||||
[![Build status](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/master?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/master) [![Build Status](https://travis-ci.org/bblanchon/ArduinoJson.svg?branch=master)](https://travis-ci.org/bblanchon/ArduinoJson) [![Coverage Status](https://img.shields.io/coveralls/bblanchon/ArduinoJson.svg)](https://coveralls.io/r/bblanchon/ArduinoJson?branch=master) [![Star this project](http://githubbadges.com/star.svg?user=bblanchon&repo=ArduinoJson&style=flat&color=fff&background=007ec6)](https://github.com/bblanchon/ArduinoJson)
|
||||
[![Build status](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) [![Build Status](https://travis-ci.org/bblanchon/ArduinoJson.svg?branch=6.x)](https://travis-ci.org/bblanchon/ArduinoJson) [![Coverage Status](https://img.shields.io/coveralls/bblanchon/ArduinoJson.svg)](https://coveralls.io/r/bblanchon/ArduinoJson?branch=6.x) [![Star this project](http://githubbadges.com/star.svg?user=bblanchon&repo=ArduinoJson&style=flat&color=fff&background=007ec6)](https://github.com/bblanchon/ArduinoJson)
|
||||
|
||||
ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 6.0.1.{build}
|
||||
version: 6.4.0.{build}
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
|
@ -7,7 +7,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/bblanchon/ArduinoJson.git"
|
||||
},
|
||||
"version": "6.2.0-beta",
|
||||
"version": "6.5.0-beta",
|
||||
"authors": {
|
||||
"name": "Benoit Blanchon",
|
||||
"url": "https://blog.benoitblanchon.fr"
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=ArduinoJson
|
||||
version=6.2.0-beta
|
||||
version=6.5.0-beta
|
||||
author=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
sentence=An efficient and elegant JSON library for Arduino.
|
||||
|
49
libraries/ArduinoJson/scripts/publish.sh
Normal file
49
libraries/ArduinoJson/scripts/publish.sh
Normal file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eu
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
VERSION="$1"
|
||||
DATE=$(date +%F)
|
||||
TAG="v$VERSION"
|
||||
|
||||
update_version_in_source () {
|
||||
IFS=".-" read MAJOR MINOR REVISION EXTRA < <(echo "$VERSION")
|
||||
UNDERLINE=$(printf -- '-%.0s' $(seq 1 ${#TAG}))
|
||||
|
||||
sed -i~ -bE "4s/HEAD/$TAG ($DATE)/; 5s/-+/$UNDERLINE/" CHANGELOG.md
|
||||
rm CHANGELOG.md*~
|
||||
sed -i~ -bE "s/\"version\":.*$/\"version\": \"$VERSION\",/" library.json
|
||||
rm library.json*~
|
||||
|
||||
sed -i~ -bE "s/version=.*$/version=$VERSION/" library.properties
|
||||
rm library.properties*~
|
||||
|
||||
sed -i~ -bE \
|
||||
-e "s/ARDUINOJSON_VERSION .*$/ARDUINOJSON_VERSION \"$VERSION\"/" \
|
||||
-e "s/ARDUINOJSON_VERSION_MAJOR .*$/ARDUINOJSON_VERSION_MAJOR $MAJOR/" \
|
||||
-e "s/ARDUINOJSON_VERSION_MINOR .*$/ARDUINOJSON_VERSION_MINOR $MINOR/" \
|
||||
-e "s/ARDUINOJSON_VERSION_REVISION .*$/ARDUINOJSON_VERSION_REVISION $REVISION/" \
|
||||
src/ArduinoJson/version.hpp
|
||||
rm src/ArduinoJson/version.hpp*~
|
||||
}
|
||||
|
||||
commit_new_version () {
|
||||
git add src/ArduinoJson/version.hpp CHANGELOG.md library.json library.properties
|
||||
git commit -m "Set version to $VERSION"
|
||||
}
|
||||
|
||||
add_tag () {
|
||||
CHANGES=$(awk '/\* /{ FOUND=1; print; next } { if (FOUND) exit}' CHANGELOG.md)
|
||||
git tag -m "ArduinoJson $VERSION"$'\n'"$CHANGES" "$TAG"
|
||||
}
|
||||
|
||||
push () {
|
||||
git push --follow-tags
|
||||
}
|
||||
|
||||
update_version_in_source
|
||||
commit_new_version
|
||||
add_tag
|
||||
push
|
@ -4,18 +4,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ArduinoJson/version.hpp"
|
||||
|
||||
#include "ArduinoJson/DynamicJsonDocument.hpp"
|
||||
#include "ArduinoJson/StaticJsonDocument.hpp"
|
||||
|
||||
#include "ArduinoJson/JsonObjectImpl.hpp"
|
||||
#include "ArduinoJson/Namespace.hpp"
|
||||
|
||||
#include "ArduinoJson/JsonArray.hpp"
|
||||
#include "ArduinoJson/JsonDocument.hpp"
|
||||
#include "ArduinoJson/JsonObject.hpp"
|
||||
#include "ArduinoJson/JsonVariant.hpp"
|
||||
|
||||
#include "ArduinoJson/Data/VariantAsImpl.hpp"
|
||||
#include "ArduinoJson/JsonArrayImpl.hpp"
|
||||
#include "ArduinoJson/JsonArraySubscript.hpp"
|
||||
#include "ArduinoJson/JsonObjectImpl.hpp"
|
||||
#include "ArduinoJson/JsonObjectSubscript.hpp"
|
||||
#include "ArduinoJson/JsonVariantImpl.hpp"
|
||||
|
||||
@ -24,3 +23,21 @@
|
||||
#include "ArduinoJson/Json/PrettyJsonSerializer.hpp"
|
||||
#include "ArduinoJson/MsgPack/MsgPackDeserializer.hpp"
|
||||
#include "ArduinoJson/MsgPack/MsgPackSerializer.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
using ARDUINOJSON_NAMESPACE::DeserializationError;
|
||||
using ARDUINOJSON_NAMESPACE::DynamicJsonDocument;
|
||||
using ARDUINOJSON_NAMESPACE::JsonArray;
|
||||
using ARDUINOJSON_NAMESPACE::JsonArrayConst;
|
||||
using ARDUINOJSON_NAMESPACE::JsonFloat;
|
||||
using ARDUINOJSON_NAMESPACE::JsonInteger;
|
||||
using ARDUINOJSON_NAMESPACE::JsonKey;
|
||||
using ARDUINOJSON_NAMESPACE::JsonObject;
|
||||
using ARDUINOJSON_NAMESPACE::JsonObjectConst;
|
||||
using ARDUINOJSON_NAMESPACE::JsonPair;
|
||||
using ARDUINOJSON_NAMESPACE::JsonUInt;
|
||||
using ARDUINOJSON_NAMESPACE::JsonVariant;
|
||||
using ARDUINOJSON_NAMESPACE::JsonVariantConst;
|
||||
using ARDUINOJSON_NAMESPACE::serialized;
|
||||
using ARDUINOJSON_NAMESPACE::StaticJsonDocument;
|
||||
} // namespace ArduinoJson
|
||||
|
@ -4,6 +4,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define ARDUINOJSON_HAS_INT64 1
|
||||
#else
|
||||
#define ARDUINOJSON_HAS_INT64 0
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
#define ARDUINOJSON_HAS_LONG_LONG 1
|
||||
#else
|
||||
#define ARDUINOJSON_HAS_LONG_LONG 0
|
||||
#endif
|
||||
|
||||
// Small or big machine?
|
||||
#ifndef ARDUINOJSON_EMBEDDED_MODE
|
||||
#if defined(ARDUINO) || defined(__IAR_SYSTEMS_ICC__) || defined(__XC) || \
|
||||
@ -25,9 +37,6 @@
|
||||
#ifndef ARDUINOJSON_USE_LONG_LONG
|
||||
#define ARDUINOJSON_USE_LONG_LONG 0
|
||||
#endif
|
||||
#ifndef ARDUINOJSON_USE_INT64
|
||||
#define ARDUINOJSON_USE_INT64 0
|
||||
#endif
|
||||
|
||||
// Embedded systems usually don't have std::string
|
||||
#ifndef ARDUINOJSON_ENABLE_STD_STRING
|
||||
@ -44,6 +53,11 @@
|
||||
#define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10
|
||||
#endif
|
||||
|
||||
// Default capacity for DynamicJsonDocument
|
||||
#ifndef ARDUINOJSON_DEFAULT_POOL_SIZE
|
||||
#define ARDUINOJSON_DEFAULT_POOL_SIZE 1024
|
||||
#endif
|
||||
|
||||
#else // ARDUINOJSON_EMBEDDED_MODE
|
||||
|
||||
// On a computer we have plenty of memory so we can use doubles
|
||||
@ -53,22 +67,13 @@
|
||||
|
||||
// Use long long when available
|
||||
#ifndef ARDUINOJSON_USE_LONG_LONG
|
||||
#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
|
||||
#if ARDUINOJSON_HAS_LONG_LONG || ARDUINOJSON_HAS_INT64
|
||||
#define ARDUINOJSON_USE_LONG_LONG 1
|
||||
#else
|
||||
#define ARDUINOJSON_USE_LONG_LONG 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Use _int64 on old versions of Visual Studio
|
||||
#ifndef ARDUINOJSON_USE_INT64
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1700
|
||||
#define ARDUINOJSON_USE_INT64 1
|
||||
#else
|
||||
#define ARDUINOJSON_USE_INT64 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// On a computer, we can use std::string
|
||||
#ifndef ARDUINOJSON_ENABLE_STD_STRING
|
||||
#define ARDUINOJSON_ENABLE_STD_STRING 1
|
||||
@ -84,6 +89,11 @@
|
||||
#define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50
|
||||
#endif
|
||||
|
||||
// Default capacity for DynamicJsonDocument
|
||||
#ifndef ARDUINOJSON_DEFAULT_POOL_SIZE
|
||||
#define ARDUINOJSON_DEFAULT_POOL_SIZE 16384
|
||||
#endif
|
||||
|
||||
#endif // ARDUINOJSON_EMBEDDED_MODE
|
||||
|
||||
#ifdef ARDUINO
|
||||
@ -141,10 +151,6 @@
|
||||
#define ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 1e-5
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_USE_LONG_LONG && ARDUINOJSON_USE_INT64
|
||||
#error ARDUINOJSON_USE_LONG_LONG and ARDUINOJSON_USE_INT64 cannot be set together
|
||||
#endif
|
||||
|
||||
#ifndef ARDUINOJSON_LITTLE_ENDIAN
|
||||
#if defined(_MSC_VER) || \
|
||||
(defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \
|
||||
|
@ -0,0 +1,99 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "JsonVariantData.hpp"
|
||||
#include "Slot.hpp"
|
||||
#include "SlotFunctions.hpp"
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
inline JsonVariantData* arrayAdd(JsonArrayData* arr, MemoryPool* pool) {
|
||||
if (!arr) return 0;
|
||||
|
||||
Slot* slot = new (pool) Slot();
|
||||
if (!slot) return 0;
|
||||
|
||||
slot->next = 0;
|
||||
|
||||
if (arr->tail) {
|
||||
slot->prev = arr->tail;
|
||||
arr->tail->next = slot;
|
||||
arr->tail = slot;
|
||||
} else {
|
||||
slot->prev = 0;
|
||||
arr->head = slot;
|
||||
arr->tail = slot;
|
||||
}
|
||||
|
||||
return &slot->value;
|
||||
}
|
||||
|
||||
inline Slot* arrayGetSlot(const JsonArrayData* arr, size_t index) {
|
||||
if (!arr) return 0;
|
||||
return slotAdvance(arr->head, index);
|
||||
}
|
||||
|
||||
inline JsonVariantData* arrayGet(const JsonArrayData* arr, size_t index) {
|
||||
Slot* slot = arrayGetSlot(arr, index);
|
||||
return slot ? &slot->value : 0;
|
||||
}
|
||||
|
||||
inline void arrayRemove(JsonArrayData* arr, Slot* slot) {
|
||||
if (!arr || !slot) return;
|
||||
|
||||
if (slot->prev)
|
||||
slot->prev->next = slot->next;
|
||||
else
|
||||
arr->head = slot->next;
|
||||
if (slot->next)
|
||||
slot->next->prev = slot->prev;
|
||||
else
|
||||
arr->tail = slot->prev;
|
||||
}
|
||||
|
||||
inline void arrayRemove(JsonArrayData* arr, size_t index) {
|
||||
arrayRemove(arr, arrayGetSlot(arr, index));
|
||||
}
|
||||
|
||||
inline void arrayClear(JsonArrayData* arr) {
|
||||
if (!arr) return;
|
||||
arr->head = 0;
|
||||
arr->tail = 0;
|
||||
}
|
||||
|
||||
bool variantCopy(JsonVariantData*, const JsonVariantData*, MemoryPool*);
|
||||
|
||||
inline bool arrayCopy(JsonArrayData* dst, const JsonArrayData* src,
|
||||
MemoryPool* pool) {
|
||||
if (!dst || !src) return false;
|
||||
arrayClear(dst);
|
||||
for (Slot* s = src->head; s; s = s->next) {
|
||||
if (!variantCopy(arrayAdd(dst, pool), &s->value, pool)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool variantEquals(const JsonVariantData*, const JsonVariantData*);
|
||||
|
||||
inline bool arrayEquals(const JsonArrayData* a1, const JsonArrayData* a2) {
|
||||
if (a1 == a2) return true;
|
||||
if (!a1 || !a2) return false;
|
||||
Slot* s1 = a1->head;
|
||||
Slot* s2 = a2->head;
|
||||
for (;;) {
|
||||
if (s1 == s2) return true;
|
||||
if (!s1 || !s2) return false;
|
||||
if (!variantEquals(&s1->value, &s2->value)) return false;
|
||||
s1 = s1->next;
|
||||
s2 = s2->next;
|
||||
}
|
||||
}
|
||||
|
||||
inline size_t arraySize(const JsonArrayData* arr) {
|
||||
if (!arr) return 0;
|
||||
return slotSize(arr->head);
|
||||
}
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -1,17 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Polyfills/type_traits.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
class JsonVariantTag {};
|
||||
|
||||
template <typename T>
|
||||
struct IsVariant : is_base_of<JsonVariantTag, T> {};
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
@ -6,13 +6,11 @@
|
||||
|
||||
#include "../Configuration.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
#if ARDUINOJSON_USE_DOUBLE
|
||||
typedef double JsonFloat;
|
||||
#else
|
||||
typedef float JsonFloat;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -6,18 +6,15 @@
|
||||
|
||||
#include "../Configuration.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
#include <stdint.h> // int64_t
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
typedef long long JsonInteger;
|
||||
typedef unsigned long long JsonUInt;
|
||||
#elif ARDUINOJSON_USE_INT64
|
||||
typedef __int64 JsonInteger;
|
||||
typedef unsigned _int64 JsonUInt;
|
||||
typedef int64_t JsonInteger;
|
||||
typedef uint64_t JsonUInt;
|
||||
#else
|
||||
typedef long JsonInteger;
|
||||
typedef unsigned long JsonUInt;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -4,8 +4,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class JsonArray;
|
||||
class JsonArrayConst;
|
||||
class JsonObject;
|
||||
class JsonObjectConst;
|
||||
class JsonVariant;
|
||||
class JsonVariantConst;
|
||||
|
||||
// A metafunction that returns the type of the value returned by
|
||||
// JsonVariant::as<T>()
|
||||
@ -19,5 +25,25 @@ struct JsonVariantAs<char*> {
|
||||
typedef const char* type;
|
||||
};
|
||||
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
||||
// A metafunction that returns the type of the value returned by
|
||||
// JsonVariant::as<T>()
|
||||
template <typename T>
|
||||
struct JsonVariantConstAs {
|
||||
typedef typename JsonVariantAs<T>::type type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct JsonVariantConstAs<JsonVariant> {
|
||||
typedef JsonVariantConst type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct JsonVariantConstAs<JsonObject> {
|
||||
typedef JsonObjectConst type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct JsonVariantConstAs<JsonArray> {
|
||||
typedef JsonArrayConst type;
|
||||
};
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -1,30 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "JsonFloat.hpp"
|
||||
#include "JsonInteger.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
// Forward declarations
|
||||
struct JsonArrayData;
|
||||
struct JsonObjectData;
|
||||
|
||||
// A union that defines the actual content of a JsonVariant.
|
||||
// The enum JsonVariantType determines which member is in use.
|
||||
union JsonVariantContent {
|
||||
JsonFloat asFloat; // used for double and float
|
||||
JsonUInt asInteger; // used for bool, char, short, int and longs
|
||||
JsonArrayData* asArray; // asArray cannot be null
|
||||
JsonObjectData* asObject; // asObject cannot be null
|
||||
const char* asString; // asString can be null
|
||||
struct {
|
||||
const char* data;
|
||||
size_t size;
|
||||
} asRaw;
|
||||
};
|
||||
} // namespace Internals
|
||||
} // namespace ArduinoJson
|
@ -0,0 +1,79 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h> // ptrdiff_t, size_t
|
||||
|
||||
#include "JsonFloat.hpp"
|
||||
#include "JsonInteger.hpp"
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
enum JsonVariantType {
|
||||
JSON_NULL,
|
||||
JSON_LINKED_RAW,
|
||||
JSON_OWNED_RAW,
|
||||
JSON_LINKED_STRING,
|
||||
JSON_OWNED_STRING,
|
||||
JSON_BOOLEAN,
|
||||
JSON_POSITIVE_INTEGER,
|
||||
JSON_NEGATIVE_INTEGER,
|
||||
JSON_ARRAY,
|
||||
JSON_OBJECT,
|
||||
JSON_FLOAT
|
||||
};
|
||||
|
||||
struct JsonObjectData {
|
||||
struct Slot *head;
|
||||
struct Slot *tail;
|
||||
};
|
||||
|
||||
struct JsonArrayData {
|
||||
struct Slot *head;
|
||||
struct Slot *tail;
|
||||
};
|
||||
|
||||
struct RawData {
|
||||
const char *data;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
// A union that defines the actual content of a JsonVariantData.
|
||||
// The enum JsonVariantType determines which member is in use.
|
||||
union JsonVariantContent {
|
||||
JsonFloat asFloat;
|
||||
JsonUInt asInteger;
|
||||
JsonArrayData asArray;
|
||||
JsonObjectData asObject;
|
||||
const char *asString;
|
||||
struct {
|
||||
const char *data;
|
||||
size_t size;
|
||||
} asRaw;
|
||||
};
|
||||
|
||||
// this struct must be a POD type to prevent error calling offsetof on clang
|
||||
struct JsonVariantData {
|
||||
bool keyIsStatic : 1;
|
||||
JsonVariantType type : 7;
|
||||
JsonVariantContent content;
|
||||
};
|
||||
|
||||
inline JsonVariantData *getVariantData(JsonArrayData *arr) {
|
||||
const ptrdiff_t offset = offsetof(JsonVariantData, content) -
|
||||
offsetof(JsonVariantContent, asArray);
|
||||
if (!arr) return 0;
|
||||
return reinterpret_cast<JsonVariantData *>(reinterpret_cast<char *>(arr) -
|
||||
offset);
|
||||
}
|
||||
|
||||
inline JsonVariantData *getVariantData(JsonObjectData *obj) {
|
||||
const ptrdiff_t offset = offsetof(JsonVariantData, content) -
|
||||
offsetof(JsonVariantContent, asObject);
|
||||
if (!obj) return 0;
|
||||
return reinterpret_cast<JsonVariantData *>(reinterpret_cast<char *>(obj) -
|
||||
offset);
|
||||
}
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -1,23 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
template <typename T>
|
||||
struct JsonVariantDefault {
|
||||
static T get() {
|
||||
return T();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct JsonVariantDefault<const T> : JsonVariantDefault<T> {};
|
||||
|
||||
template <typename T>
|
||||
struct JsonVariantDefault<T&> : JsonVariantDefault<T> {};
|
||||
}
|
||||
}
|
30
libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantTo.hpp
Normal file
30
libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantTo.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
class JsonArray;
|
||||
class JsonObject;
|
||||
class JsonVariant;
|
||||
|
||||
// A metafunction that returns the type of the value returned by
|
||||
// JsonVariant::to<T>()
|
||||
template <typename T>
|
||||
struct JsonVariantTo {};
|
||||
|
||||
template <>
|
||||
struct JsonVariantTo<JsonArray> {
|
||||
typedef JsonArray type;
|
||||
};
|
||||
template <>
|
||||
struct JsonVariantTo<JsonObject> {
|
||||
typedef JsonObject type;
|
||||
};
|
||||
template <>
|
||||
struct JsonVariantTo<JsonVariant> {
|
||||
typedef JsonVariant type;
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user