数码之家

 找回密码
 立即注册
搜索
查看: 8463|回复: 70

[Arduino] 公模智能插座改点灯软件/小爱同学、Web配网和密钥,Web OTA、需要的功能都有

    [复制链接]
发表于 2021-8-14 10:28:13 | 显示全部楼层 |阅读模式

爱科技、爱创意、爱折腾、爱极致,我们都是技术控

您需要 登录 才可以下载或查看,没有账号?立即注册

x
1.前言

咸鱼上有卖只能插座8.5一个,比较便宜就入手了
智能插座属于三无产品,公模外壳,app是丛云,应该已经停了
因此卖的便宜,也因此需要DIY软件,芯片是ESP8266
看了本帖,你可以学会如下技能:

-某智能插座的PIN定义
-如何Web配网和密钥
-如何Web OTA和Flash不足时OTA
-接入小爱同学


2.硬件介绍

公模外壳
IMG_20210808_161818.jpg


三无产品
IMG_20210808_161812.jpg
带一个按键


IMG_20210808_161822.jpg


带安全门
IMG_20210808_162922.jpg


PIN脚定义
5D4C1875-8A18-4510-A794-8C08CA51E0F8.png


正面
IMG_20210808_162142.jpg
IMG_20210808_162937.jpg


ESP8266+1MB
IMG_20210808_173441.jpg


因此刷机时,按如下方式接线
插座  TTL板
Rx  -  Tx
Tx  -  Rx
Vcc - 3.3V
Gnd- Gnd
GPIO0-Gnd


3.软件介绍
3.1需要安装Arduino(略)
3.2需要安装Blinker(略)blinker-library-0.3.80210611
3.3需要安装依赖库
“工具”- “管理库”
WiFiManager;用于web配网

QQ截图20210813214225.png


3.4代码(都是网上找的,大家将就着看吧)


