初始化提交
This commit is contained in:
@@ -0,0 +1,239 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_ALIGENIE_AIRCONDITION
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
bool oState = false;
|
||||
bool hsState = false;
|
||||
bool vsState = false;
|
||||
String setLevel = "auto";
|
||||
uint8_t setTemp = 26;
|
||||
|
||||
void aligenieTemp(uint8_t temp)
|
||||
{
|
||||
BLINKER_LOG("need set temp: ", temp);
|
||||
|
||||
setTemp = temp;
|
||||
|
||||
BlinkerAliGenie.temp(temp);
|
||||
BlinkerAliGenie.print();
|
||||
}
|
||||
|
||||
void aligenieRelativeTemp(uint8_t relTemp)
|
||||
{
|
||||
BLINKER_LOG("need set temp: ", relTemp);
|
||||
|
||||
setTemp = setTemp + relTemp;
|
||||
|
||||
BlinkerAliGenie.temp(setTemp);
|
||||
BlinkerAliGenie.print();
|
||||
}
|
||||
|
||||
void aligenieLevel(const String & level)
|
||||
{
|
||||
BLINKER_LOG("need set level: ", level);
|
||||
// auto 自动风
|
||||
// low 低风
|
||||
// medium 中风
|
||||
// high 高风
|
||||
|
||||
setLevel = level;
|
||||
|
||||
BlinkerAliGenie.level(level);
|
||||
BlinkerAliGenie.print();
|
||||
}
|
||||
|
||||
void aligenieHSwingState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set HSwing state: ", state);
|
||||
// horizontal-swing
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerAliGenie.hswing("on");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
hsState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerAliGenie.hswing("off");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
hsState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void aligenieVSwingState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set VSwing state: ", state);
|
||||
// vertical-swing
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerAliGenie.vswing("on");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
vsState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerAliGenie.vswing("off");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
vsState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void aligenieMode(const String & mode)
|
||||
{
|
||||
BLINKER_LOG("need set mode: ", mode);
|
||||
|
||||
BlinkerAliGenie.mode(mode);
|
||||
BlinkerAliGenie.print();
|
||||
}
|
||||
|
||||
void aligeniePowerState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerAliGenie.powerState("on");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
oState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerAliGenie.powerState("off");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
oState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void aligenieQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("AliGenie Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_ALL_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query All");
|
||||
BlinkerAliGenie.powerState(oState ? "on" : "off");
|
||||
BlinkerAliGenie.hswing(hsState ? "on" : "off");
|
||||
BlinkerAliGenie.vswing(vsState ? "on" : "off");
|
||||
BlinkerAliGenie.level(setLevel);
|
||||
BlinkerAliGenie.mode("quietWind");
|
||||
BlinkerAliGenie.temp(setTemp);
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query Power State");
|
||||
BlinkerAliGenie.powerState(oState ? "on" : "off");
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerAliGenie.powerState(oState ? "on" : "off");
|
||||
BlinkerAliGenie.hswing(hsState ? "on" : "off");
|
||||
BlinkerAliGenie.vswing(vsState ? "on" : "off");
|
||||
BlinkerAliGenie.level(setLevel);
|
||||
BlinkerAliGenie.mode("quietWind");
|
||||
BlinkerAliGenie.temp(setTemp);
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerAliGenie.attachPowerState(aligeniePowerState);
|
||||
BlinkerAliGenie.attachHSwing(aligenieHSwingState);
|
||||
BlinkerAliGenie.attachVSwing(aligenieVSwingState);
|
||||
BlinkerAliGenie.attachLevel(aligenieLevel);
|
||||
BlinkerAliGenie.attachMode(aligenieMode);
|
||||
BlinkerAliGenie.attachTemp(aligenieTemp);
|
||||
BlinkerAliGenie.attachRelativeTemp(aligenieRelativeTemp);
|
||||
BlinkerAliGenie.attachQuery(aligenieQuery);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_ALIGENIE_FAN
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
bool oState = false;
|
||||
bool hsState = false;
|
||||
bool vsState = false;
|
||||
uint8_t setLevel;
|
||||
|
||||
void aligenieLevel(uint8_t level)
|
||||
{
|
||||
BLINKER_LOG("need set level: ", level);
|
||||
// 0:AUTO MODE, 1-3 LEVEL
|
||||
|
||||
setLevel = level;
|
||||
|
||||
BlinkerAliGenie.level(level);
|
||||
BlinkerAliGenie.print();
|
||||
}
|
||||
|
||||
void aligenieHSwingState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set HSwing state: ", state);
|
||||
// horizontal-swing
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerAliGenie.hswing("on");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
hsState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerAliGenie.hswing("off");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
hsState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void aligenieVSwingState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set VSwing state: ", state);
|
||||
// vertical-swing
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerAliGenie.vswing("on");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
vsState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerAliGenie.vswing("off");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
vsState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void aligenieMode(const String & mode)
|
||||
{
|
||||
BLINKER_LOG("need set mode: ", mode);
|
||||
|
||||
BlinkerAliGenie.mode(mode);
|
||||
BlinkerAliGenie.print();
|
||||
}
|
||||
|
||||
void aligeniePowerState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerAliGenie.powerState("on");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
oState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerAliGenie.powerState("off");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
oState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void aligenieQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("AliGenie Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_ALL_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query All");
|
||||
BlinkerAliGenie.powerState(oState ? "on" : "off");
|
||||
BlinkerAliGenie.hswing(hsState ? "on" : "off");
|
||||
BlinkerAliGenie.vswing(vsState ? "on" : "off");
|
||||
BlinkerAliGenie.level(setLevel);
|
||||
BlinkerAliGenie.mode("quietWind");
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query Power State");
|
||||
BlinkerAliGenie.powerState(oState ? "on" : "off");
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerAliGenie.powerState(oState ? "on" : "off");
|
||||
BlinkerAliGenie.hswing(hsState ? "on" : "off");
|
||||
BlinkerAliGenie.vswing(vsState ? "on" : "off");
|
||||
BlinkerAliGenie.level(setLevel);
|
||||
BlinkerAliGenie.mode("quietWind");
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerAliGenie.attachPowerState(aligeniePowerState);
|
||||
BlinkerAliGenie.attachHSwing(aligenieHSwingState);
|
||||
BlinkerAliGenie.attachVSwing(aligenieVSwingState);
|
||||
BlinkerAliGenie.attachLevel(aligenieLevel);
|
||||
BlinkerAliGenie.attachMode(aligenieMode);
|
||||
BlinkerAliGenie.attachQuery(aligenieQuery);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
@@ -0,0 +1,439 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_ALIGENIE_LIGHT
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
// Download Adafruit_NeoPixel library here:
|
||||
// https://github.com/adafruit/Adafruit_NeoPixel
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#define PIN 13
|
||||
#define NUMPIXELS 24
|
||||
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
#define RGB_1 "RGBKey"
|
||||
|
||||
BlinkerRGB WS2812(RGB_1);
|
||||
|
||||
uint8_t colorR, colorG, colorB, colorW;
|
||||
bool wsState;
|
||||
String wsMode = BLINKER_CMD_COMMON;
|
||||
|
||||
void pixelShow()
|
||||
{
|
||||
pixels.setBrightness(colorW);
|
||||
|
||||
for(int i = 0; i < NUMPIXELS; i++){
|
||||
pixels.setPixelColor(i, colorR, colorG, colorB);
|
||||
}
|
||||
pixels.show();
|
||||
}
|
||||
|
||||
void ws2812_callback(uint8_t r_value, uint8_t g_value, uint8_t b_value, uint8_t bright_value)
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
||||
BLINKER_LOG("R value: ", r_value);
|
||||
BLINKER_LOG("G value: ", g_value);
|
||||
BLINKER_LOG("B value: ", b_value);
|
||||
BLINKER_LOG("Rrightness value: ", bright_value);
|
||||
|
||||
colorR = r_value;
|
||||
colorG = g_value;
|
||||
colorB = b_value;
|
||||
colorW = bright_value;
|
||||
|
||||
pixelShow();
|
||||
}
|
||||
|
||||
String getColor()
|
||||
{
|
||||
uint32_t color = colorR << 16 | colorG << 8 | colorB;
|
||||
|
||||
switch (color)
|
||||
{
|
||||
case 0xFF0000 :
|
||||
return "Red";
|
||||
case 0xFFFF00 :
|
||||
return "Yellow";
|
||||
case 0x0000FF :
|
||||
return "Blue";
|
||||
case 0x00FF00 :
|
||||
return "Green";
|
||||
case 0xFFFFFF :
|
||||
return "White";
|
||||
case 0x000000 :
|
||||
return "Black";
|
||||
case 0x00FFFF :
|
||||
return "Cyan";
|
||||
case 0x800080 :
|
||||
return "Purple";
|
||||
case 0xFFA500 :
|
||||
return "Orange";
|
||||
default :
|
||||
return "White";
|
||||
}
|
||||
}
|
||||
|
||||
void aligeniePowerState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerAliGenie.powerState("on");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
wsState = true;
|
||||
|
||||
if (colorW == 0) colorW = 255;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerAliGenie.powerState("off");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
wsState = false;
|
||||
|
||||
colorW == 0;
|
||||
}
|
||||
|
||||
pixelShow();
|
||||
}
|
||||
|
||||
void aligenieColor(const String & color)
|
||||
{
|
||||
BLINKER_LOG("need set color: ", color);
|
||||
|
||||
if (color == "Red") {
|
||||
colorR = 255;
|
||||
colorG = 0;
|
||||
colorB = 0;
|
||||
}
|
||||
else if (color == "Yellow") {
|
||||
colorR = 255;
|
||||
colorG = 255;
|
||||
colorB = 0;
|
||||
}
|
||||
else if (color == "Blue") {
|
||||
colorR = 0;
|
||||
colorG = 0;
|
||||
colorB = 255;
|
||||
}
|
||||
else if (color == "Green") {
|
||||
colorR = 0;
|
||||
colorG = 255;
|
||||
colorB = 0;
|
||||
}
|
||||
else if (color == "White") {
|
||||
colorR = 255;
|
||||
colorG = 255;
|
||||
colorB = 255;
|
||||
}
|
||||
else if (color == "Black") {
|
||||
colorR = 0;
|
||||
colorG = 0;
|
||||
colorB = 0;
|
||||
}
|
||||
else if (color == "Cyan") {
|
||||
colorR = 0;
|
||||
colorG = 255;
|
||||
colorB = 255;
|
||||
}
|
||||
else if (color == "Purple") {
|
||||
colorR = 128;
|
||||
colorG = 0;
|
||||
colorB = 128;
|
||||
}
|
||||
else if (color == "Orange") {
|
||||
colorR = 255;
|
||||
colorG = 165;
|
||||
colorB = 0;
|
||||
}
|
||||
|
||||
if (wsState == false) {
|
||||
wsState = true;
|
||||
colorW = 255;
|
||||
}
|
||||
|
||||
if (colorW == 0) {
|
||||
colorW = 255;
|
||||
}
|
||||
|
||||
pixelShow();
|
||||
|
||||
BlinkerAliGenie.color(color);
|
||||
BlinkerAliGenie.print();
|
||||
}
|
||||
|
||||
void aligenieMode(const String & mode)
|
||||
{
|
||||
BLINKER_LOG("need set mode: ", mode);
|
||||
|
||||
if (mode == BLINKER_CMD_ALIGENIE_READING) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (mode == BLINKER_CMD_ALIGENIE_MOVIE) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (mode == BLINKER_CMD_ALIGENIE_SLEEP) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (mode == BLINKER_CMD_ALIGENIE_HOLIDAY) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (mode == BLINKER_CMD_ALIGENIE_MUSIC) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (mode == BLINKER_CMD_ALIGENIE_COMMON) {
|
||||
// Your mode function
|
||||
}
|
||||
|
||||
wsMode = mode;
|
||||
|
||||
BlinkerAliGenie.mode(mode);
|
||||
BlinkerAliGenie.print();
|
||||
}
|
||||
|
||||
void aligeniecMode(const String & cmode)
|
||||
{
|
||||
BLINKER_LOG("need cancel mode: ", cmode);
|
||||
|
||||
if (cmode == BLINKER_CMD_ALIGENIE_READING) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (cmode == BLINKER_CMD_ALIGENIE_MOVIE) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (cmode == BLINKER_CMD_ALIGENIE_SLEEP) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (cmode == BLINKER_CMD_ALIGENIE_HOLIDAY) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (cmode == BLINKER_CMD_ALIGENIE_MUSIC) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (cmode == BLINKER_CMD_ALIGENIE_COMMON) {
|
||||
// Your mode function
|
||||
}
|
||||
|
||||
wsMode = BLINKER_CMD_COMMON; // new mode
|
||||
|
||||
BlinkerAliGenie.mode(wsMode); // must response
|
||||
BlinkerAliGenie.print();
|
||||
}
|
||||
|
||||
void aligenieBright(const String & bright)
|
||||
{
|
||||
BLINKER_LOG("need set brightness: ", bright);
|
||||
|
||||
if (bright == BLINKER_CMD_MAX) {
|
||||
colorW = 255;
|
||||
}
|
||||
else if (bright == BLINKER_CMD_MIN) {
|
||||
colorW = 0;
|
||||
}
|
||||
else {
|
||||
colorW = bright.toInt();
|
||||
}
|
||||
|
||||
BLINKER_LOG("now set brightness: ", colorW);
|
||||
|
||||
pixelShow();
|
||||
|
||||
BlinkerAliGenie.brightness(colorW);
|
||||
BlinkerAliGenie.print();
|
||||
}
|
||||
|
||||
void aligenieRelativeBright(int32_t bright)
|
||||
{
|
||||
BLINKER_LOG("need set relative brightness: ", bright);
|
||||
|
||||
if (colorW + bright < 255 && colorW + bright >= 0) {
|
||||
colorW += bright;
|
||||
}
|
||||
|
||||
BLINKER_LOG("now set brightness: ", colorW);
|
||||
|
||||
pixelShow();
|
||||
|
||||
BlinkerAliGenie.brightness(bright);
|
||||
BlinkerAliGenie.print();
|
||||
}
|
||||
|
||||
void aligenieColoTemp(int32_t colorTemp)
|
||||
{
|
||||
BLINKER_LOG("need set colorTemperature: ", colorTemp);
|
||||
|
||||
BlinkerAliGenie.colorTemp(colorTemp);
|
||||
BlinkerAliGenie.print();
|
||||
}
|
||||
|
||||
void aligenieRelativeColoTemp(int32_t colorTemp)
|
||||
{
|
||||
BLINKER_LOG("need set relative colorTemperature: ", colorTemp);
|
||||
|
||||
BlinkerAliGenie.colorTemp(colorTemp);
|
||||
BlinkerAliGenie.print();
|
||||
}
|
||||
|
||||
void aligenieQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("AliGenie Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_ALL_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query All");
|
||||
BlinkerAliGenie.powerState(wsState ? "on" : "off");
|
||||
BlinkerAliGenie.color(getColor());
|
||||
BlinkerAliGenie.mode(wsMode);
|
||||
BlinkerAliGenie.colorTemp(50);
|
||||
BlinkerAliGenie.brightness(colorW);
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query Power State");
|
||||
BlinkerAliGenie.powerState(wsState ? "on" : "off");
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_COLOR_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query Color");
|
||||
BlinkerAliGenie.color(getColor());
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_MODE_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query Mode");
|
||||
BlinkerAliGenie.mode(wsMode);
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_COLORTEMP_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query ColorTemperature");
|
||||
BlinkerAliGenie.colorTemp(50);
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_BRIGHTNESS_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query Brightness");
|
||||
BlinkerAliGenie.brightness(colorW);
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerAliGenie.powerState(wsState ? "on" : "off");
|
||||
BlinkerAliGenie.color(getColor());
|
||||
BlinkerAliGenie.mode(wsMode);
|
||||
BlinkerAliGenie.colorTemp(50);
|
||||
BlinkerAliGenie.brightness(colorW);
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerAliGenie.attachPowerState(aligeniePowerState);
|
||||
BlinkerAliGenie.attachColor(aligenieColor);
|
||||
BlinkerAliGenie.attachMode(aligenieMode);
|
||||
BlinkerAliGenie.attachCancelMode(aligeniecMode);
|
||||
BlinkerAliGenie.attachBrightness(aligenieBright);
|
||||
BlinkerAliGenie.attachRelativeBrightness(aligenieRelativeBright);
|
||||
BlinkerAliGenie.attachColorTemperature(aligenieColoTemp);
|
||||
BlinkerAliGenie.attachRelativeColorTemperature(aligenieRelativeColoTemp);
|
||||
BlinkerAliGenie.attachQuery(aligenieQuery);
|
||||
|
||||
pinMode(14, OUTPUT);
|
||||
digitalWrite(14, HIGH);
|
||||
pinMode(15, OUTPUT);
|
||||
digitalWrite(15, HIGH);
|
||||
|
||||
colorR = 255;
|
||||
colorG = 255;
|
||||
colorB = 255;
|
||||
colorW = 0;
|
||||
wsState = true;
|
||||
|
||||
pixels.begin();
|
||||
pixels.setBrightness(colorW);
|
||||
WS2812.attach(ws2812_callback);
|
||||
pixelShow();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
|
||||
for(int i = 0; i < NUMPIXELS; i++){
|
||||
pixels.setPixelColor(i, colorR, colorG, colorB);
|
||||
}
|
||||
pixels.show();
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_ALIGENIE_MULTI_OUTLET
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
bool oState[5] = { false };
|
||||
|
||||
void aligeniePowerState(const String & state, uint8_t num)
|
||||
{
|
||||
BLINKER_LOG("need set outlet: ", num, ", power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerAliGenie.powerState("on", num);
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
oState[num] = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerAliGenie.powerState("off", num);
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
oState[num] = true;
|
||||
|
||||
if (num == 0)
|
||||
{
|
||||
for (uint8_t o_num = 0; o_num < 5; o_num++)
|
||||
{
|
||||
oState[o_num] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void aligenieQuery(int32_t queryCode, uint8_t num)
|
||||
{
|
||||
BLINKER_LOG("AliGenie Query outlet: ", num,", codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_ALL_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query All");
|
||||
BlinkerAliGenie.powerState(oState[num] ? "on" : "off", num);
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query Power State");
|
||||
BlinkerAliGenie.powerState(oState[num] ? "on" : "off", num);
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerAliGenie.powerState(oState[num] ? "on" : "off", num);
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerAliGenie.attachPowerState(aligeniePowerState);
|
||||
BlinkerAliGenie.attachQuery(aligenieQuery);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_ALIGENIE_OUTLET
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
bool oState = false;
|
||||
|
||||
void aligeniePowerState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerAliGenie.powerState("on");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
oState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerAliGenie.powerState("off");
|
||||
BlinkerAliGenie.print();
|
||||
|
||||
oState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void aligenieQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("AliGenie Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_ALL_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query All");
|
||||
BlinkerAliGenie.powerState(oState ? "on" : "off");
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query Power State");
|
||||
BlinkerAliGenie.powerState(oState ? "on" : "off");
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerAliGenie.powerState(oState ? "on" : "off");
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerAliGenie.attachPowerState(aligeniePowerState);
|
||||
BlinkerAliGenie.attachQuery(aligenieQuery);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_ALIGENIE_SENSOR
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
void aligenieQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("AliGenie Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_ALL_NUMBER :
|
||||
BLINKER_LOG("AliGenie Query All");
|
||||
BlinkerAliGenie.temp(20);
|
||||
BlinkerAliGenie.humi(20);
|
||||
BlinkerAliGenie.pm25(20);
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerAliGenie.temp(20);
|
||||
BlinkerAliGenie.humi(20);
|
||||
BlinkerAliGenie.pm25(20);
|
||||
BlinkerAliGenie.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerAliGenie.attachQuery(aligenieQuery);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_DUEROS_AIRCONDITION
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
#define BUTTON_1 "ButtonKey"
|
||||
|
||||
BlinkerButton Button1(BUTTON_1);
|
||||
|
||||
bool oState = false;
|
||||
bool hsState = false;
|
||||
bool vsState = false;
|
||||
uint8_t setLevel;
|
||||
uint8_t setTemp;
|
||||
String wsMode = "AUTO";
|
||||
|
||||
void duerLevel(uint8_t level)
|
||||
{
|
||||
BLINKER_LOG("need set level: ", level);
|
||||
// 0:AUTO MODE, 1-3 LEVEL
|
||||
|
||||
setLevel = level;
|
||||
|
||||
BlinkerDuerOS.level(level);
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void duerRelativeLevel(int32_t level)
|
||||
{
|
||||
BLINKER_LOG("need set relative level: ", level);
|
||||
// 0:AUTO MODE, 1-3 LEVEL
|
||||
|
||||
setLevel += level;
|
||||
|
||||
BlinkerDuerOS.level(setLevel);
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void duerTemp(uint8_t temp)
|
||||
{
|
||||
BLINKER_LOG("need set temp: ", temp);
|
||||
|
||||
setTemp = temp;
|
||||
|
||||
BlinkerDuerOS.temp(temp);
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void duerRelativeTemp(int32_t temp)
|
||||
{
|
||||
BLINKER_LOG("need set relative temp: ", temp);
|
||||
|
||||
setTemp += temp;
|
||||
|
||||
BlinkerDuerOS.temp(setTemp);
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void duerMode(const String & mode)
|
||||
{
|
||||
BLINKER_LOG("need set mode: ", mode);
|
||||
// COOL:制冷
|
||||
// HEAT:制热
|
||||
// AUTO:自动
|
||||
// FAN:送风
|
||||
// DEHUMIDIFICATION:除湿
|
||||
// SLEEP:睡眠
|
||||
// CLEAN:净化
|
||||
// NAI:负离子
|
||||
// NO_WIND_FEELING: 无风感
|
||||
// NO_UP_WIND_FEELING: 上无风感
|
||||
// NO_DOWN_WIND_FEELING: 下无风感
|
||||
// UP_DOWN_SWING: 上下摆风
|
||||
// LEFT_RIGHT_SWING: 左右摆风
|
||||
|
||||
wsMode = mode;
|
||||
|
||||
BlinkerDuerOS.mode(mode);
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void button1_callback(const String & state)
|
||||
{
|
||||
BLINKER_LOG("get button state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
BLINKER_LOG("Toggle on!");
|
||||
|
||||
Button1.icon("icon_1");
|
||||
Button1.color("#FFFFFF");
|
||||
Button1.text("Your button name or describe");
|
||||
Button1.print("on");
|
||||
|
||||
oState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
BLINKER_LOG("Toggle off!");
|
||||
|
||||
Button1.icon("icon_1");
|
||||
Button1.color("#FFFFFF");
|
||||
Button1.text("Your button name or describe");
|
||||
Button1.print("off");
|
||||
|
||||
oState = false;
|
||||
}
|
||||
|
||||
BlinkerDuerOS.powerState(oState ? "on" : "off");
|
||||
BlinkerDuerOS.report();
|
||||
|
||||
digitalWrite(LED_BUILTIN, oState);
|
||||
}
|
||||
|
||||
void duerPowerState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerDuerOS.powerState("on");
|
||||
BlinkerDuerOS.print();
|
||||
|
||||
oState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerDuerOS.powerState("off");
|
||||
BlinkerDuerOS.print();
|
||||
|
||||
oState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void duerQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("DuerOS Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
|
||||
BLINKER_LOG("DuerOS Query power state");
|
||||
BlinkerDuerOS.powerState(oState ? "on" : "off");
|
||||
BlinkerDuerOS.level(setLevel);
|
||||
BlinkerDuerOS.temp(setTemp);
|
||||
BlinkerDuerOS.mode(wsMode);
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_TIME_NUMBER :
|
||||
BLINKER_LOG("DuerOS Query time");
|
||||
BlinkerDuerOS.time(millis());
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerDuerOS.powerState(oState ? "on" : "off");
|
||||
BlinkerDuerOS.level(setLevel);
|
||||
BlinkerDuerOS.temp(setTemp);
|
||||
BlinkerDuerOS.mode(wsMode);
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
// Blinker.vibrate();
|
||||
|
||||
// uint32_t BlinkerTime = millis();
|
||||
|
||||
// Blinker.print("millis", BlinkerTime);
|
||||
|
||||
BlinkerDuerOS.powerState("off");
|
||||
BlinkerDuerOS.report();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
BLINKER_DEBUG.debugAll();
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerDuerOS.attachPowerState(duerPowerState);
|
||||
BlinkerDuerOS.attachLevel(duerLevel);
|
||||
BlinkerDuerOS.attachRelativeLevel(duerRelativeLevel);
|
||||
BlinkerDuerOS.attachTemp(duerTemp);
|
||||
BlinkerDuerOS.attachRelativeTemp(duerRelativeTemp);
|
||||
BlinkerDuerOS.attachMode(duerMode);
|
||||
BlinkerDuerOS.attachQuery(duerQuery);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_DUEROS_FAN
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
#define BUTTON_1 "ButtonKey"
|
||||
|
||||
BlinkerButton Button1(BUTTON_1);
|
||||
|
||||
bool oState = false;
|
||||
bool hsState = false;
|
||||
bool vsState = false;
|
||||
uint8_t setLevel;
|
||||
String wsMode = "NIGHT";
|
||||
|
||||
void duerLevel(uint8_t level)
|
||||
{
|
||||
BLINKER_LOG("need set level: ", level);
|
||||
// 0:AUTO MODE, 1-3 LEVEL
|
||||
|
||||
setLevel = level;
|
||||
|
||||
BlinkerDuerOS.level(level);
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void duerRelativeLevel(int32_t level)
|
||||
{
|
||||
BLINKER_LOG("need set relative level: ", level);
|
||||
// 0:AUTO MODE, 1-3 LEVEL
|
||||
|
||||
setLevel += level;
|
||||
|
||||
BlinkerDuerOS.level(setLevel);
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void duerMode(const String & mode)
|
||||
{
|
||||
BLINKER_LOG("need set mode: ", mode);
|
||||
// NIGHT:夜间
|
||||
// SWING:摆动/摆风
|
||||
// SINGLE:单人
|
||||
// MULTI:多人
|
||||
// SPURT:喷射
|
||||
// SPREAD:扩散
|
||||
// QUIET:安静
|
||||
// NORMAL:正常风速/适中风速/一般风速
|
||||
// POWERFUL:强效
|
||||
// MUTE:静音风速
|
||||
// NATURAL:自然风速
|
||||
// BABY:无感风速/轻微风速
|
||||
// COMFORTABLE:舒适风速
|
||||
// FEEL:人感风速
|
||||
|
||||
wsMode = mode;
|
||||
|
||||
BlinkerDuerOS.mode(mode);
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void button1_callback(const String & state)
|
||||
{
|
||||
BLINKER_LOG("get button state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
BLINKER_LOG("Toggle on!");
|
||||
|
||||
Button1.icon("icon_1");
|
||||
Button1.color("#FFFFFF");
|
||||
Button1.text("Your button name or describe");
|
||||
Button1.print("on");
|
||||
|
||||
oState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
BLINKER_LOG("Toggle off!");
|
||||
|
||||
Button1.icon("icon_1");
|
||||
Button1.color("#FFFFFF");
|
||||
Button1.text("Your button name or describe");
|
||||
Button1.print("off");
|
||||
|
||||
oState = false;
|
||||
}
|
||||
|
||||
BlinkerDuerOS.powerState(oState ? "on" : "off");
|
||||
BlinkerDuerOS.report();
|
||||
|
||||
digitalWrite(LED_BUILTIN, oState);
|
||||
}
|
||||
|
||||
void duerPowerState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerDuerOS.powerState("on");
|
||||
BlinkerDuerOS.print();
|
||||
|
||||
oState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerDuerOS.powerState("off");
|
||||
BlinkerDuerOS.print();
|
||||
|
||||
oState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void duerQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("DuerOS Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
|
||||
BLINKER_LOG("DuerOS Query power state");
|
||||
BlinkerDuerOS.powerState(oState ? "on" : "off");
|
||||
BlinkerDuerOS.level(setLevel);
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_TIME_NUMBER :
|
||||
BLINKER_LOG("DuerOS Query time");
|
||||
BlinkerDuerOS.time(millis());
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerDuerOS.powerState(oState ? "on" : "off");
|
||||
BlinkerDuerOS.level(setLevel);
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
// Blinker.vibrate();
|
||||
|
||||
// uint32_t BlinkerTime = millis();
|
||||
|
||||
// Blinker.print("millis", BlinkerTime);
|
||||
|
||||
BlinkerDuerOS.powerState("off");
|
||||
BlinkerDuerOS.report();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
BLINKER_DEBUG.debugAll();
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerDuerOS.attachPowerState(duerPowerState);
|
||||
BlinkerDuerOS.attachLevel(duerLevel);
|
||||
BlinkerDuerOS.attachRelativeLevel(duerRelativeLevel);
|
||||
BlinkerDuerOS.attachMode(duerMode);
|
||||
BlinkerDuerOS.attachQuery(duerQuery);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_DUEROS_LIGHT
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
// Download Adafruit_NeoPixel library here:
|
||||
// https://github.com/adafruit/Adafruit_NeoPixel
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#define PIN 13
|
||||
#define NUMPIXELS 24
|
||||
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
#define RGB_1 "RGBKey"
|
||||
|
||||
BlinkerRGB WS2812(RGB_1);
|
||||
|
||||
uint8_t colorR, colorG, colorB, colorW;
|
||||
bool wsState;
|
||||
String wsMode = BLINKER_CMD_COMMON;
|
||||
|
||||
void pixelShow()
|
||||
{
|
||||
pixels.setBrightness(colorW);
|
||||
|
||||
for(int i = 0; i < NUMPIXELS; i++){
|
||||
pixels.setPixelColor(i, colorR, colorG, colorB);
|
||||
}
|
||||
pixels.show();
|
||||
}
|
||||
|
||||
void ws2812_callback(uint8_t r_value, uint8_t g_value, uint8_t b_value, uint8_t bright_value)
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
||||
BLINKER_LOG("R value: ", r_value);
|
||||
BLINKER_LOG("G value: ", g_value);
|
||||
BLINKER_LOG("B value: ", b_value);
|
||||
BLINKER_LOG("Rrightness value: ", bright_value);
|
||||
|
||||
colorR = r_value;
|
||||
colorG = g_value;
|
||||
colorB = b_value;
|
||||
colorW = bright_value;
|
||||
|
||||
pixelShow();
|
||||
}
|
||||
|
||||
String getColor()
|
||||
{
|
||||
uint32_t color = colorR << 16 | colorG << 8 | colorB;
|
||||
|
||||
switch (color)
|
||||
{
|
||||
case 0xFF0000 :
|
||||
return "Red";
|
||||
case 0xFFFF00 :
|
||||
return "Yellow";
|
||||
case 0x0000FF :
|
||||
return "Blue";
|
||||
case 0x00FF00 :
|
||||
return "Green";
|
||||
case 0xFFFFFF :
|
||||
return "White";
|
||||
case 0x000000 :
|
||||
return "Black";
|
||||
case 0x00FFFF :
|
||||
return "Cyan";
|
||||
case 0x800080 :
|
||||
return "Purple";
|
||||
case 0xFFA500 :
|
||||
return "Orange";
|
||||
default :
|
||||
return "White";
|
||||
}
|
||||
}
|
||||
|
||||
void duerPowerState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerDuerOS.powerState("on");
|
||||
BlinkerDuerOS.print();
|
||||
|
||||
wsState = true;
|
||||
|
||||
if (colorW == 0) colorW = 255;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerDuerOS.powerState("off");
|
||||
BlinkerDuerOS.print();
|
||||
|
||||
wsState = false;
|
||||
|
||||
colorW == 0;
|
||||
}
|
||||
|
||||
pixelShow();
|
||||
}
|
||||
|
||||
void duerColor(int32_t color)
|
||||
{
|
||||
BLINKER_LOG("need set color: ", color);
|
||||
|
||||
colorR = color >> 16 & 0xFF;
|
||||
colorG = color >> 8 & 0xFF;
|
||||
colorB = color & 0xFF;
|
||||
|
||||
BLINKER_LOG("colorR: ", colorR, ", colorG: ", colorG, ", colorB: ", colorB);
|
||||
|
||||
pixelShow();
|
||||
|
||||
BlinkerDuerOS.color(color);
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void duerMode(const String & mode)
|
||||
{
|
||||
BLINKER_LOG("need set mode: ", mode);
|
||||
// READING:阅读
|
||||
// SLEEP:睡眠
|
||||
// ALARM:报警
|
||||
// NIGHT_LIGHT:夜灯
|
||||
// ROMANTIC:浪漫
|
||||
// SUNDOWN:日落
|
||||
// SUNRISE:日出
|
||||
// RELAX :休闲/放松
|
||||
// LIGHTING :照明
|
||||
// SUN :太阳
|
||||
// STAR :星星
|
||||
// ENERGY_SAVING:节能
|
||||
// MOON:月亮
|
||||
// JUDI:蹦迪
|
||||
|
||||
wsMode = mode;
|
||||
|
||||
BlinkerDuerOS.mode(mode);
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void duercMode(const String & cmode)
|
||||
{
|
||||
BLINKER_LOG("need cancel mode: ", cmode);
|
||||
|
||||
wsMode = BLINKER_CMD_COMMON; // new mode
|
||||
|
||||
BlinkerDuerOS.mode(wsMode); // must response
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void duerBright(const String & bright)
|
||||
{
|
||||
BLINKER_LOG("need set brightness: ", bright);
|
||||
|
||||
if (bright == BLINKER_CMD_MAX) {
|
||||
colorW = 255;
|
||||
}
|
||||
else if (bright == BLINKER_CMD_MIN) {
|
||||
colorW = 0;
|
||||
}
|
||||
else {
|
||||
colorW = bright.toInt();
|
||||
}
|
||||
|
||||
BLINKER_LOG("now set brightness: ", colorW);
|
||||
|
||||
pixelShow();
|
||||
|
||||
BlinkerDuerOS.brightness(colorW);
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void duerRelativeBright(int32_t bright)
|
||||
{
|
||||
BLINKER_LOG("need set relative brightness: ", bright);
|
||||
|
||||
if (colorW + bright < 255 && colorW + bright >= 0) {
|
||||
colorW += bright;
|
||||
}
|
||||
|
||||
BLINKER_LOG("now set brightness: ", colorW);
|
||||
|
||||
pixelShow();
|
||||
|
||||
BlinkerDuerOS.brightness(bright);
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void duerColoTemp(int32_t colorTemp)
|
||||
{
|
||||
BLINKER_LOG("need set colorTemperature: ", colorTemp);
|
||||
|
||||
BlinkerDuerOS.colorTemp(colorTemp);
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void duerRelativeColoTemp(int32_t colorTemp)
|
||||
{
|
||||
BLINKER_LOG("need set relative colorTemperature: ", colorTemp);
|
||||
|
||||
BlinkerDuerOS.colorTemp(colorTemp);
|
||||
BlinkerDuerOS.print();
|
||||
}
|
||||
|
||||
void duerQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("DuerOS Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_TIME_NUMBER :
|
||||
BLINKER_LOG("DuerOS Query time");
|
||||
BlinkerDuerOS.time(millis());
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerDuerOS.time(millis());
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerDuerOS.attachPowerState(duerPowerState);
|
||||
BlinkerDuerOS.attachColor(duerColor);
|
||||
BlinkerDuerOS.attachMode(duerMode);
|
||||
BlinkerDuerOS.attachCancelMode(duercMode);
|
||||
BlinkerDuerOS.attachBrightness(duerBright);
|
||||
BlinkerDuerOS.attachRelativeBrightness(duerRelativeBright);
|
||||
BlinkerDuerOS.attachColorTemperature(duerColoTemp);
|
||||
BlinkerDuerOS.attachRelativeColorTemperature(duerRelativeColoTemp);
|
||||
BlinkerDuerOS.attachQuery(duerQuery);
|
||||
|
||||
pinMode(14, OUTPUT);
|
||||
digitalWrite(14, HIGH);
|
||||
pinMode(15, OUTPUT);
|
||||
digitalWrite(15, HIGH);
|
||||
|
||||
colorR = 255;
|
||||
colorG = 255;
|
||||
colorB = 255;
|
||||
colorW = 0;
|
||||
wsState = true;
|
||||
|
||||
pixels.begin();
|
||||
pixels.setBrightness(colorW);
|
||||
WS2812.attach(ws2812_callback);
|
||||
pixelShow();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
|
||||
for(int i = 0; i < NUMPIXELS; i++){
|
||||
pixels.setPixelColor(i, colorR, colorG, colorB);
|
||||
}
|
||||
pixels.show();
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_DUEROS_MULTI_OUTLET
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
bool oState[5] = { false };
|
||||
|
||||
void duerPowerState(const String & state, uint8_t num)
|
||||
{
|
||||
BLINKER_LOG("need set outlet: ", num, ", power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerDuerOS.powerState("on", num);
|
||||
BlinkerDuerOS.print();
|
||||
|
||||
oState[num] = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerDuerOS.powerState("off", num);
|
||||
BlinkerDuerOS.print();
|
||||
|
||||
oState[num] = false;
|
||||
|
||||
if (num == 0)
|
||||
{
|
||||
for (uint8_t o_num = 0; o_num < 5; o_num++)
|
||||
{
|
||||
oState[o_num] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerDuerOS.attachPowerState(duerPowerState);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_DUEROS_OUTLET
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
#define BUTTON_1 "ButtonKey"
|
||||
|
||||
BlinkerButton Button1(BUTTON_1);
|
||||
|
||||
bool oState = false;
|
||||
|
||||
void button1_callback(const String & state)
|
||||
{
|
||||
BLINKER_LOG("get button state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
BLINKER_LOG("Toggle on!");
|
||||
|
||||
Button1.icon("icon_1");
|
||||
Button1.color("#FFFFFF");
|
||||
Button1.text("Your button name or describe");
|
||||
Button1.print("on");
|
||||
|
||||
oState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
BLINKER_LOG("Toggle off!");
|
||||
|
||||
Button1.icon("icon_1");
|
||||
Button1.color("#FFFFFF");
|
||||
Button1.text("Your button name or describe");
|
||||
Button1.print("off");
|
||||
|
||||
oState = false;
|
||||
}
|
||||
|
||||
BlinkerDuerOS.powerState(oState ? "on" : "off");
|
||||
BlinkerDuerOS.report();
|
||||
|
||||
digitalWrite(LED_BUILTIN, oState);
|
||||
}
|
||||
|
||||
void duerPowerState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerDuerOS.powerState("on");
|
||||
BlinkerDuerOS.print();
|
||||
|
||||
oState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerDuerOS.powerState("off");
|
||||
BlinkerDuerOS.print();
|
||||
|
||||
oState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void duerQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("DuerOS Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
|
||||
BLINKER_LOG("DuerOS Query power state");
|
||||
BlinkerDuerOS.powerState(oState ? "on" : "off");
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_TIME_NUMBER :
|
||||
BLINKER_LOG("DuerOS Query time");
|
||||
BlinkerDuerOS.time(millis());
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerDuerOS.powerState(oState ? "on" : "off");
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
// Blinker.vibrate();
|
||||
|
||||
// uint32_t BlinkerTime = millis();
|
||||
|
||||
// Blinker.print("millis", BlinkerTime);
|
||||
|
||||
BlinkerDuerOS.powerState("off");
|
||||
BlinkerDuerOS.report();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
BLINKER_DEBUG.debugAll();
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerDuerOS.attachPowerState(duerPowerState);
|
||||
BlinkerDuerOS.attachQuery(duerQuery);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_DUEROS_SENSOR
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
void duerQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("DuerOS Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_AQI_NUMBER :
|
||||
BLINKER_LOG("DuerOS Query AQI");
|
||||
BlinkerDuerOS.aqi(20);
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_CO2_NUMBER :
|
||||
BLINKER_LOG("DuerOS Query CO2");
|
||||
BlinkerDuerOS.co2(20);
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_PM10_NUMBER :
|
||||
BLINKER_LOG("DuerOS Query PM10");
|
||||
BlinkerDuerOS.pm10(20);
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_PM25_NUMBER :
|
||||
BLINKER_LOG("DuerOS Query PM25");
|
||||
BlinkerDuerOS.pm25(20);
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_HUMI_NUMBER :
|
||||
BLINKER_LOG("DuerOS Query HUMI");
|
||||
BlinkerDuerOS.humi(20);
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_TEMP_NUMBER :
|
||||
BLINKER_LOG("DuerOS Query TEMP");
|
||||
BlinkerDuerOS.temp(20);
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_TIME_NUMBER :
|
||||
BLINKER_LOG("DuerOS Query time");
|
||||
BlinkerDuerOS.time(millis());
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerDuerOS.temp(20);
|
||||
BlinkerDuerOS.humi(20);
|
||||
BlinkerDuerOS.pm25(20);
|
||||
BlinkerDuerOS.pm10(20);
|
||||
BlinkerDuerOS.co2(20);
|
||||
BlinkerDuerOS.aqi(20);
|
||||
BlinkerDuerOS.time(millis());
|
||||
BlinkerDuerOS.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerDuerOS.attachQuery(duerQuery);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_MIOT_AIRCONDITION
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
bool oState = false;
|
||||
bool hsState = false;
|
||||
bool vsState = false;
|
||||
uint8_t setLevel;
|
||||
|
||||
void miotLevel(uint8_t level)
|
||||
{
|
||||
BLINKER_LOG("need set level: ", level);
|
||||
// 0:AUTO MODE, 1-3 LEVEL
|
||||
|
||||
setLevel = level;
|
||||
|
||||
BlinkerMIOT.level(level);
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
|
||||
void miotTemp(uint8_t temp)
|
||||
{
|
||||
BLINKER_LOG("need set temp: ", temp);
|
||||
|
||||
BlinkerMIOT.temp(temp);
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
|
||||
void miotHumi(uint8_t humi)
|
||||
{
|
||||
BLINKER_LOG("need set humi: ", humi);
|
||||
|
||||
BlinkerMIOT.humi(humi);
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
|
||||
void miotMode(const String & mode, const String & state)
|
||||
{
|
||||
// eco ECO节能模式
|
||||
// anion 负离子
|
||||
// heater 辅热功能
|
||||
// dryer 干燥功能
|
||||
// sleep 睡眠模式
|
||||
// soft 柔风功能
|
||||
// uv UV杀菌
|
||||
// unsb un-straight-blowing 防直吹
|
||||
|
||||
BLINKER_LOG("need set mode: ", mode, ", state:", state);
|
||||
|
||||
BlinkerMIOT.mode(mode, state);
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
|
||||
void miotHSwingState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set HSwing state: ", state);
|
||||
// horizontal-swing
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerMIOT.hswing("on");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
hsState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerMIOT.hswing("off");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
hsState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void miotVSwingState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set VSwing state: ", state);
|
||||
// vertical-swing
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerMIOT.vswing("on");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
vsState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerMIOT.vswing("off");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
vsState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void miotPowerState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerMIOT.powerState("on");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
oState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerMIOT.powerState("off");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
oState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void miotQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("MIOT Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_ALL_NUMBER :
|
||||
BLINKER_LOG("MIOT Query All");
|
||||
BlinkerMIOT.powerState(oState ? "on" : "off");
|
||||
BlinkerMIOT.hswing(hsState ? "on" : "off");
|
||||
BlinkerMIOT.vswing(vsState ? "on" : "off");
|
||||
BlinkerMIOT.eco("off");
|
||||
BlinkerMIOT.anion("off");
|
||||
BlinkerMIOT.heater("off");
|
||||
BlinkerMIOT.dryer("off");
|
||||
BlinkerMIOT.sleep("off");
|
||||
BlinkerMIOT.soft("off");
|
||||
BlinkerMIOT.uv("off");
|
||||
BlinkerMIOT.unStraightBlow("off");
|
||||
BlinkerMIOT.level(setLevel);
|
||||
BlinkerMIOT.temp(16);
|
||||
BlinkerMIOT.humi(20);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
|
||||
BLINKER_LOG("MIOT Query Power State");
|
||||
BlinkerMIOT.powerState(oState ? "on" : "off");
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerMIOT.powerState(oState ? "on" : "off");
|
||||
BlinkerMIOT.hswing(hsState ? "on" : "off");
|
||||
BlinkerMIOT.vswing(vsState ? "on" : "off");
|
||||
BlinkerMIOT.eco("off");
|
||||
BlinkerMIOT.anion("off");
|
||||
BlinkerMIOT.heater("off");
|
||||
BlinkerMIOT.dryer("off");
|
||||
BlinkerMIOT.sleep("off");
|
||||
BlinkerMIOT.soft("off");
|
||||
BlinkerMIOT.uv("off");
|
||||
BlinkerMIOT.unStraightBlow("off");
|
||||
BlinkerMIOT.level(setLevel);
|
||||
BlinkerMIOT.temp(16);
|
||||
BlinkerMIOT.humi(20);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerMIOT.attachPowerState(miotPowerState);
|
||||
BlinkerMIOT.attachHSwing(miotHSwingState);
|
||||
BlinkerMIOT.attachVSwing(miotVSwingState);
|
||||
BlinkerMIOT.attachLevel(miotLevel);
|
||||
BlinkerMIOT.attachMode(miotMode);
|
||||
BlinkerMIOT.attachTemp(miotTemp);
|
||||
BlinkerMIOT.attachHumi(miotHumi);
|
||||
BlinkerMIOT.attachQuery(miotQuery);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.4 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_MIOT_FAN
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
bool oState = false;
|
||||
bool hsState = false;
|
||||
bool vsState = false;
|
||||
uint8_t setLevel;
|
||||
|
||||
void miotLevel(uint8_t level)
|
||||
{
|
||||
BLINKER_LOG("need set level: ", level);
|
||||
// 0:AUTO MODE, 1-3 LEVEL
|
||||
|
||||
setLevel = level;
|
||||
|
||||
BlinkerMIOT.level(level);
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
|
||||
void miotHSwingState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set HSwing state: ", state);
|
||||
// horizontal-swing
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerMIOT.hswing("on");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
hsState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerMIOT.hswing("off");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
hsState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void miotVSwingState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set VSwing state: ", state);
|
||||
// vertical-swing
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerMIOT.vswing("on");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
vsState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerMIOT.vswing("off");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
vsState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void miotPowerState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerMIOT.powerState("on");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
oState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerMIOT.powerState("off");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
oState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void miotQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("MIOT Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_ALL_NUMBER :
|
||||
BLINKER_LOG("MIOT Query All");
|
||||
BlinkerMIOT.powerState(oState ? "on" : "off");
|
||||
BlinkerMIOT.hswing(hsState ? "on" : "off");
|
||||
BlinkerMIOT.vswing(vsState ? "on" : "off");
|
||||
BlinkerMIOT.level(setLevel);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
|
||||
BLINKER_LOG("MIOT Query Power State");
|
||||
BlinkerMIOT.powerState(oState ? "on" : "off");
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerMIOT.powerState(oState ? "on" : "off");
|
||||
BlinkerMIOT.hswing(hsState ? "on" : "off");
|
||||
BlinkerMIOT.vswing(vsState ? "on" : "off");
|
||||
BlinkerMIOT.level(setLevel);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerMIOT.attachPowerState(miotPowerState);
|
||||
BlinkerMIOT.attachHSwing(miotHSwingState);
|
||||
BlinkerMIOT.attachVSwing(miotVSwingState);
|
||||
BlinkerMIOT.attachLevel(miotLevel);
|
||||
BlinkerMIOT.attachQuery(miotQuery);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_MIOT_LIGHT
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
// Download Adafruit_NeoPixel library here:
|
||||
// https://github.com/adafruit/Adafruit_NeoPixel
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#define PIN 2
|
||||
#define NUMPIXELS 24
|
||||
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
#define RGB_1 "RGBKey"
|
||||
|
||||
BlinkerRGB WS2812(RGB_1);
|
||||
|
||||
uint8_t colorR, colorG, colorB, colorW;
|
||||
bool wsState;
|
||||
uint8_t wsMode = BLINKER_CMD_MIOT_DAY;
|
||||
|
||||
void pixelShow()
|
||||
{
|
||||
pixels.setBrightness(colorW);
|
||||
|
||||
for(int i = 0; i < NUMPIXELS; i++){
|
||||
pixels.setPixelColor(i, colorR, colorG, colorB);
|
||||
}
|
||||
pixels.show();
|
||||
}
|
||||
|
||||
void ws2812_callback(uint8_t r_value, uint8_t g_value, uint8_t b_value, uint8_t bright_value)
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
||||
BLINKER_LOG("R value: ", r_value);
|
||||
BLINKER_LOG("G value: ", g_value);
|
||||
BLINKER_LOG("B value: ", b_value);
|
||||
BLINKER_LOG("Rrightness value: ", bright_value);
|
||||
|
||||
colorR = r_value;
|
||||
colorG = g_value;
|
||||
colorB = b_value;
|
||||
colorW = bright_value;
|
||||
|
||||
pixelShow();
|
||||
}
|
||||
|
||||
uint32_t getColor()
|
||||
{
|
||||
uint32_t color = colorR << 16 | colorG << 8 | colorB;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void miotPowerState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerMIOT.powerState("on");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
wsState = true;
|
||||
|
||||
if (colorW == 0) colorW = 255;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerMIOT.powerState("off");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
wsState = false;
|
||||
|
||||
colorW = 0;
|
||||
}
|
||||
|
||||
pixelShow();
|
||||
}
|
||||
|
||||
void miotColor(int32_t color)
|
||||
{
|
||||
BLINKER_LOG("need set color: ", color);
|
||||
|
||||
colorR = color >> 16 & 0xFF;
|
||||
colorG = color >> 8 & 0xFF;
|
||||
colorB = color & 0xFF;
|
||||
|
||||
BLINKER_LOG("colorR: ", colorR, ", colorG: ", colorG, ", colorB: ", colorB);
|
||||
|
||||
pixelShow();
|
||||
|
||||
BlinkerMIOT.color(color);
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
|
||||
void miotMode(uint8_t mode)
|
||||
{
|
||||
BLINKER_LOG("need set mode: ", mode);
|
||||
|
||||
if (mode == BLINKER_CMD_MIOT_DAY) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (mode == BLINKER_CMD_MIOT_NIGHT) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (mode == BLINKER_CMD_MIOT_COLOR) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (mode == BLINKER_CMD_MIOT_WARMTH) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (mode == BLINKER_CMD_MIOT_TV) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (mode == BLINKER_CMD_MIOT_READING) {
|
||||
// Your mode function
|
||||
}
|
||||
else if (mode == BLINKER_CMD_MIOT_COMPUTER) {
|
||||
// Your mode function
|
||||
}
|
||||
|
||||
wsMode = mode;
|
||||
|
||||
BlinkerMIOT.mode(mode);
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
|
||||
void miotBright(const String & bright)
|
||||
{
|
||||
BLINKER_LOG("need set brightness: ", bright);
|
||||
|
||||
colorW = bright.toInt();
|
||||
|
||||
BLINKER_LOG("now set brightness: ", colorW);
|
||||
|
||||
pixelShow();
|
||||
|
||||
BlinkerMIOT.brightness(colorW);
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
|
||||
void miotColoTemp(int32_t colorTemp)
|
||||
{
|
||||
BLINKER_LOG("need set colorTemperature: ", colorTemp);
|
||||
|
||||
BlinkerMIOT.colorTemp(colorTemp);
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
|
||||
void miotQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("MIOT Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_ALL_NUMBER :
|
||||
BLINKER_LOG("MIOT Query All");
|
||||
BlinkerMIOT.powerState(wsState ? "on" : "off");
|
||||
BlinkerMIOT.color(0);
|
||||
BlinkerMIOT.mode(0);
|
||||
BlinkerMIOT.colorTemp(1000);
|
||||
BlinkerMIOT.brightness(1);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
|
||||
BLINKER_LOG("MIOT Query Power State");
|
||||
BlinkerMIOT.powerState(wsState ? "on" : "off");
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_COLOR_NUMBER :
|
||||
BLINKER_LOG("MIOT Query Color");
|
||||
BlinkerMIOT.color(0);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_MODE_NUMBER :
|
||||
BLINKER_LOG("MIOT Query Mode");
|
||||
BlinkerMIOT.mode(0);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_COLORTEMP_NUMBER :
|
||||
BLINKER_LOG("MIOT Query ColorTemperature");
|
||||
BlinkerMIOT.colorTemp(1000);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_BRIGHTNESS_NUMBER :
|
||||
BLINKER_LOG("MIOT Query Brightness");
|
||||
BlinkerMIOT.brightness(1);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerMIOT.powerState(wsState ? "on" : "off");
|
||||
BlinkerMIOT.color(0);
|
||||
BlinkerMIOT.mode(0);
|
||||
BlinkerMIOT.colorTemp(1000);
|
||||
BlinkerMIOT.brightness(1);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
BLINKER_DEBUG.debugAll();
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerMIOT.attachPowerState(miotPowerState);
|
||||
BlinkerMIOT.attachColor(miotColor);
|
||||
BlinkerMIOT.attachMode(miotMode);
|
||||
BlinkerMIOT.attachBrightness(miotBright);
|
||||
BlinkerMIOT.attachColorTemperature(miotColoTemp);
|
||||
BlinkerMIOT.attachQuery(miotQuery);
|
||||
|
||||
pinMode(14, OUTPUT);
|
||||
digitalWrite(14, HIGH);
|
||||
pinMode(15, OUTPUT);
|
||||
digitalWrite(15, HIGH);
|
||||
|
||||
colorR = 255;
|
||||
colorG = 255;
|
||||
colorB = 255;
|
||||
colorW = 0;
|
||||
wsState = true;
|
||||
|
||||
pixels.begin();
|
||||
pixels.setBrightness(colorW);
|
||||
WS2812.attach(ws2812_callback);
|
||||
pixelShow();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
|
||||
for(int i = 0; i < NUMPIXELS; i++){
|
||||
pixels.setPixelColor(i, colorR, colorG, colorB);
|
||||
}
|
||||
pixels.show();
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_MIOT_MULTI_OUTLET
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
bool oState[5] = { false };
|
||||
|
||||
void miotPowerState(const String & state, uint8_t num)
|
||||
{
|
||||
BLINKER_LOG("need set outlet: ", num, ", power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerMIOT.powerState("on", num);
|
||||
BlinkerMIOT.print();
|
||||
|
||||
oState[num] = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerMIOT.powerState("off", num);
|
||||
BlinkerMIOT.print();
|
||||
|
||||
oState[num] = false;
|
||||
|
||||
if (num == 0)
|
||||
{
|
||||
for (uint8_t o_num = 0; o_num < 5; o_num++)
|
||||
{
|
||||
oState[o_num] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void miotQuery(int32_t queryCode, uint8_t num)
|
||||
{
|
||||
BLINKER_LOG("MIOT Query outlet: ", num,", codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_ALL_NUMBER :
|
||||
BLINKER_LOG("MIOT Query All");
|
||||
BlinkerMIOT.powerState(oState[num] ? "on" : "off", num);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
|
||||
BLINKER_LOG("MIOT Query Power State");
|
||||
BlinkerMIOT.powerState(oState[num] ? "on" : "off", num);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerMIOT.powerState(oState[num] ? "on" : "off", num);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerMIOT.attachPowerState(miotPowerState);
|
||||
BlinkerMIOT.attachQuery(miotQuery);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_MIOT_OUTLET
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
bool oState = false;
|
||||
|
||||
void miotPowerState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set power state: ", state);
|
||||
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerMIOT.powerState("on");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
oState = true;
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerMIOT.powerState("off");
|
||||
BlinkerMIOT.print();
|
||||
|
||||
oState = false;
|
||||
}
|
||||
}
|
||||
|
||||
void miotQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("MIOT Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_ALL_NUMBER :
|
||||
BLINKER_LOG("MIOT Query All");
|
||||
BlinkerMIOT.powerState(oState ? "on" : "off");
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
|
||||
BLINKER_LOG("MIOT Query Power State");
|
||||
BlinkerMIOT.powerState(oState ? "on" : "off");
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerMIOT.powerState(oState ? "on" : "off");
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerMIOT.attachPowerState(miotPowerState);
|
||||
BlinkerMIOT.attachQuery(miotQuery);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_MIOT_SENSOR
|
||||
|
||||
#include <Blinker.h>
|
||||
|
||||
char auth[] = "Your Device Secret Key";
|
||||
char ssid[] = "Your WiFi network SSID or name";
|
||||
char pswd[] = "Your WiFi network WPA password or WEP key";
|
||||
|
||||
void miotQuery(int32_t queryCode)
|
||||
{
|
||||
BLINKER_LOG("MIOT Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode)
|
||||
{
|
||||
case BLINKER_CMD_QUERY_ALL_NUMBER :
|
||||
BLINKER_LOG("MIOT Query All");
|
||||
BlinkerMIOT.temp(20);
|
||||
BlinkerMIOT.humi(20);
|
||||
BlinkerMIOT.pm25(20);
|
||||
BlinkerMIOT.co2(20);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerMIOT.temp(20);
|
||||
BlinkerMIOT.humi(20);
|
||||
BlinkerMIOT.pm25(20);
|
||||
BlinkerMIOT.co2(20);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker readString: ", data);
|
||||
|
||||
Blinker.vibrate();
|
||||
|
||||
uint32_t BlinkerTime = millis();
|
||||
|
||||
Blinker.print("millis", BlinkerTime);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
|
||||
BlinkerMIOT.attachQuery(miotQuery);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blinker.run();
|
||||
}
|
||||
Reference in New Issue
Block a user