|
本帖最后由 13413180254 于 2021-11-16 10:56 编辑
SMARTCONFIG配网成功,每次点击设备会断网重连一次。
代码如下:
- #define BLINKER_WIFI
- #define BLINKER_ESP_SMARTCONFIG
- //#define BLINKER_APCONFIG
- #define BLINKER_PRINT Serial //串口协议库
- #include <Blinker.h>
- #include "OneButton.h" //按键库文件
- #define BLINKER_BUTTON_PIN D7 //重置WiFi按键,短接低电平
- // button trigged when pin input level is LOW
- OneButton button(BLINKER_BUTTON_PIN, true);
- #define yj1 D5 //要操作的IO,设定D5引脚为输出
- char auth[] = "018a1a188888"; //点灯秘钥
- void deviceReset() //重置设备,消除无线配置。
- {
- Blinker.reset();
- }
- BlinkerButton Button1("btn-abc"); //app按钮
- void Button1_callback(const String & state) // 按下按键即会执行该函数
- {
- BLINKER_LOG("get button state: ", state);
- if (state == "on") {
- Button1.print("on");
- digitalWrite(yj1,HIGH);
- }
- else if (state == "off") {
- Button1.print("off");
- digitalWrite(yj1,LOW);
- }
- }
- void dataRead(const String & data) //未绑定组件打印信息
- {
- BLINKER_LOG("Blinker readString: ", data);
- Blinker.vibrate();
- uint32_t BlinkerTime = millis();
- Blinker.print("millis", BlinkerTime);
- }
- void heartbeat() // 心跳包函数,app状况回调
- {
- BLINKER_LOG("状态同步!");
- if (digitalRead(yj1)==HIGH)
- {
- Button1.print("on");
- }
- else
- {
- Button1.print("off");
- }
- }
- void setup(){
- Serial.begin(115200);
- BLINKER_DEBUG.stream(Serial);
- BLINKER_DEBUG.debugAll(); //开启调试模式,可以看到 blinker mqtt 协议相关交互信息
- pinMode(LED_BUILTIN, OUTPUT);
- pinMode(yj1, OUTPUT);
- digitalWrite(yj1, LOW);
- Blinker.begin(auth);
- Button1.attach(Button1_callback); //开关按钮回调
- Blinker.attachHeartbeat(heartbeat); //APP状态回调
- Blinker.attachData(dataRead); //未绑定组件回调
- button.attachLongPressStop(deviceReset); //重置按键回调
- }
- void loop()
- {
- Blinker.run();
- button.tick();
- }
复制代码
|
|