|
楼主 |
发表于 2020-6-15 19:19
|
显示全部楼层
这个代码能实现点灯科技app控制
但是天猫精灵控制不了,天猫精灵能绑定设备,就是不能语音控制
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#define BLINKER_ALIGENIE_OUTLET //不知道改不改
#include <Blinker.h>
char auth[] = "1a2c142";
char ssid[] = "2.00000G";
char pswd[] = "x000000";
BlinkerButton Button1("LC"); //定义按钮键名
bool oState = false;
int counter = 0;
void aligeniePowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) { //天猫精灵控制开命令 此处修改为点动模式,适合按钮操作,
digitalWrite(0, LOW);
delay(200);
digitalWrite(0, HIGH);
BlinkerAliGenie.powerState("on");
BlinkerAliGenie.print();
oState = true;
}
else if (state == BLINKER_CMD_OFF) { //天猫精灵控制关命令 此处修改为点动模式,适合按钮操作,
digitalWrite(0,LOW);
delay(200);
digitalWrite(0, HIGH);
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(BlinkerTime);
Blinker.print("millis", BlinkerTime);
}
void Button1_callback(const String & state)
{
if (state == BLINKER_CMD_BUTTON_TAP){
digitalWrite(0, HIGH);
Button1.text("", "已开启");
Button1.print("on");
Blinker.delay(1500);
digitalWrite(0, LOW);
Button1.text("", "已关闭");
Button1.print("off");
}
}
void setup() {
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(0, OUTPUT);
digitalWrite(0, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Button1.attach(Button1_callback);
Blinker.notify("!卧室的吸顶灯已上线!");
}
void loop() {
Blinker.run();
} |
|