继电器
Relay.ino
  1. #define BLINKER_WIFI
  2. #define BLINKER_MIOT_OUTLET

  3. #include <Blinker.h>
  4. #include <Ticker.h>
  5. #include <ESP8266WebServer.h>
  6. #include <ESP8266mDNS.h>
  7. #include <ESP8266HTTPUpdateServer.h>
  8. #include "Blwifi.h"

  9. const char* host = "SwitchUpdate";

  10. ESP8266WebServer httpServer(80);
  11. ESP8266HTTPUpdateServer httpUpdater;

  12. BlinkerButton BtRelay("btn-rly");
  13. #define BLUE_LED  15
  14. #define RED_LED   13
  15. Ticker ticker;
  16. uint8_t connFlag = 0;

  17. void BtRelay_callback(const String & state)
  18. {
  19.   BLINKER_LOG("get button state: ", state);
  20.   if(state=="on")
  21.   {
  22.     digitalWrite(RELAY_PIN, HIGH);
  23.     BtRelay.text("on");
  24.     BtRelay.color("#FFB90F");
  25.     BtRelay.print("on");
  26.   }
  27.   else if(state=="off")
  28.   {
  29.     digitalWrite(RELAY_PIN, LOW);
  30.     BtRelay.text("off");
  31.     BtRelay.color("#DCDCDC");
  32.     BtRelay.print("off");
  33.   }
  34.   else
  35.   {
  36.     if(digitalRead(RELAY_PIN))
  37.     {
  38.       digitalWrite(RELAY_PIN, LOW);
  39.       BtRelay.text("on");
  40.       BtRelay.color("#FFB90F");
  41.       BtRelay.print("on");
  42.     }
  43.     else
  44.     {
  45.       digitalWrite(RELAY_PIN, HIGH);
  46.       BtRelay.text("off");
  47.       BtRelay.color("#DCDCDC");
  48.       BtRelay.print("off");
  49.     }
  50.   }
  51. }

  52. void SetLed()
  53. {
  54.   //if(connFlag == 1)
  55.   {
  56.     if(digitalRead(RELAY_PIN))
  57.     {
  58.       digitalWrite(BLUE_LED, HIGH);
  59.       digitalWrite(RED_LED, LOW);
  60.     }
  61.     else
  62.     {
  63.       digitalWrite(BLUE_LED, LOW);
  64.       digitalWrite(RED_LED, HIGH);
  65.     }
  66.   }
  67. }

  68. void tickerCount()
  69. {
  70.   if(connFlag == 0)
  71.     digitalWrite(BLUE_LED, !digitalRead(BLUE_LED));
  72. }
  73. void dataRead(const String & data)
  74. {
  75.     BLINKER_LOG("Blinker readString: ", data);

  76.     Blinker.vibrate();
  77.    
  78.     uint32_t BlinkerTime = millis();
  79.    
  80.     Blinker.print("millis", BlinkerTime);
  81. }

  82. void heartbeat()
  83. {  
  84.   if(digitalRead(RELAY_PIN))
  85.   {
  86.     BtRelay.text("on");
  87.     BtRelay.color("#FFB90F");
  88.     BtRelay.print("on");
  89.   }
  90.   else
  91.   {
  92.     BtRelay.text("off");
  93.     BtRelay.color("#DCDCDC");
  94.     BtRelay.print("off");
  95.   }
  96. }

  97. void miotPowerState(const String & state)
  98. {
  99.   BLINKER_LOG("need set power state: ", state);

  100.   if (state == BLINKER_CMD_ON)
  101.   {
  102.     digitalWrite(RELAY_PIN, HIGH);
  103.     BlinkerMIOT.powerState("on");
  104.     BlinkerMIOT.print();
  105.   }
  106.   else if (state == BLINKER_CMD_OFF)
  107.   {
  108.     digitalWrite(RELAY_PIN, LOW);
  109.     BlinkerMIOT.powerState("off");
  110.     BlinkerMIOT.print();
  111.   }
  112. }

  113. void miotQuery(int32_t queryCode)
  114. {
  115.   BLINKER_LOG("MIOT Query codes: ", queryCode);

  116.   switch (queryCode)
  117.   {
  118.     case BLINKER_CMD_QUERY_ALL_NUMBER :
  119.       BLINKER_LOG("MIOT Query All");
  120.       BlinkerMIOT.powerState(digitalRead(RELAY_PIN) ? "on" : "off");
  121.       BlinkerMIOT.print();
  122.       break;
  123.     case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
  124.       BLINKER_LOG("MIOT Query Power State");
  125.       BlinkerMIOT.powerState(digitalRead(RELAY_PIN) ? "on" : "off");
  126.       BlinkerMIOT.print();
  127.       break;
  128.     default :
  129.       BlinkerMIOT.powerState(digitalRead(RELAY_PIN) ? "on" : "off");
  130.       BlinkerMIOT.print();
  131.       break;
  132.   }
  133. }

  134. void setup()
  135. {
  136.     Serial.begin(115200);
  137.     BLINKER_DEBUG.stream(Serial);
  138.     connFlag = 0;
  139.     ticker.attach(1, tickerCount);
  140.    
  141.     Blwifi_InitWiFi();
  142.    
  143.     Blinker.begin(wifiSettings.auth_key, wifiSettings.ssid, wifiSettings.pswd);
  144.     Blinker.attachData(dataRead);
  145.     Blinker.attachHeartbeat(heartbeat);

  146.     BlinkerMIOT.attachPowerState(miotPowerState);
  147.     BlinkerMIOT.attachQuery(miotQuery);
  148.    
  149.     BtRelay.attach(BtRelay_callback);
  150.     pinMode(RELAY_PIN, OUTPUT);
  151.     digitalWrite(RELAY_PIN, HIGH);
  152.     pinMode(BLUE_LED, OUTPUT);
  153.     pinMode(RED_LED, OUTPUT);
  154.     digitalWrite(RED_LED, LOW);

  155.     MDNS.begin(host);
  156.     httpUpdater.setup(&httpServer);
  157.     httpServer.begin();
  158.     MDNS.addService("http", "tcp", 80);
  159.     connFlag = 1;
  160. }

  161. void loop()
  162. {
  163.     Blinker.run();
  164.     Blwifi_Loop();
  165.     httpServer.handleClient();
  166.     SetLed();
  167. }
复制代码

