esp32-real-hardware-flash
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseESP32 Real Hardware Flash + WiFi
ESP32 真实硬件烧录 + WiFi
Overview
概述
Flash firmware to a physical ESP32 over USB and verify it boots + connects WiFi. Works alongside [wokwi-mcp-testing] (sim) — this skill is for the real board.
通过USB向物理ESP32烧录固件,并验证其启动及WiFi连接情况。可与[wokwi-mcp-testing](模拟环境)配合使用——本技能针对真实开发板。
When to Use
使用场景
- First flash of a new ESP32 (PlatformIO )
pio run -t upload - Debug why upload fails to open the serial port
- Set up WiFi on real hardware (home SSID, static vs DHCP)
- Verify boot: WiFi connect + IP + web server start
- 首次烧录新ESP32(PlatformIO 命令 )
pio run -t upload - 排查上传时无法打开串口的故障
- 在真实硬件上配置WiFi(家庭网络SSID、静态IP vs DHCP)
- 验证启动流程:WiFi连接、IP获取及Web服务器启动
Key Rule: Bash tool cannot open serial O_RDWR on macOS
关键规则:macOS下Bash工具无法以O_RDWR模式打开串口
Claude's Bash tool (even with sandbox disabled) gets (EPERM) opening with — esptool/pyserial need O_RDWR, so uploads fail with "Could not open /dev/cu.usbserial-XXXX, the port doesn't exist" (esptool masks EPERM). Read-only opens (, e.g. ) succeed.
Operation not permitted/dev/cu.*O_RDWRO_RDONLYddFix: give the user the commands to run in their own terminal. Do not keep retrying from Bash.
Claude的Bash工具(即使禁用沙箱)在以模式打开时会提示「操作不被允许」(EPERM)——而esptool/pyserial需要O_RDWR模式,因此上传会失败并提示「无法打开/dev/cu.usbserial-XXXX,端口不存在」(esptool会隐藏EPERM错误)。只读模式打开(,例如命令)可成功执行。
O_RDWR/dev/cu.*O_RDONLYdd解决方法:提供命令让用户在自己的终端中运行。不要在Bash工具中反复重试。
Flash Workflow (user runs these)
烧录流程(用户执行以下命令)
bash
cd <project>
export PATH="/Users/hoang/.nvm/versions/node/v24.18.0/bin:/opt/miniconda3/bin:$PATH"
~/.platformio/penv/bin/pio run -t upload --upload-port /dev/cu.usbserial-2410Monitor boot log:
bash
~/.platformio/penv/bin/pio device monitor --port /dev/cu.usbserial-2410 --baud 115200If no log appears: tell user to press EN/RESET on the board.
bash
cd <project>
export PATH="/Users/hoang/.nvm/versions/node/v24.18.0/bin:/opt/miniconda3/bin:$PATH"
~/.platformio/penv/bin/pio run -t upload --upload-port /dev/cu.usbserial-2410监控启动日志:
bash
~/.platformio/penv/bin/pio device monitor --port /dev/cu.usbserial-2410 --baud 115200如果没有日志输出:告知用户按下开发板上的EN/RESET按键。
Identifying the Port
端口识别
- Chip on cheap dev boards is usually CH340: →
VID 0x1a86 PID 0x7523/dev/cu.usbserial-XXXX - Detect: (ignore
ls /dev/cu.*), orcu.Bluetooth-Incoming-Portfor VID/PIDsystem_profiler SPUSBDataType - Verify sees it
pio device list
- 廉价开发板通常搭载CH340芯片:→ 对应端口为
VID 0x1a86 PID 0x7523/dev/cu.usbserial-XXXX - 检测方式:执行(忽略
ls /dev/cu.*),或通过cu.Bluetooth-Incoming-Port查看VID/PIDsystem_profiler SPUSBDataType - 验证是否能识别该端口
pio device list
WiFi Config (real hardware)
WiFi配置(真实硬件)
cpp
const char* WIFI_SSID = "HOME_SSID";
const char* WIFI_PASS = "pass1234";- Credentials never committed — they sit in source for a local demo; flag before any commit
- ESP32 is 2.4GHz only — 5GHz SSID won't connect (symptom: )
WiFi connect timeout - Prefer DHCP + mDNS over static IP — name is stable, self-heals on network change, no IP conflict risk. Static IP only if mDNS fails or port-forwarding needs a fixed address
esp-light.local - Verify via serial log: expect then
WiFi connected, IP: 192.168.x.x; open browser to the IP or mDNS nameHTTP server started
cpp
const char* WIFI_SSID = "HOME_SSID";
const char* WIFI_PASS = "pass1234";- 凭证切勿提交至版本库——仅在本地演示时保留在源码中;提交前需标记提醒
- ESP32仅支持2.4GHz频段——5GHz SSID无法连接(症状:)
WiFi connect timeout - 优先使用DHCP + mDNS而非静态IP——名称稳定,网络变更时可自动恢复,无IP冲突风险。仅在mDNS失效或端口转发需要固定地址时使用静态IP
esp-light.local - 通过串口日志验证:预期输出为,随后显示
WiFi connected, IP: 192.168.x.x;在浏览器中输入该IP或mDNS名称访问HTTP server started
Common Mistakes
常见错误
| Mistake | Fix |
|---|---|
| Upload fails "port doesn't exist" from Bash | User runs the command in their own terminal (O_RDWR blocked in Bash tool) |
| No serial output after flash | Press EN/RESET; monitor may need restart |
| Wrong SSID/pass, or router is 5GHz-only |
| Committed WiFi password | Strip/guard before commit, or use a config that reads env |
| Wrong port path | |
| 错误情况 | 解决方法 |
|---|---|
| Bash工具中上传失败提示「端口不存在」 | 用户在自己的终端中执行命令(Bash工具被阻止使用O_RDWR模式) |
| 烧录后无串口输出 | 按下EN/RESET按键;可能需要重启监控工具 |
| SSID/密码错误,或路由器仅支持5GHz频段 |
| WiFi密码被提交至版本库 | 提交前移除/保护密码,或使用读取环境变量的配置方式 |
| 端口路径错误 | 使用 |