我结合使用没问题,代码如下,你看看:
- #define BLINKER_WIFI
- #include <Blinker.h>
- #include <WiFiManager.h>
- //引脚定义
- #define RELAY 0 //继电器按钮
- #define RECONFIG 2 //重置网络实体按钮(LED),GPIO2引脚接地500ms即可复位
- //点灯平台信息
- char auth[] = "授权码";
- // 新建组件对象
- BlinkerButton Button_Relay("btn-relay");
- //使用web配置网络
- WiFiManager wifiManager;
- char devname[] = "ESP8266-01S-1"; //定义WIFI名称和主机名
- void WebConfig() {
- Serial.println("Entered config mode...");
- // 自动连接WiFi,参数是连接ESP8266时的WiFi名称
- //wifiManager.setConnectTimeout(30); //设置连接超时时间30s
- wifiManager.autoConnect(devname);
- WiFi.hostname(devname); //设置主机名
- // WiFi连接成功后将通过串口监视器输出连接成功信息
- Serial.println("");
- Serial.println("======== WifiManager Network Info ========");
- Serial.print("### ESP8266 Connected to: ");
- Serial.println("### SSID: " + (String)WiFi.SSID()); // WiFi名称
- Serial.println("### PSWD: " + (String)WiFi.psk()); // WiFi名称
- Serial.print("### IP address: ");
- Serial.println(WiFi.localIP()); // IP
- Serial.println("### HostName: " + WiFi.hostname()); // 主机名
- Serial.println("==========================================");
- Serial.println("");
- }
- //重置网络信息按钮事件
- void Button_RstConfig_callback(){
- if (digitalRead(RECONFIG) == LOW) {
- delay(500);
- if (digitalRead(RECONFIG) == LOW) {
- Serial.println("Reset Config...");
- wifiManager.resetSettings(); //擦除WIFI信息
- //wifiManager.reboot(); //重启设备
- Blinker.reset(); //重置设备
- }
- }
- }
- // 继电器按钮事件
- void Button_Relay_callback(const String & state){
- BLINKER_LOG("Relay State: ", state);
- //digitalWrite(RELAY, !digitalRead(RELAY));
- if (digitalRead(RELAY) == HIGH) {
- digitalWrite(RELAY, LOW);
- Button_Relay.icon("fad fa-siren-on");
- Button_Relay.print("on");
- } else if (digitalRead(RELAY) == LOW) {
- digitalWrite(RELAY, HIGH);
- Button_Relay.icon("fad fa-siren");
- Button_Relay.print("off");
- }
- }
- // 如果未绑定的组件被触发,则会执行其中内容
- void dataRead(const String & data){
- BLINKER_LOG("Blinker readString: ", data);
- }
- void setup(){
- // 初始化串口
- Serial.begin(115200);
- BLINKER_DEBUG.stream(Serial);
- BLINKER_DEBUG.debugAll();
- //串口打印说明信息
- Serial.println("### Notice: Set GPIO2 to LOW and reset after 500ms.");
- // 初始化IO
- pinMode(RELAY, OUTPUT);
- pinMode(RECONFIG, OUTPUT);
- digitalWrite(RELAY, HIGH);
- digitalWrite(RECONFIG, HIGH);
- WebConfig(); //配置网络
- Blinker.begin(auth, WiFi.SSID().c_str(), WiFi.psk().c_str()); //初始化blinker
- //Blinker.begin(auth);
- Blinker.attachData(dataRead);
- Button_Relay.attach(Button_Relay_callback);
- }
- void loop() {
- Blinker.run();
- Button_RstConfig_callback(); //循环监听复位按钮是否按下
- }
复制代码
|