|
爱科技、爱创意、爱折腾、爱极致,我们都是技术控
您需要 登录 才可以下载或查看,没有账号?立即注册
x
看到坛友发的8.5的智能插座,也跟风买了几个,不过联想的没货了,就买的5孔的。
本人这方面小白,刷固件时遇到点问题,想请教一下。
卖家提供了两份代码,一个是联想的,一个是小葱的,也就是我买的这个。但小葱的编译不成功,提示如下
而我用联想的那个代码就没问题,可以正常刷写。
对比了一下两份代码,基本大同小异,只是小葱的多了几处代码。我贴出一部分
这是联想的:
- #define BLINKER_WIFI //官方wifi协议库
- #define BLINKER_MIOT_LIGHT // 设置小爱灯类库
- #define BLINKER_ALIGENIE_LIGHT // 设置天猫灯类库
- #define BLINKER_PRINT Serial //串口协议库
- #include <Blinker.h> //官方库
- #include <ESP8266WiFi.h> //官方库
- WiFiServer server(80); // 服务器端口号
- char auth[] = "改这里"; //设备key
- char ssid[] = "改这里"; //路由器wifi ssid
- char pswd[] = "改这里"; //路由器wifi 密码
- bool oState = false;
- int kg=5;//继电器输出
- int de=12;//灯输出
- int key=4 ;//按键
- //*******新建组件对象
- BlinkerButton Button1("btn-abc"); //设置app按键的键名
- //*******app上按下按键即会执行该函数app里按键
- void button1_callback(const String & state)
- {
- if (digitalRead(kg)==LOW)
- {
- BLINKER_LOG("get button state: ", state);
- digitalWrite(kg, HIGH);
- digitalWrite(de, LOW);
- Button1.print("on");
- Button1.color("#0000FF"); //设置app按键是浅蓝色
- Button1.text("开启中");
- }
- else if (digitalRead(kg)==HIGH)
- {
- BLINKER_LOG("get button state: ", state);
- digitalWrite(kg, LOW);
- digitalWrite(de, HIGH);
- Button1.print("off");
- Button1.color("#00FFFF"); //设置app按键是深蓝色
- Button1.text("关闭中");
- }
- }
复制代码
这是小葱的:
- #define BLINKER_WIFI //官方wifi协议库
- #define BLINKER_MIOT_LIGHT // 设置小爱灯类库
- #define BLINKER_ALIGENIE_LIGHT // 设置天猫灯类库
- #define BLINKER_DUEROS_LIGHT // 设置小度灯类库
- #define BLINKER_PRINT Serial //串口协议库
- #include <Blinker.h> //官方库
- #include <ESP8266WiFi.h> //官方库
- WiFiServer server(80); // 服务器端口号
- char auth[] = "改这里"; //设备key
- char ssid[] = "改这里"; //路由器wifi ssid
- char pswd[] = "改这里"; //路由器wifi 密码
- bool oState = false;
- int kg=14; //继电器输出
- int de=4; //灯输出
- int key=13 ;//按键
- //*******新建组件对象
- BlinkerButton Button1("btn-abc"); //设置app按键的键名
- BlinkerNumber Number1("num-abc");
- int counter = 0;
- void button1_callback(const String & state)
- {
- BLINKER_LOG("get button state: ", state);
- digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
- }
- void dataRead(const String & data)
- {
- BLINKER_LOG("Blinker readString: ", data);
- counter++;
- Number1.print(counter);
- }
- void setup()
- {
- Serial.begin(115200);
- BLINKER_DEBUG.stream(Serial);
- BLINKER_DEBUG.debugAll();
- WiFi.mode(WIFI_STA);
- WiFiManager wm;
- bool res;
- res = wm.autoConnect("AutoConnectAP", "password");
- if (!res) {
- Serial.println("Failed to connect");
- ESP.restart();
- }
- else {
- Serial.println("connected...yeey :)");
-
- Blinker.begin(auth, wm.getWiFiSSID().c_str(), wm.getWiFiPass().c_str());
- Blinker.attachData(dataRead);
- Button1.attach(button1_callback);
- }
-
- pinMode(LED_BUILTIN, OUTPUT);
- digitalWrite(LED_BUILTIN, HIGH);
- }
- //*******app上按下按键即会执行该函数app里按键
- void button1_callback(const String & state)
- {
- if (digitalRead(kg)==LOW)
- {
- BLINKER_LOG("get button state: ", state);
- digitalWrite(kg, HIGH);
- digitalWrite(de, LOW);
- Button1.print("on");
- Button1.color("#0000FF"); //设置app按键是浅蓝色
- Button1.text("开启中");
- }
- else if (digitalRead(kg)==HIGH)
- {
- BLINKER_LOG("get button state: ", state);
- digitalWrite(kg, LOW);
- digitalWrite(de, HIGH);
- Button1.print("off");
- Button1.color("#00FFFF"); //设置app按键是深蓝色
- Button1.text("关闭中");
- }
- }
- //利用resetFunc()内置函数,实现断网重启,定义相关变量
- uint32_t con_time = 0; //断网记时
- int con_flag = 0; //断网标记,1为断网
- void(*resetFunc) (void) = 0;
- //硬件重置WIFI配网信息
- uint32_t rst_time = 0; //记录RESET_IO低电平前系统时间
- void button1_callback(const String & state)
- {
- if (state == BLINKER_CMD_ON) {
- BLINKER_LOG("Toggle on!");
- digitalWrite(LED_BUILTIN, LOW);
- Button1.icon("fas fa-lightbulb-on");
- Button1.color("#FFFF00");
- Button1.text("开");
- Button1.print("on");
- BUILTIN_Button.print("on"); // Blinker主界面设备开关按钮状态
- }
- else if (state == BLINKER_CMD_OFF) {
- BLINKER_LOG("Toggle off!");
- digitalWrite(LED_BUILTIN, HIGH);
- Button1.icon("fas fa-lightbulb");
- Button1.color("#808080");
- Button1.text("关");
- Button1.print("off");
- BUILTIN_Button.print("off");
- }
- }
- void reset_callback(const String & state){
- BLINKER_LOG("get button state:", state);
- //当长按"Reset"释放后清除配网信息
- if(state == "pressup"){
- for(int i = 0; i<3 ; i++)
- {
- digitalWrite(LED_BUILTIN, LOW);
- Blinker.delay(300);
- digitalWrite(LED_BUILTIN, HIGH);
- Blinker.delay(300);
- }
- Blinker.reset();
- }
- }
- //断网自动重连程序
- if (Blinker.connected())
- {
- con_flag = 0;
- }
- else
- {
- if (con_flag == 0)
- {
- con_time = millis(); //给断网时间赋初始值
- con_flag = 1;
- }
- else
- {
- if ((millis() - con_time) >= 90000) //判断断网时间超90秒后执行重启,这个时间可根据实际需要调整
- {
- resetFunc();
- }
- }
- }
- //复位清除配网
- if(digitalRead(Button1) == HIGH)
- {
- rst_time = millis(); //刷新复位针脚复位之前的系统时间
- }
- if(digitalRead(Button1) == LOW)
- {
- if((millis() - rst_time) >= 3000)//复位按钮按下时长大于3秒,开始清除配网信息
- {
- //清除配网前LED灯闪烁
- for(int i = 0; i<3 ; i++)
- {
- digitalWrite(LED_BUILTIN, LOW);
- Blinker.delay(300);
- digitalWrite(LED_BUILTIN, HIGH);
- Blinker.delay(300);
- }
复制代码
后面基本相同,错误就出现在多出的代码里面,我也不懂这个不会修改。或者可能是我的库有问题?
求大佬帮我解答一下。感谢。
|
|