|
楼主 |
发表于 2020-6-16 21:40
|
显示全部楼层
无师自通,结合了几个前辈的代码,测试成功
[mw_shl_code=arduino,true]#define BLINKER_WIFI
#define BLINKER_ALIGENIE_OUTLET //caiyq52-天猫精灵
#define BLINKER_ALIGENIE_LIGHT // 设置天猫灯类库
#define BLINKER_PRINT Serial //串口协议库
#include <Blinker.h>
#include <ESP8266WiFi.h> //官方库
char auth[] = "1a00000";
char ssid[] = "2.d0000000000G";
char pswd[] = "x0000000000";
#define BT_1 "lb"//后期可自行修改数据键名
BlinkerButton BT1(BT_1);
void BT1_callback(const String & state)
{
if (state == BLINKER_CMD_BUTTON_TAP){
digitalWrite(0, HIGH);
BT1.text("", "已开启");
BT1.print("on");
Blinker.delay(1500);
digitalWrite(0, LOW);
BT1.text("", "已关闭");
BT1.print("off");
}
}
void AliGeniePowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) { //caiyq52-天猫精灵控制开命令
digitalWrite(0, HIGH);
BLINKER_LOG("已开启!"); //串口打印
BT1.text("已开启");
BlinkerAliGenie.powerState("on");
BlinkerAliGenie.print();
// 反馈开关状态
BT1.print("on");
Blinker.delay(1500);
digitalWrite(0, LOW);
BLINKER_LOG("已关闭!"); //串口打印
BT1.text("已关闭");
BlinkerAliGenie.powerState("off");
BlinkerAliGenie.print();
// 反馈开关状态
BT1.print("off");
}
}
void setup() {
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(0, OUTPUT);
digitalWrite(0, LOW);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
BlinkerAliGenie.attachPowerState(AliGeniePowerState);
BT1.attach(BT1_callback);
Blinker.notify("!卧室的吸顶灯已上线!");
}
void loop() {
Blinker.run();
}[/mw_shl_code] |
|