想在点灯app里面加个刷新按键,程序里面加个刷新程序,一打开app,按一下刷新按键,就可以知道开关状态。不加刷新程序打开app会不显示按键颜色以及开关状态,需要按下开关按键,才能反馈开关状态。
所以想加个刷新程序,哪个大佬帮忙给加一下刷新程序
程序:
#define BLINKER_WIFI
#define BLINKER_MIOT_LIGHT
#include <Blinker.h>
char auth[] = "1650193a3e82";
char ssid[] = "LP_360-wifi";
char pswd[] = "1505313";
// 新建组件对象
BlinkerButton Button1("btn-3mo");
BlinkerNumber Number1("num-abc");
int counter = 0;
int GPIO = 0;
// 按下按键即会执行该函数
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state =="off" ) {
digitalWrite(GPIO, LOW);
Button1.print("off");
Button1.color("#808080");
Button1.text("灯关了");
}
else if (state == "on") {
digitalWrite(GPIO,HIGH );
Button1.print("on");
Button1.color("#008000");
Button1.text("灯开了");
}
}
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();
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(GPIO, HIGH);
BlinkerMIOT.powerState("off");
BlinkerMIOT.print();
}
}
// 如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter++;
Number1.print(counter);
}
void setup()
{
// 初始化串口
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
// 初始化有LED的IO
pinMode(GPIO, OUTPUT);
digitalWrite(GPIO, HIGH);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
BlinkerMIOT.attachPowerState(miotPowerState);
}
void loop() {
Blinker.run();
} |