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

+10
View File
@@ -10,6 +10,9 @@
extern "C" {
#endif
#define WEB_API_MSG_MAX 2048 // a request message: {"method","path","body","host"}
#define WEB_API_REPLY_MAX 8192 // a reply envelope: {"status","body"}
/** @brief Start the HTTP server on port 80 (UI and JSON API). */
esp_err_t web_start(void);
@@ -19,6 +22,13 @@ esp_err_t web_start(void);
*/
void web_allow_lan_origin(httpd_req_t *req);
/**
* @brief Run one API request without HTTP, as the WebSocket does: msg is
* {"method": "GET" or "POST", "path": "/api/...", "body": ..., "host": optional relay target}.
* out gets the envelope {"status": n, "body": "<JSON text>"}. Used by the USB config port.
*/
void web_api_call(const char *msg, char *out, size_t cap);
#ifdef __cplusplus
}
#endif