状态不能同步了?
app和小爱控制都正常,就是app的按钮不显示开关状态,请各位大佬帮忙看看什么原因?#define BLINKER_WIFI
#define BLINKER_MIOT_LIGHT//支持小爱同学
#include <Blinker.h>
char auth[] = "*********";//app中获取到的Secret Key(密钥)
char ssid[] = "****";
char pswd[] = "********";
unsigned long Timers = {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);
}
}
https://www.arduino.cn/thread-84332-1-1.html 奈何col 发表于 2020-6-22 20:20
https://www.arduino.cn/thread-84332-1-1.html
下面是我在app点击按钮之后的信息,劳烦帮忙看下,安装的状态一直是关闭。。。
21:25:24.448 -> num: 0, get Text: {"btn-abc":"on"}, length: 16
21:25:24.482 -> parse data: {"btn-abc":"on"}
21:25:24.482 -> defined BLINKER_ARDUINOJSON
21:25:24.482 -> autoManager begin: 0 0
21:25:24.482 -> checkNum count: 1
21:25:24.482 -> strWidgetsParse isParsed
21:25:24.482 -> strWidgetsParse: btn-abc
21:25:24.482 -> get button state: on
21:25:24.482 -> autoFormatData key: vibrate, json: "vibrate":200
21:25:24.517 -> new.
21:25:24.517 -> isParsed
21:25:24.589 -> print: {"vibrate":200}
21:25:24.589 -> Proto print...
21:25:24.589 -> Freeheap: 7760
21:25:24.589 -> WS response:
21:25:24.624 -> {"vibrate":200}
21:25:24.624 -> Success...
21:25:24.624 -> Freeheap: 8120
21:25:27.110 -> num: 0, get Text: {"btn-abc":"on"}, length: 16
21:25:27.147 -> parse data: {"btn-abc":"on"}
21:25:27.147 -> defined BLINKER_ARDUINOJSON
21:25:27.147 -> autoManager begin: 0 0
21:25:27.147 -> checkNum count: 1
21:25:27.147 -> strWidgetsParse isParsed
21:25:27.147 -> strWidgetsParse: btn-abc
21:25:27.147 -> get button state: on
21:25:27.147 -> autoFormatData key: vibrate, json: "vibrate":200
21:25:27.182 -> new.
21:25:27.182 -> isParsed
21:25:27.252 -> print: {"vibrate":200}
21:25:27.252 -> Proto print...
21:25:27.252 -> Freeheap: 7760
21:25:27.287 -> WS response:
21:25:27.287 -> {"vibrate":200}
21:25:27.287 -> Success...
21:25:27.287 -> Freeheap: 8120
21:25:28.994 -> MQTT Ping!
21:25:28.994 -> Freeheap: 8984
请把入门教程先看一遍
https://www.arduino.cn/thread-83176-1-1.html
页:
[1]