|
直接上代码
#define BLINKER_WIFI
#define BLINKER_MIOT_LIGHT
#include <Blinker.h>
char auth[] = "1eb908545a4d";
char ssid[] = "dfjjs";
char pswd[] = "fsij115266";
// 新建组件对象
BlinkerButton Button1("btn-3za");
int GPIO = 2;//GPIO脚
// 按下按键即会执行该函数
void button1_callback(const String & state)
{
Serial.println(state);
//digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
digitalWrite(GPIO, !digitalRead(GPIO));//
BLINKER_LOG("get button state: ", state);
// Button1.print(state);
if (digitalRead(GPIO) == 1)
{
digitalWrite(LED_BUILTIN, HIGH);
Button1.text("已开启");
Button1.print("on");
}
else if (digitalRead(GPIO) == 0)
{
digitalWrite(LED_BUILTIN, LOW);
Button1.text("已关闭");
Button1.print("off");
}
Blinker.vibrate();//
}
void miotPowerState(const String & state)//ME:ZJK
{
BLINKER_LOG("need set power state: ", state);
Serial.println(state);
if (state == BLINKER_CMD_ON) {
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(GPIO, HIGH);//
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();
Button1.text("已开启");
Button1.print("on");
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(GPIO, LOW);//
BlinkerMIOT.powerState("off");
BlinkerMIOT.print();
Button1.text("已关闭");
Button1.print("off");
}
}
void heartbeat()
{
if(digitalRead(GPIO) == 1)
{
Button1.text("已开启");
Button1.print("on");
}
else{
Button1.text("已关闭");
Button1.print("off");
}
}
void setup()
{
// 初始化串口
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
// 初始化有LED的IO
// pinMode(LED_BUILTIN, OUTPUT);
// digitalWrite(LED_BUILTIN, HIGH);
pinMode(GPIO, OUTPUT);//
digitalWrite(GPIO, LOW);//
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
// Blinker.attachData(dataRead);
Button1.attach(button1_callback);//初始化点灯app按钮
BlinkerMIOT.attachPowerState(miotPowerState);//注册小米回调函数
}
void loop() {
Blinker.run();
}
大神帮忙看下 啥子情况
手机软件里显示离线
串口总是重复显示 下面信息
[274049] ERROR: Maybe you have put in the wrong AuthKey!
[274049] ERROR: Or maybe your request is too frequently!
[274053] ERROR: Or maybe your network is disconnected!
|
|