引用的文件
Blwifi.cpp
  1. #include <WiFiManager.h>
  2. #include <EEPROM.h>
  3. #include "GpioButton.h"
  4. #include "Blwifi.h"

  5. WiFiManager wifiManager;

  6. void ResetWifi()
  7. {
  8.   ClearWiFiInfo();
  9.   wifiManager.resetSettings();
  10.   ESP.restart();
  11. }

  12. void mbt_press_callback()
  13. {
  14.   #ifdef SUPPORT_DEBUG
  15.   Serial.println("<Event>Click");
  16.   #endif
  17.   if(digitalRead(RELAY_PIN))
  18.   {
  19.     digitalWrite(RELAY_PIN, LOW);
  20.   }
  21.   else
  22.   {
  23.     digitalWrite(RELAY_PIN, HIGH);
  24.   }  
  25. }

  26. void mbt_long_press_callback()
  27. {
  28.   #ifdef SUPPORT_DEBUG
  29.   Serial.println("<Event>Long Press Tick");
  30.   Serial.println(F("WiFi resetSettings."));
  31.   #endif
  32.   for(int i=0;i<3;i++)
  33.   {
  34.     digitalWrite(LED_IO, LOW);
  35.     delay(100);
  36.     digitalWrite(LED_IO, HIGH);
  37.     delay(400);
  38.   }
  39.   ResetWifi();
  40. }

  41. // 定义按钮对象,指定按钮的GPIO口
  42. GpioButton myButton(RESET_WIFI_PIN);

  43. bool shouldSaveConfig=false;
  44. Settings wifiSettings;

  45. void saveConfigCallback()
  46. {
  47.   #ifdef SUPPORT_DEBUG
  48.   Serial.println("Should save config");
  49.   #endif
  50.   shouldSaveConfig = true;
  51. }

  52. bool chkAuthkey(char* key, int len)
  53. {
  54.   if (len != 12) return false;
  55.   for (int i=0;key[i]!=0;i++){
  56.     if (!isxdigit(key[i])) return false;
  57.   }
  58.   return true;
  59. }
  60. void ClearWiFiInfo()
  61. {
  62.   EEPROM.begin(1280);
  63.   EEPROM.get<Settings>(1024, wifiSettings);
  64.   wifiSettings.auth_key[0]='\0';
  65.   EEPROM.put<Settings>(1024, wifiSettings);
  66.   if (EEPROM.commit())
  67.   {
  68.     #ifdef SUPPORT_DEBUG
  69.     Serial.println(F("EEPROM successfully committed"));
  70.     #endif
  71.   }
  72.   else
  73.   {
  74.     #ifdef SUPPORT_DEBUG
  75.     Serial.println(F("ERROR! EEPROM commit failed"));
  76.     #endif
  77.   }
  78.   EEPROM.end();
  79. }
  80. void Blwifi_InitWiFi()
  81. {
  82.   myButton.bindEventOnClick(mbt_press_callback);
  83.   myButton.bindEventOnLongPress(mbt_long_press_callback);

  84.   EEPROM.begin(1280);
  85.   EEPROM.get<Settings>(1024, wifiSettings);

  86.   if( wifiSettings.auth_key[0]=='\0'||wifiSettings.auth_key[0]==0xFF)
  87.   {
  88.     WiFi.mode(WIFI_STA);
  89.     //wifiManager.setDebugOutput(true);
  90.    
  91.     wifiManager.resetSettings();

  92.     wifiManager.setAPStaticIPConfig(IPAddress(192,168,10,1), IPAddress(192,168,10,1), IPAddress(255, 255, 255, 0));
  93.      // 3分钟配网时间,如没有完成则退出配网.
  94.      // 例如原正常连接的WIFI路由掉线死机或不通电等情况, 通过配网超时后, 会重新进行连接原WIFI信号。 避免停在配网模式下等待
  95.     wifiManager.setConfigPortalTimeout(180);
  96.     //wifiManager.setConnectTimeout(240);

  97.     // 设置点击保存的回调
  98.     wifiManager.setSaveConfigCallback(saveConfigCallback);

  99.     WiFiManagerParameter custom_authkey("auth_key", "Authkey", wifiSettings.auth_key, 12);
  100.     wifiManager.addParameter(&custom_authkey);

  101.     //AP名称:ESP_AP 密码:12345678
  102.     if(!wifiManager.autoConnect("ESP_AP","12345678"))
  103.     {
  104.       #ifdef SUPPORT_DEBUG
  105.       Serial.println(F("Failed to connect. Reset and try again. . ."));
  106.       #endif
  107.       ResetWifi();
  108.       delay(5000);
  109.     }
  110.     #ifdef SUPPORT_DEBUG
  111.     Serial.println(F("Connected to Wifi."));
  112.     Serial.print(F("My IP:"));
  113.     Serial.println(WiFi.localIP());
  114.     #endif

  115.     // 保存自定义信息
  116.     if (shouldSaveConfig)
  117.     {
  118.       #ifdef SUPPORT_DEBUG
  119.       Serial.println(F("saving config..."));
  120.       #endif
  121.       //Serial.println(custom_authkey.getValue());
  122.       strncpy(wifiSettings.auth_key, custom_authkey.getValue(), 12);
  123.       wifiSettings.auth_key[12] = '\0';
  124.       strcpy(wifiSettings.ssid, wifiManager.getWiFiSSID().c_str());
  125.       wifiSettings.ssid[wifiManager.getWiFiSSID().length()]='\0';
  126.       
  127.       strcpy(wifiSettings.pswd, wifiManager.getWiFiPass().c_str());
  128.       wifiSettings.pswd[wifiManager.getWiFiPass().length()]='\0';
  129.       
  130.       if (!chkAuthkey(wifiSettings.auth_key, strlen(wifiSettings.auth_key)))
  131.       {
  132.         #ifdef SUPPORT_DEBUG
  133.         Serial.println(F("Authkey is wrong."));
  134.         #endif
  135.         ResetWifi();
  136.         delay(5000);
  137.       }

  138.       EEPROM.put<Settings>(1024, wifiSettings);
  139.       if (EEPROM.commit())
  140.       {
  141.         #ifdef SUPPORT_DEBUG
  142.         Serial.println(F("EEPROM successfully committed"));
  143.         #endif
  144.       }
  145.       else
  146.       {
  147.         #ifdef SUPPORT_DEBUG
  148.         Serial.println(F("ERROR! EEPROM commit failed"));
  149.         #endif
  150.       }
  151.       ESP.restart();
  152.     }
  153.   }
  154.   EEPROM.end();
  155.   wifiSettings.auth_key[12] = '\0';
  156. }

  157. void Blwifi_Loop()
  158. {
  159.   myButton.loop();
  160. }
