feat: control several drivers from one web UI

- Device dropdown: All devices, this device by name, then drivers found by
  mDNS (tagged app=led-strip) and any added by hand.
- POST /api/relay: a driver calls another driver's API for the page, so the
  browser only talks to its own board. Limited to /api/*, /ota and /reboot.
- All devices sends brightness and preset plays to every device.
- Settings: sync this device's presets, order and startup to the others.
- CORS for LAN and localhost origins, and an OPTIONS handler for /ota.
- Header labels are removed; the controls keep aria-labels.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Haiku 5.5 committed 2026-11-11 02:48:48 +13:00
1 parent 4b623bb156
commit d32f3d69cf
8 files changed
+525 -11

No files matched your search

+20
View File
@@ -1,4 +1,5 @@
#include "ota.h"
#include "web.h"
#include <stdio.h>
#include <stdlib.h>
@@ -48,6 +49,7 @@ static esp_err_t fail(httpd_req_t *req, const char *status, const char *msg)
ESP_LOGE(TAG, "%s", msg);
httpd_resp_set_status(req, status);
httpd_resp_set_type(req, "application/json");
web_allow_lan_origin(req);
char buf[160];
snprintf(buf, sizeof(buf), "{\"error\":\"%s\"}", msg);
return httpd_resp_sendstr(req, buf);
@@ -125,6 +127,7 @@ static esp_err_t ota_post_handler(httpd_req_t *req)
ESP_LOGI(TAG, "update ok, rebooting");
httpd_resp_set_type(req, "application/json");
web_allow_lan_origin(req);
httpd_resp_sendstr(req, "{\"message\":\"update written, rebooting\"}");
static esp_timer_handle_t t;
@@ -151,6 +154,7 @@ static esp_err_t ota_get_handler(httpd_req_t *req)
"{\"partition\":\"%s\",\"version\":\"%s\",\"built\":\"%s %s\",\"idf\":\"%s\",\"sha\":\"%s\"}",
run ? run->label : "?", app->version, app->date, app->time, app->idf_ver, sha);
httpd_resp_set_type(req, "application/json");
web_allow_lan_origin(req);
return httpd_resp_sendstr(req, buf);
}
@@ -158,6 +162,7 @@ static esp_err_t reboot_post_handler(httpd_req_t *req)
{
ESP_LOGI(TAG, "reboot requested");
httpd_resp_set_type(req, "application/json");
web_allow_lan_origin(req);
httpd_resp_sendstr(req, "{\"message\":\"rebooting\"}");
static esp_timer_handle_t t;
@@ -170,14 +175,29 @@ static esp_err_t reboot_post_handler(httpd_req_t *req)
return ESP_OK;
}
// Browser preflight for a firmware upload from another device's page (octet-stream is not a simple request)
static esp_err_t ota_preflight_handler(httpd_req_t *req)
{
web_allow_lan_origin(req);
httpd_resp_set_hdr(req, "Access-Control-Allow-Methods", "POST");
httpd_resp_set_hdr(req, "Access-Control-Allow-Headers", "Content-Type");
httpd_resp_set_hdr(req, "Access-Control-Max-Age", "600");
httpd_resp_set_status(req, "204 No Content");
return httpd_resp_send(req, NULL, 0);
}
esp_err_t ota_register(httpd_handle_t server)
{
const httpd_uri_t post = { .uri = "/ota", .method = HTTP_POST, .handler = ota_post_handler };
const httpd_uri_t get = { .uri = "/ota", .method = HTTP_GET, .handler = ota_get_handler };
const httpd_uri_t preflight = { .uri = "/ota", .method = HTTP_OPTIONS, .handler = ota_preflight_handler };
esp_err_t err = httpd_register_uri_handler(server, &post);
if (err == ESP_OK) {
err = httpd_register_uri_handler(server, &get);
}
if (err == ESP_OK) {
err = httpd_register_uri_handler(server, &preflight);
}
const httpd_uri_t reboot = { .uri = "/reboot", .method = HTTP_POST, .handler = reboot_post_handler };
if (err == ESP_OK) {
err = httpd_register_uri_handler(server, &reboot);