esp8266 arduino IDE WIFI Setting 的含义

本文对比了ESP8266两种不同的烧写模式:EraseFlash:SketchOnly与EraseFlash:Sketch+WiFiSetting。前者可能导致ESP8266 web server在客户端请求数据时快速断开连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用ESP8266的过程中,发现烧写的时候,
如果Option 7 不设置为 Erase Flash: Sketch +WiFi Setting 模式
只是设置为 Erase Flash : Sketch Only 模式

模式1

这里写图片描述

Compiling 'EspSignalReport' for 'NodeMCU 1.0 (ESP-12E Module)'
Program size: 294,992 bytes (used 28% of a 1,044,464 byte maximum) (7.50 secs)
Minimum Memory Usage: 36844 bytes (45% of a 81920 byte maximum)

Uploading 'EspSignalReport' to 'NodeMCU 1.0 (ESP-12E Module)' using 'COM13'
Erasing 0x4000 bytes starting at 0x003FC000
Uploading 299136 bytes from C:\Users\xxx\AppData\Local\Temp\VMBuilds\ESPSIG~1\ESP826~2\Debug/ESPSIG~1.BIN to flash at 0x00000000
................................................................................ [ 27% ]
................................................................................ [ 54% ]
................................................................................ [ 81% ]
.....................................................                            [ 100% ]
    The upload process has finished.

模式2

这里写图片描述

log为:

Compiling 'EspSignalReport' for 'NodeMCU 1.0 (ESP-12E Module)'
Program size: 294,992 bytes (used 28% of a 1,044,464 byte maximum) (3.31 secs)
Minimum Memory Usage: 36844 bytes (45% of a 81920 byte maximum)

Uploading 'EspSignalReport' to 'NodeMCU 1.0 (ESP-12E Module)' using 'COM13'
Uploading 299136 bytes from C:\Users\xxx\AppData\Local\Temp\VMBuilds\ESPSIG~1\ESP826~2\Debug/ESPSIG~1.BIN to flash at 0x00000000
................................................................................ [ 27% ]
................................................................................ [ 54% ]
................................................................................ [ 81% ]
    The upload process has finished.
.....................................................                            [ 100% ]

用模式2 这种方法烧写 ,会使 ESP8266webserver 很快的断开客户机的连接
比如客户机 http get 数据,ESP8266 如果没有及时响应返回数据,ESP8266 自己就主动的断开 连接了。

### ESP8266 Arduino OTA 更新教程 #### 准备工作 为了实现ESP8266的OTA更新,需先配置Arduino IDE环境并编写相应的代码。确保已安装ESP8266开发板支持包以及必要的库文件。 #### 设置Arduino IDE 打开Arduino IDE,在`工具>开发板>`选项下选择对应的NodeMCU型号,并确认端口设置无误。接着通过Preferences添加ESP8266额外开发板管理器URLs[^1]。 #### 安装依赖库 利用库管理器安装如下几个关键组件: - `ESP8266mDNS.h`: 实现多播域名解析服务(Multicast DNS),方便设备发现; - `ArduinoOTA.h`: 负责处理固件远程升级逻辑。 #### 示例代码展示 下面是一份简单的示例程序用于演示如何启用和执行OTA更新: ```cpp #include <ESP8266WiFi.h> #include <ESP8266mDNS.h> #include <ArduinoOTA.h> // 替换成自己的网络凭证 (SSID 和密码) const char* ssid = "your_SSID"; const char* password = "your_PASSWORD"; void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); // 设定为STA模式 WiFi.begin(ssid, password); while (WiFi.waitForConnectResult() != WL_CONNECTED) { Serial.println("Connection Failed! Rebooting..."); delay(5000); ESP.restart(); } // 启动MDNS以便于本地局域网内的主机能够访问到这台设备 if (!MDNS.begin("esp8266")){ Serial.println("Error setting up MDNS responder!"); while(1){ delay(1000); } } ArduinoOTA.setHostname("esp8266"); ArduinoOTA.onStart([](){ String type; if (ArduinoOTA.getCommand() == U_FLASH){ type = "sketch"; } else { // U_FS type = "filesystem"; } Serial.println("Start updating " + type); }); ArduinoOTA.onEnd([](){ Serial.println("\nEnd"); }); ArduinoOTA.onProgress([](unsigned int progress,unsigned int total){ Serial.printf("Progress: %u%%\r",(progress/(total/100))); }); ArduinoOTA.onError([](ota_error_t error){ Serial.printf("Error[%u]: ",error); if(error==OTA_AUTH_ERROR){Serial.println("Auth Failed");} else if(error==OTA_BEGIN_ERROR){Serial.println("Begin Failed");} else if(error==OTA_CONNECT_ERROR){Serial.println("Connect Failed");} else if(error==OTA_RECEIVE_ERROR){Serial.println("Receive Failed");} else if(error==OTA_END_ERROR){Serial.println("End Failed");} }); ArduinoOTA.begin(); Serial.println("Ready"); } void loop() { ArduinoOTA.handle(); // 处理来自客户端的请求 } ``` 此段代码实现了基本的功能框架,允许用户通过浏览器或其他HTTP客户端发起针对指定IP地址(`http://<ip address>/update`)的POST请求来完成新版本固件的推送与替换过程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值