|
本帖最后由 yz465795771 于 2020-2-10 20:05 编辑
这是写好的代码,烧录后ESP8266,开关设备指示灯不亮,不清楚能不能用,各位大佬帮忙给看一看
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#define BLINKER_ALIGENIE_OUTLET //不知道改不改
#include <Blinker.h>
char auth[] = ""; //设备key
char ssid[] = ""; //路由器wifi ssid
char pswd[] = ""; //路由器wifi 密码
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) //点灯app内控制按键触发
{
BLINKER_LOG("get button state: ", state);
digitalWrite(0,LOW);
delay(200);
digitalWrite(0, HIGH);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial); //Serial
pinMode(0, OUTPUT); //定义io口为输出 或者改成pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(0, HIGH); //定义io默认为高电平 或者改成digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
BlinkerAliGenie.attachPowerState(aligeniePowerState);
BlinkerAliGenie.attachQuery(aligenieQuery);
Button1.attach(button1_callback);
}
void loop()
{
Blinker.run();
}
|
|