复制代码


Blwifi.h
  1. #ifndef __BLWIFI_H__
  2. #define __BLWIFI_H__

  3. //#define SUPPORT_DEBUG
  4. #define RESET_WIFI_PIN    12
  5. #define RELAY_PIN         4
  6. #define LED_IO 15

  7. struct Settings
  8. {
  9.   char auth_key[13];
  10.   char ssid[128];
  11.   char pswd[32];
  12. };
  13. extern Settings wifiSettings;

  14. void Blwifi_InitWiFi();
  15. void ClearWiFiInfo();
  16. void Blwifi_Loop();

  17. #endif
复制代码

这个应该是本论坛找的GpioButton.h
  1. GpioButton.h
  2. #ifndef _GPIO_BUTTON_H_
  3. #define _GPIO_BUTTON_H_
  4. #include <Arduino.h>

  5. #define        DEF_ELIMINATING_JITTER_MS        20                // 消抖延时毫秒数
  6. #define DEF_LONG_CLICK_MS           3000    // 默认单次长按事件触发毫秒数
  7. #define DEF_DB_INTERVAL_MS          300     // 默认双击事件间隔毫秒数
  8. #define DEF_LONG_PRESS_START_MS     DEF_LONG_CLICK_MS   // 长按循环触发事件的起始毫秒数
  9. #define DEF_LONG_PRESS_INTERVAL_MS  500     // 长按循环触发触发事件的间隔毫秒数

  10. #define DEF_KEY_UP                  HIGH
  11. #define DEF_KEY_DOWN                LOW

  12. typedef enum {
  13.     KEY_DOWN,
  14.     KEY_UP,
  15.     NO_CHANGE
  16. } KeyAction;

  17. class GpioButton {
  18.     public:
  19.         // 构造函数
  20.         GpioButton(uint8_t _pin, uint8_t _mode=INPUT_PULLUP, uint8_t _up_v=DEF_KEY_UP) : BtnPin(_pin), KeyUp(_up_v) {
  21.             KeyDown = (KeyUp==HIGH)?LOW:HIGH;
  22.             pinMode(BtnPin, _mode);
  23.         }
  24.         
  25.         // 事件绑定函数
  26.         void bindEventOnClick(void (*callback)()) {
  27.             on_click = callback;
  28.         }
  29.         void bindEventOnDBClick(void (*callback)()) {
  30.             on_db_click = callback;
  31.         }
  32.         void bindEventOnLongClick(void (*callback)()) {
  33.             on_long_click = callback;
  34.             on_long_press = nullptr;
  35.         }
  36.         void bindEventOnLongPress(void (*callback)()) {
  37.             on_long_press = callback;
  38.             on_long_click = nullptr;
  39.         }
  40.         void bindEventOnKeyDown(void (*callback)()) {
  41.             on_key_down = callback;
  42.         }
  43.         void bindEventOnKeyUp(void (*callback)()) {
  44.             on_key_up = callback;
  45.         }
  46.         
  47.         // set,get方法
  48.         void setEliminatingJitterMs(uint16_t _ms) {EliminatingJitterMs = _ms;}
  49.         void setLongClickMS(uint16_t _ms) {LongClickMS = _ms;}
  50.         void setLongStartMS(uint16_t _ms) {LongStartMS = _ms;}
  51.         void setLongIntervalMS(uint16_t _ms) {LongIntervalMS = _ms;}
  52.         void setLongPressNextTimeOut(uint32_t _to) {LongPressNextTimeOut = _to;}
  53.         void setDblClickIntervalMS(uint16_t _ms) {DblClickIntervalMS = _ms;}

  54.         uint16_t getEliminatingJitterMs() { return EliminatingJitterMs;}
  55.         uint16_t getLongClickMS() {return LongClickMS;}
  56.         uint16_t getLongStartMS() {return LongStartMS;}
  57.         uint16_t getLongIntervalMS() {return LongIntervalMS;}
  58.         uint32_t getLongPressNextTimeOut() {return LongPressNextTimeOut;}
  59.         uint16_t getDblClickIntervalMS() {return DblClickIntervalMS;}

  60.         // 对象轮询函数
  61.         void loop() {
  62.             switch(getKeyAction()) {
  63.                 case    KEY_DOWN:
  64.                     // Serial.println("KEY_DOWN");
  65.                     keyDownProc();
  66.                     break;
  67.                 case    KEY_UP:
  68.                     // Serial.println("KEY_UP");
  69.                     keyUpProc();
  70.                     break;
  71.                 default:
  72.                     keyNoChange();
  73.                     break;
  74.             }
  75.         }
  76.         
  77.     private:
  78.         uint8_t     BtnPin;
  79.         uint8_t     KeyDown = DEF_KEY_DOWN;
  80.         uint8_t     KeyUp = DEF_KEY_UP;

  81.         // 参数
  82.         uint16_t    EliminatingJitterMs = DEF_ELIMINATING_JITTER_MS;
  83.         uint16_t    LongClickMS = DEF_LONG_CLICK_MS;
  84.         uint16_t    LongStartMS = DEF_LONG_PRESS_START_MS;
  85.         uint16_t    LongIntervalMS = DEF_LONG_PRESS_INTERVAL_MS;
  86.         uint16_t    DblClickIntervalMS = DEF_DB_INTERVAL_MS;

  87.         // 控制变量
  88.         uint32_t    LongClickTimeOut = 0;
  89.         uint32_t    LongPressNextTimeOut = 0;
  90.         uint32_t    DblClickTimeOut = 0;
  91.         
  92.         // 计时器
  93.         uint32_t    KeyDownTimer = 0;
  94.         uint32_t    LastKeyDownTimer = 0;
  95.         uint32_t    KeyUpTimer = 0;
  96.         uint8_t     KeyStatus = DEF_KEY_UP;
  97.         bool        isDone = true;
  98.         bool        isReset = true;

  99.         // event callback function ptr
  100.         void (*on_click)() = nullptr;
  101.         void (*on_db_click)() = nullptr;
  102.         void (*on_long_click)() = nullptr;
  103.         void (*on_long_press)() = nullptr;
  104.         void (*on_key_down)() = nullptr;
  105.         void (*on_key_up)() = nullptr;

  106.         // 捕获按键动作,按下,释放,无动作
  107.         KeyAction getKeyAction() {
  108.             uint8_t gpio_v = digitalRead(BtnPin);
  109.             if(gpio_v == KeyStatus) return NO_CHANGE;
  110.             KeyStatus = gpio_v;
  111.             if(gpio_v == KeyDown) return KEY_DOWN;
  112.             else return KEY_UP;
  113.         }
  114.         // 消抖函数
  115.         bool isOutJitter(uint32_t _t) {
  116.             return (_t > KeyUpTimer + EliminatingJitterMs) && (_t > KeyDownTimer + EliminatingJitterMs);
  117.         }
  118.         // 事件结束处理
  119.         void eventEndProcess(uint32_t _t) {
  120.             LongClickTimeOut = LongPressNextTimeOut = DblClickTimeOut = _t;
  121.             isReset = true;
  122.         }
  123.         // 按下处理
  124.         void keyDownProc() {
  125.             uint32_t tmpTimer = millis();
  126.             if(isOutJitter(tmpTimer)) {
  127.                 if(on_key_down) on_key_down();
  128.                 LongClickTimeOut = tmpTimer + LongClickMS;
  129.                 LongPressNextTimeOut = tmpTimer + LongStartMS;
  130.                 LastKeyDownTimer = KeyDownTimer;
  131.                 KeyDownTimer = tmpTimer;
  132.                 isDone = false;
  133.                 isReset = false;
  134.             }
  135.         }
  136.         // 释放处理
  137.         void keyUpProc() {
  138.             uint32_t tmpTimer = millis();
  139.             if(isOutJitter(tmpTimer)) {
  140.                 if(on_key_up) on_key_up();
  141.                 KeyUpTimer = tmpTimer;
  142.                 eventEndProcess(tmpTimer);
  143.                 if(!isDone) {
  144.                     DblClickTimeOut = tmpTimer + DblClickIntervalMS;
  145.                 }
  146.                 else {
  147.                     isReset = true;
  148.                 }
  149.             }
  150.         }
  151.         // 无动作处理
  152.         void keyNoChange() {
  153.             uint32_t nowTimer = millis();
  154.             uint32_t fromKeyDown = nowTimer - KeyDownTimer;
  155.             
  156.             // 按键按下状态
  157.             if(!isReset && KeyStatus == KeyDown) {
  158.                 if(fromKeyDown < EliminatingJitterMs) return;
  159.                 if(!isDone && on_long_click && nowTimer > LongClickTimeOut) {
  160.                     isDone = true;
  161.                     on_long_click();
  162.                     eventEndProcess(nowTimer);
  163.                 }
  164.                 else if(on_long_press && nowTimer > LongPressNextTimeOut) {
  165.                     isDone = true;
  166.                     on_long_press();
  167.                     LongPressNextTimeOut += LongIntervalMS;
  168.                 }
  169.                 else if(!isDone && on_db_click && nowTimer < DblClickTimeOut) {
  170.                     isDone = true;
  171.                     DblClickTimeOut = nowTimer;
  172.                     on_db_click();
  173.                     eventEndProcess(nowTimer);
  174.                 }
  175.             }
  176.             // 按键释放状态
  177.             else {
  178.                 uint32_t fromKeyUp = nowTimer - KeyUpTimer;
  179.                 if(fromKeyUp < EliminatingJitterMs) return;
  180.                
  181.                 if(!isDone && on_click && nowTimer > DblClickTimeOut) {
  182.                     isDone = true;
  183.                     on_click();
  184.                     eventEndProcess(nowTimer);
  185.                 }
  186.             }
  187.         }
  188. };

  189. #endif
