app和小爱控制都正常,就是app的按钮不显示开关状态,请各位大佬帮忙看看什么原因?
[md]#define BLINKER_WIFI
#define BLINKER_MIOT_LIGHT//支持小爱同学
#include <Blinker.h>
char auth[] = "*********";//app中获取到的Secret Key(密钥)
char ssid[] = "****";
char pswd[] = "********";
unsigned long Timers[3] = {0};
int GPIO = 0; //定义继电器输入引脚为GPIO/0
int switch_button = 2;
int temp = 0;
// 新建组件对象
BlinkerButton Button1("btn-abc");//注意:要和APP组件’数据键名’一致
// 按下BlinkerAPP按键即会执行该函数
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
digitalWrite(GPIO, !digitalRead(GPIO));
Blinker.vibrate();
}
bool oState = false;
//小爱电源类操作的回调函数:
//当小爱同学向设备发起控制, 设备端需要有对应控制处理函数
void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) {
digitalWrite(GPIO, LOW);
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();
oState = true;
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(GPIO, HIGH);
BlinkerMIOT.powerState("off");
BlinkerMIOT.print();
oState = false;
}
}
void setup() {
// 初始化串口,并开启调试信息,调试用可以删除
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
// 初始化IO
pinMode(GPIO, OUTPUT);
digitalWrite(GPIO, HIGH);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Button1.attach(button1_callback);
//小爱同学务必在回调函数中反馈该控制状态
BlinkerMIOT.attachPowerState(miotPowerState);//注册回调函数
}
void loop() {
Blinker.run();
temp = digitalRead(switch_button);
if (temp == LOW) {
digitalWrite(GPIO, !digitalRead(GPIO));
pinMode(switch_button, INPUT_PULLUP);
delay(300);
}
}[/md]
|