|
楼主 |
发表于 2020-2-25 19:59
|
显示全部楼层
下面是我的代码。
#define BLINKER_WIFI
#define BLINKER_ALIGENIE_OUTLET //caiyq52-天猫精灵
#include <Blinker.h>
char auth[] = "-"; //caiyq52-改成自己在点灯app中生成的key码
char ssid[] = "-"; //caiyq52-改成自己的WIFI名称
char pswd[] = "-"; //caiyq52-改成自己的WIFI密码
BlinkerButton Button1("dianshi"); //caiyq52-此组件未点灯app中自己设置的按键,改名"btn-abc"必须与自己APP中设定的名称一致
bool oState = false;
int Pin = 0; //caiyq52-定义控制引脚
void AliGeniePowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) { //caiyq52-天猫精灵控制开命令
digitalWrite(0, LOW);
delay(200);
digitalWrite(0, HIGH);
BlinkerAliGenie.powerState("on");
BlinkerAliGenie.print();
oState = true;
}
else if (state == BLINKER_CMD_OFF) { //caiyq52-天猫精灵控制关命令
digitalWrite(0,LOW);
delay(200);
digitalWrite(0, HIGH);
BlinkerAliGenie.powerState("off");
BlinkerAliGenie.print();
oState = false;
}
}
void AliGenieQuery(int32_t queryCode) //caiyq52-天猫精灵控制
{
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 button1_callback(const String & state) //点灯app内控制按键触发
{
BLINKER_LOG("get button state: ", state);
digitalWrite(0,LOW);
delay(200);
digitalWrite(0, HIGH);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(Pin, OUTPUT); //定义io口为输出
digitalWrite(Pin, LOW); //定义io默认电平
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
BlinkerAliGenie.attachPowerState(AliGeniePowerState);
BlinkerAliGenie.attachQuery(AliGenieQuery);
Button1.attach(button1_callback);
}
void loop()
{
Blinker.run();
} |
|