复制代码


4. 使用方法
4.1刷写程序(略)
4.2配网
上电后创建“ESP_AP”热点,手机后自动弹出HTML配网页面,或者输入192.168.10.1
输入SSID,密码和密钥;点击Save即可,如下图
Screenshot_2021-08-09-22-54-53-084_com.android.htmlviewer.jpg

界面配置如下
  1. {¨version¨¨2.0.0¨¨config¨{¨headerColor¨¨transparent¨¨headerStyle¨¨dark¨¨background¨{¨img¨¨assets/img/headerbg.jpg¨¨isFull¨«}}¨dashboard¨|{¨type¨¨btn¨¨ico¨¨fad fa-power-off¨¨mode¨Ê¨t0¨´关´¨t1¨¨文本2¨¨bg¨É¨cols¨Í¨rows¨Í¨key¨¨btn-rly¨´x´Ë´y´Ï¨speech¨|÷¨clr¨¨#076EEF¨¨lstyle¨Ë}÷¨actions¨|÷¨triggers¨|÷}
复制代码

Dingtalk_20210813222920.jpg


4.3 重置WiFi
长按按键3s,即可清除密码,重新配网


4.4 Web OTA
配网之后,正常运行时,在IE(推荐)浏览器中输入IP/Update,即可打开升级页面
注意,不知道IP的话去路由器中查看
点击“浏览”选择生成的bin文件
点击Update Firmware进行升级,升级成功有提示

Dingtalk_20210813221550.jpg


4.5 内存不够升级失败
用中转的方式解决
先刷入较小的支持OTA的固件,仅300多KB,然后再刷入正常的OTA固件
OTA代码

  1. /**
  2. /*
  3.   To upload through terminal you can use: curl -F "image=@firmware.bin" esp8266-webupdate.local/update
  4. */

  5. #include <ESP8266WebServer.h>
  6. #include <ESP8266mDNS.h>
  7. #include <ESP8266HTTPUpdateServer.h>
  8. #include <Ticker.h>

  9. const char* host = "SwitchUpdate";

  10. ESP8266WebServer httpServer(80);
  11. ESP8266HTTPUpdateServer httpUpdater;

  12. Ticker ticker;
  13. #define BLUE_LED  15
  14. #define RED_LED   13

  15. void tickerCount()
  16. {
  17.   digitalWrite(RED_LED, !digitalRead(RED_LED));
  18. }

  19. void setup(void)
  20. {
  21.   uint32_t wait = millis()+10*1000;
  22.   while(WiFi.waitForConnectResult() != WL_CONNECTED)
  23.   {
  24.     if(wait < millis())
  25.       ESP.restart();
  26.   }

  27.   MDNS.begin(host);

  28.   httpUpdater.setup(&httpServer);
  29.   httpServer.begin();

  30.   MDNS.addService("http", "tcp", 80);
  31.   pinMode(RED_LED, OUTPUT);
  32.   pinMode(BLUE_LED, OUTPUT);
  33.   digitalWrite(BLUE_LED, HIGH);
  34.   ticker.attach(1, tickerCount);
  35. }

  36. void loop(void)
  37. {
  38.   httpServer.handleClient();
  39. }
复制代码


5.注意事项
硬件分为2M和1M版本
下图是2MB版本
IMG_20210812_224326.jpg


需要根据Flash大小来配置,否则刷进去不启动,原因不明
QQ截图20210813220225.png
2MB版本可以直接OTA,不需要通过较小的OTA转


6.其他
以上全部内容打包到附件中,包括BIN文件


Blinker.rar

1011.74 KB, 下载次数: 76, 下载积分: 家元 -55

打赏

参与人数 3家元 +48 收起 理由
hydize + 20 優秀文章
kkdkj + 20 原創內容
小王是胖子 + 8

查看全部打赏

本帖被以下淘专辑推荐:

发表于 2021-8-14 10:50:55 | 显示全部楼层
本帖最后由 xljxlj 于 2021-8-14 10:52 编辑

打错太多字了吧:dizzy:
额,是浏览器自动翻译了。。。
回复 支持 1 反对 0

使用道具 举报

发表于 2021-8-14 15:42:44 | 显示全部楼层
点灯平台还是算了吧:lol: 不掏钱的平台都不好用,估计撑到最后还是涂鸦剩者为王。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-8-14 15:59:03 | 显示全部楼层
jpdd521 发表于 2021-8-14 15:42
点灯平台还是算了吧 不掏钱的平台都不好用,估计撑到最后还是涂鸦剩者为王。 ...

的确,感觉点灯的盈利模式不行,涂鸦不开放,卖模块也能赚不少
回复 支持 反对

使用道具 举报

发表于 2021-8-15 10:55:57 | 显示全部楼层
胡奚曷 发表于 2021-8-14 15:59
的确,感觉点灯的盈利模式不行,涂鸦不开放,卖模块也能赚不少

涂鸦也是开放平台啊兄弟,并且初次注册还能弄到10个激活码。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-8-15 11:00:01 | 显示全部楼层
jpdd521 发表于 2021-8-15 10:55
涂鸦也是开放平台啊兄弟,并且初次注册还能弄到10个激活码。

是吗,听说刷一次软件要7块钱
回复 支持 反对

使用道具 举报

发表于 2021-8-15 11:20:05 | 显示全部楼层
胡奚曷 发表于 2021-8-15 11:00
是吗,听说刷一次软件要7块钱

现在送开发者10个注册码,可以自己写进去,也是开放平台,方便很多了:lol:
回复 支持 反对

使用道具 举报

发表于 2021-8-15 11:43:33 | 显示全部楼层
好东西,可惜没精力折腾
回复 支持 反对

使用道具 举报

发表于 2021-8-16 09:17:51 来自手机浏览器 | 显示全部楼层
还没弄明白这是本地还是,在线 要服务器吗
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-8-16 22:40:56 | 显示全部楼层
当红不让 发表于 2021-8-16 09:17
还没弄明白这是本地还是,在线 要服务器吗

要服务器的,服务器是点灯科技提供的
回复 支持 0 反对 1

使用道具 举报

发表于 2021-8-16 23:15:15 | 显示全部楼层
楼主好,最近搜到您在老站的帖子,但我的ID不知为什么进不了老站。我最近拆了一个农行的U盾,想把U盾屏利用起来,排线上是FPC-QFG2864,想向您请教下怎样才能用起来,能传点资料给我吗?谢谢了!不好意思,没M币不能发消息,麻烦了
回复 支持 反对

使用道具 举报

发表于 2021-8-23 17:25:54 | 显示全部楼层
本帖最后由 易记 于 2021-8-23 17:27 编辑

现在都是把蛋糕做大,我不认为点灯一定会死掉,点灯免费才5个,他们也有收费服务,MQTT占资源又不多,服务成本不大的。
回复 支持 反对

使用道具 举报

发表于 2021-8-25 13:14:17 | 显示全部楼层
这个插座怎么拆开
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-8-26 14:37:10 | 显示全部楼层
kkstun 发表于 2021-8-25 13:14
这个插座怎么拆开

用有点刃的刮锡膏的工具,往缝隙里捅,基本上可以无损拆掉
里面是胶粘的,比较容易拆
回复 支持 反对

使用道具 举报

发表于 2021-8-26 23:31:13 来自手机浏览器 | 显示全部楼层
厉害,我也买了3个,想跟小爱同学连起来用
回复 支持 反对

使用道具 举报

发表于 2021-8-27 08:13:27 | 显示全部楼层
sclg80 发表于 2021-8-26 23:31
厉害,我也买了3个,想跟小爱同学连起来用

多买点平摊运费啊
回复 支持 反对

使用道具 举报

发表于 2021-8-31 07:11:11 | 显示全部楼层
刷写程序这一部分。能写的再详细一些吗?就是卡在这一步了,怎么刷都是失败?
2AE5511F-5DC5-47C5-B591-ACDAEB65EC8E.jpeg
回复 支持 反对

使用道具 举报

发表于 2021-8-31 09:37:57 | 显示全部楼层
代码有三个部分,是要合在一起吗,还是怎么弄啊?新手确实不明白
回复 支持 反对

使用道具 举报

发表于 2021-9-1 06:40:41 来自手机浏览器 | 显示全部楼层
刷机步骤不能省略,就卡在刷机步骤这里了…
另外问下,刷机后,是不是原机身上的按钮就不起作用了?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-1 08:56:47 | 显示全部楼层
hbliwww 发表于 2021-8-31 09:37
代码有三个部分,是要合在一起吗,还是怎么弄啊?新手确实不明白

三部分当然是三个文件啦,文件名都在上面
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

APP|手机版|小黑屋|关于我们|联系我们|法律条款|技术知识分享平台

闽公网安备35020502000485号

闽ICP备2021002735号-2

GMT+8, 2024-3-29 02:31 , Processed in 0.140400 second(s), 16 queries , Redis On.

Powered by Discuz!

© 2006-2023 smzj.net

快速回复 返回顶部 返回列表