feat: JSON API on the USB serial port for led-tool

One request per line on USB-Serial-JTAG (@api {"id","method","path","body"}),
one @api envelope back; @reboot restarts. Requests run on the httpd task
through the same dispatcher as the WebSocket, so the checks match the web UI
and never race an HTTP handler. Replies go out in chunks under a lock that log
output shares, so a reply over the TX buffer size isn't dropped and log lines
can't land inside one. The primary console moves to USB-Serial-JTAG.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Opus 5.5 committed 2026-11-11 22:34:36 +13:00
1 parent 4cd3bc7973
commit 762ec338bc
8 files changed
+266 -4

No files matched your search

+20
View File
@@ -75,6 +75,26 @@ JSON API (port 80):
| POST | `/api/wifi` | `{"ssid","password"}`: save and connect |
| GET | `/api/wifi/scan` | Visible networks |
### USB configuration (led-tool)
The JSON API above is also served on the USB serial port (`/dev/ttyACM0`, `main/usb_cfg.cpp`), so a driver can be set up without Wi-Fi. One line per request and per reply; every other line is log output:
```
@api {"id":1,"method":"GET","path":"/api/status"}
@api {"id":1,"status":200,"body":"{...}"}
@api {"id":2,"method":"POST","path":"/api/hardware","body":{"num_leds":60}}
@reboot
```
Requests run on the web server's task, with the same checks as the web UI. `led-tool` uses this automatically:
```bash
python cli.py -s
python cli.py -l 60 -o rgb --pin 10 -b 128 -n bar1
```
Open the port with DTR high and RTS low (RTS high with DTR low resets the chip).
Build and flash for the ESP32-C3:
```bash