Files
led-driver/main/web.h
T
jimmyandClaude Opus 5.5 762ec338bc 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>
2026-11-11 22:34:36 +13:00

35 lines
1013 B
C

/*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_err.h"
#include "esp_http_server.h"
#ifdef __cplusplus
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);
/**
* @brief Add Access-Control-Allow-Origin for a LAN or localhost page that asked (the Origin header).
* Call before the response is sent. Other origins get no header, so the browser blocks them.
*/
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