天猫精灵智能家居无法控制
点灯科技app可以控制,天猫精灵能绑定设备,就是不能控制,怎么办
请大佬帮忙看看下面的代码
#define BLINKER_WIFI
#define BLINKER_DUEROS_OUTLET
#define BLINKER_ALIGENIE_OUTLET //天猫精灵
#include <Blinker.h>
char auth[] = "100000002";
char ssid[] = "2000000G";
char pswd[] = "x0000000";
#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 AliGenieQuery(int32_t queryCode) //天猫精灵控制
{
BLINKER_LOG("AliGenie Query codes: ", queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("AliGenie Query All");
BlinkerAliGenie.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG("AliGenie Query Power State");
BlinkerAliGenie.print();
break;
default :
BlinkerAliGenie.print();
break;
}
}
void setup() {
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(0, OUTPUT);
digitalWrite(0, LOW);
Blinker.begin(auth, ssid, pswd);
BT1.attach(BT1_callback);
Blinker.notify("!卧室的吸顶灯已上线!");
}
void loop() {
Blinker.run();
}
无师自通,结合了几个前辈的代码,测试成功
#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();
}
页:
[1]