feat(ui): driver settings and code updates over ESP-NOW

Settings gets a Driver tab (/settings/editor). It sends a driver its settings through PUT /devices/<id>, which now forwards name too, and runs the tools/driver_ota.py session from the browser. The firmware embeds the led-driver files and a manifest of their hashes, because crypto.subtle is unavailable over plain HTTP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Opus 5.5 committed 2026-11-04 23:51:41 +13:00
1 parent 2f0c26e9b8
commit 06953028ab
11 files changed
+421 -8

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@ It keeps profiles, zones, presets, device groups, sequences, palettes, patterns
make build # minify the web UI from web/, then build the firmware (ESP-IDF in Docker) make build # minify the web UI from web/, then build the firmware (ESP-IDF in Docker)
make flash # flash over USB make flash # flash over USB
make ota [HOST=<ip>] # update firmware (web UI included) over Ethernet, no USB (POST /ota); HOST defaults to led-controller.local make ota [HOST=<ip>] # update firmware (web UI included) over Ethernet, no USB (POST /ota); HOST defaults to led-controller.local
make ota-drivers HOST=<ip> [MAC=..] [BROADCAST=1] # push changed led-driver .py files over ESP-NOW make ota-drivers HOST=<ip> [MAC=..] [BROADCAST=1] # push changed led-driver .py files over ESP-NOW (or Settings > Driver in the web UI)
make monitor # serial console make monitor # serial console
make test # driver unit tests and the C/Python envelope cross-check make test # driver unit tests and the C/Python envelope cross-check
make test-api HOST=<ip> # HTTP API tests against a running controller (its data is restored afterwards) make test-api HOST=<ip> # HTTP API tests against a running controller (its data is restored afterwards)
+3 -2
View File
@@ -24,6 +24,7 @@ Request and response bodies are JSON (`Content-Type: application/json`) unless n
| GET | `/` | Main UI | | GET | `/` | Main UI |
| GET | `/settings/page` | Standalone settings page | | GET | `/settings/page` | Standalone settings page |
| GET | `/audio` | Live audio and beat page (level, tempo, bar position, tap) | | GET | `/audio` | Live audio and beat page (level, tempo, bar position, tap) |
| GET | `/settings/editor` | Driver settings editor: sends a driver settings (`PUT /devices/<id>`) and updates its code (`/drivers/ota`) over ESP-NOW |
| GET | `/static/<path>` | UI scripts and styles | | GET | `/static/<path>` | UI scripts and styles |
| GET | `/favicon.ico` | 204 | | GET | `/favicon.ico` | 204 |
@@ -153,7 +154,7 @@ A device is `{id: MAC, name, type: "led", transport: "espnow" | "wifi", address,
| GET | `/devices` | All devices, each with `connected` (`null` for ESP-NOW, `false` for Wi-Fi) | | GET | `/devices` | All devices, each with `connected` (`null` for ESP-NOW, `false` for Wi-Fi) |
| GET | `/devices/<id>` | One device (the id may be written with colons) | | GET | `/devices/<id>` | One device (the id may be written with colons) |
| POST | `/devices` | Create. `name` required; `mac` (or, for ESP-NOW, a MAC in `address`); `transport` `espnow` (default) or `wifi`. Reply `{"<mac>": device}`, 201; 409 for a MAC already registered | | POST | `/devices` | Create. `name` required; `mac` (or, for ESP-NOW, a MAC in `address`); `transport` `espnow` (default) or `wifi`. Reply `{"<mac>": device}`, 201; 409 for a MAC already registered |
| PUT | `/devices/<id>` | Merge fields. `name` cannot be blank, the MAC cannot change, `output_brightness` 0–255. Changing `max_brightness`, `num_leds`, `color_order`, `startup_mode` or `reversed` also sends them to the driver as `device_config` | | PUT | `/devices/<id>` | Merge fields. `name` cannot be blank, the MAC cannot change, `output_brightness` 0–255. Changing `name`, `max_brightness`, `num_leds`, `color_order`, `startup_mode` or `reversed` also sends them to the driver as `device_config` |
| DELETE | `/devices/<id>` | Delete | | DELETE | `/devices/<id>` | Delete |
| GET | `/devices/status` | Per driver: `{"last_ack_ms_ago": ms or -1, "failed_messages": n}` from the acked link | | GET | `/devices/status` | Per driver: `{"last_ack_ms_ago": ms or -1, "failed_messages": n}` from the acked link |
| POST | `/devices/ping` | Body `{"timeout_s": 0.5–30}` (default 3). Broadcasts a ping and collects replies: `{"ok", "ping_id", "timeout_s", "responses": {mac: {mac, name, rtt_ms}}, "registered": n}`. Drivers that answer are added or renamed | | POST | `/devices/ping` | Body `{"timeout_s": 0.5–30}` (default 3). Broadcasts a ping and collects replies: `{"ok", "ping_id", "timeout_s", "responses": {mac: {mac, name, rtt_ms}}, "registered": n}`. Drivers that answer are added or renamed |
@@ -270,7 +271,7 @@ On connect the controller sends `{"type": "device_tcp_snapshot", "connected_ips"
## Driver app update — `/drivers/ota` ## Driver app update — `/drivers/ota`
Pushes led-driver `.py` files to ESP-NOW drivers, one file per request; `tools/driver_ota.py` (`make ota-drivers`) runs a whole session. The wire format is in `led-driver/src/espnow_ota.py`. One request runs at a time; another gets 409. Pushes led-driver `.py` files to ESP-NOW drivers, one file per request; `tools/driver_ota.py` (`make ota-drivers`) and the editor at `/settings/editor` run a whole session. The firmware embeds the driver files from its build: `/static/driver/manifest.json` lists `{path, sha, size}` and `/static/driver/<path>` serves each. The wire format is in `led-driver/src/espnow_ota.py`. One request runs at a time; another gets 409.
| Method | Path | Description | | Method | Path | Description |
|--------|------|-------------| |--------|------|-------------|
+1 -1
View File
@@ -106,7 +106,7 @@ The preset editor:
## Settings ## Settings
**Settings** (Edit mode) holds the controller's name, the ESP-NOW channel (for reference: the controller's channel is set at build time), its mDNS **hostname** and the **static IPs** it tries on the Ethernet link (DHCP when none answers). With no DHCP server, as on a cable straight to a PC, the controller is at `192.168.4.1`; give the PC a static IP such as `192.168.4.2`. Network changes apply after a restart. Drivers are configured over USB with `led-cli` on a computer. **Settings** (Edit mode) holds the controller's name, the ESP-NOW channel (for reference: the controller's channel is set at build time), its mDNS **hostname** and the **static IPs** it tries on the Ethernet link (DHCP when none answers). With no DHCP server, as on a cable straight to a PC, the controller is at `192.168.4.1`; give the PC a static IP such as `192.168.4.2`. Network changes apply after a restart. **Driver** in Settings sends a driver its name, LED count, colour order, startup mode, maximum brightness and direction over ESP-NOW, with no cable. **Update code** there sends a driver, or all of them, the led-driver code built into the controller. `led-cli` on a computer edits a driver's whole `settings.json` over USB.
![Schematic: narrow layout with Menu and the same header actions in a dropdown.](images/help/mobile-menu.svg) ![Schematic: narrow layout with Menu and the same header actions in a dropdown.](images/help/mobile-menu.svg)
+3
View File
@@ -411,6 +411,9 @@ static esp_err_t settings_handler_inner(httpd_req_t *req)
if (n == 2 && strcmp(seg[1], "page") == 0 && req->method == HTTP_GET) { if (n == 2 && strcmp(seg[1], "page") == 0 && req->method == HTTP_GET) {
return web_send_page(req, "settings.html"); return web_send_page(req, "settings.html");
} }
if (n == 2 && strcmp(seg[1], "editor") == 0 && req->method == HTTP_GET) {
return web_send_page(req, "settings_editor.html");
}
if (n == 1 && req->method == HTTP_GET) { if (n == 1 && req->method == HTTP_GET) {
return api_json(req, "200 OK", store_settings(), false); return api_json(req, "200 OK", store_settings(), false);
} }
+1 -1
View File
@@ -151,7 +151,7 @@ static esp_err_t create_device(httpd_req_t *req)
} }
// Settings a driver keeps in its own settings.json and takes from a device_config message // Settings a driver keeps in its own settings.json and takes from a device_config message
static const char *const DEVICE_CONFIG_KEYS[] = { "max_brightness", "num_leds", "color_order", "startup_mode", "reversed" }; static const char *const DEVICE_CONFIG_KEYS[] = { "name", "max_brightness", "num_leds", "color_order", "startup_mode", "reversed" };
// The driver settings present in a device update, or NULL when it has none. Caller deletes the result. // The driver settings present in a device update, or NULL when it has none. Caller deletes the result.
static cJSON *device_config_from(const cJSON *body) static cJSON *device_config_from(const cJSON *body)
+18 -1
View File
@@ -1,3 +1,5 @@
import hashlib
import pytest import pytest
@@ -11,11 +13,26 @@ def test_favicon(c):
assert c.get("/favicon.ico").status_code == 204 assert c.get("/favicon.ico").status_code == 204
@pytest.mark.parametrize("path", ["style.css", "zones.js", "presets.js", "profiles.js", "devices.js"]) @pytest.mark.parametrize("path", ["style.css", "zones.js", "presets.js", "profiles.js", "devices.js",
"settings_editor.js"])
def test_static(c, path): def test_static(c, path):
assert c.get(f"/static/{path}").status_code == 200 assert c.get(f"/static/{path}").status_code == 200
def test_settings_editor_page(c):
resp = c.get("/settings/editor")
assert resp.status_code == 200
assert "espnow-send" in resp.text
def test_driver_files(c):
files = c.get("/static/driver/manifest.json").json()["files"]
assert any(f["path"] == "main.py" for f in files)
for f in (files[0], files[-1]):
body = c.get(f"/static/driver/{f['path']}").content
assert hashlib.sha256(body).hexdigest() == f["sha"]
def test_status_reset_reason(c): def test_status_reset_reason(c):
assert c.get("/status").json()["reset_reason"] assert c.get("/status").json()["reset_reason"]
+18 -1
View File
@@ -18,7 +18,7 @@ for f in "$SRC"/static/*; do
*) cp "$f" "$OUT/static/$b" ;; *) cp "$f" "$OUT/static/$b" ;;
esac esac
done done
for p in index settings; do for p in index settings settings_editor; do
npx --yes html-minifier-terser@7.2.0 --collapse-whitespace --remove-comments \ npx --yes html-minifier-terser@7.2.0 --collapse-whitespace --remove-comments \
--minify-css true --minify-js true -o "$OUT/$p.html" "$SRC/templates/$p.html" --minify-css true --minify-js true -o "$OUT/$p.html" "$SRC/templates/$p.html"
done done
@@ -27,6 +27,23 @@ done
npx --yes html-minifier-terser@7.2.0 --collapse-whitespace --remove-comments \ npx --yes html-minifier-terser@7.2.0 --collapse-whitespace --remove-comments \
--minify-css true --minify-js true -o "$OUT/audio.html" web/audio.html --minify-css true --minify-js true -o "$OUT/audio.html" web/audio.html
# led-driver app files and their hashes, for updating drivers from the web UI (same set as tools/driver_ota.py)
python3 - "$OUT/static/driver" <<'PY'
import hashlib, json, os, shutil, sys
sys.path.insert(0, "tools")
from driver_ota import MAX_FILE, file_set
root = sys.argv[1]
files = []
for dest, local in file_set("led-driver"):
data = open(local, "rb").read()
if len(data) > MAX_FILE:
sys.exit(f"{dest}: over {MAX_FILE} B, drivers cannot be sent it")
os.makedirs(os.path.dirname(os.path.join(root, dest)), exist_ok=True)
shutil.copy(local, os.path.join(root, dest))
files.append({"path": dest, "sha": hashlib.sha256(data).hexdigest(), "size": len(data)})
json.dump({"files": files}, open(os.path.join(root, "manifest.json"), "w"))
PY
# Ship only the .gz copies; the server sends Content-Encoding: gzip # Ship only the .gz copies; the server sends Content-Encoding: gzip
find "$OUT" -type f -exec gzip -9 -n -f {} \; find "$OUT" -type f -exec gzip -9 -n -f {} \;
find "$OUT" -name '*.gz' -exec gzip -t {} \; find "$OUT" -name '*.gz' -exec gzip -t {} \;
+28
View File
@@ -165,9 +165,36 @@ document.addEventListener('DOMContentLoaded', () => {
const addIpButton = document.getElementById('static-ip-add-btn'); const addIpButton = document.getElementById('static-ip-add-btn');
if (addIpButton) addIpButton.addEventListener('click', () => addStaticIpRow()); if (addIpButton) addIpButton.addEventListener('click', () => addStaticIpRow());
const settingsTabButtons = document.querySelectorAll('#settings-modal .settings-tab-btn');
const settingsTabPanels = document.querySelectorAll('#settings-modal .settings-tab-panel');
const ledToolIframe = document.getElementById('led-tool-iframe');
function switchSettingsTab(tabId) {
for (const btn of settingsTabButtons) {
const on = btn.getAttribute('data-settings-tab') === tabId;
btn.classList.toggle('active', on);
btn.setAttribute('aria-selected', on ? 'true' : 'false');
}
for (const panel of settingsTabPanels) {
const on = panel.getAttribute('data-settings-panel') === tabId;
panel.classList.toggle('active', on);
panel.hidden = !on;
}
settingsModal.classList.toggle('settings-modal--led-tool', tabId === 'led-tool');
if (ledToolIframe) {
// Loaded on demand, so the Controller tab costs no requests
ledToolIframe.src = tabId === 'led-tool' ? '/settings/editor' : 'about:blank';
}
}
for (const btn of settingsTabButtons) {
btn.addEventListener('click', () => switchSettingsTab(btn.getAttribute('data-settings-tab')));
}
if (settingsButton && settingsModal) { if (settingsButton && settingsModal) {
settingsButton.addEventListener('click', () => { settingsButton.addEventListener('click', () => {
settingsModal.classList.add('active'); settingsModal.classList.add('active');
switchSettingsTab('controller');
loadDeviceSettings(); loadDeviceSettings();
}); });
} }
@@ -175,6 +202,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (settingsCloseButton && settingsModal) { if (settingsCloseButton && settingsModal) {
settingsCloseButton.addEventListener('click', () => { settingsCloseButton.addEventListener('click', () => {
settingsModal.classList.remove('active'); settingsModal.classList.remove('active');
switchSettingsTab('controller');
}); });
} }
+191
View File
@@ -0,0 +1,191 @@
(function () {
const messageEl = document.getElementById('flash');
function flash(text, isError) {
if (!messageEl) return;
messageEl.textContent = text;
messageEl.className = isError ? 'flash error show' : 'flash show';
setTimeout(() => messageEl.classList.remove('show'), 5000);
}
function errorMessage(e) {
if (!e) return 'Unknown error';
if (typeof e === 'string') return e;
return e.message || String(e);
}
// ESP-NOW: PUT /devices/<id> stores the fields and sends them to the driver in one message
const espnowDevice = document.getElementById('espnow-device');
const espnowSend = document.getElementById('espnow-send');
const espnowFields = document.querySelectorAll('[data-espnow]');
let espnowDevices = {};
function showEspnowDevice() {
const dev = espnowDevices[espnowDevice.value] || {};
espnowFields.forEach((el) => {
const v = dev[el.getAttribute('data-espnow')];
el.value = v === undefined || v === null ? '' : String(v);
});
}
async function loadEspnowDevices() {
const res = await fetch('/devices');
if (!res.ok) throw new Error(`Could not list drivers (${res.status})`);
const all = await res.json();
espnowDevices = {};
espnowDevice.innerHTML = '';
for (const [id, dev] of Object.entries(all)) {
if (dev.transport !== 'espnow') continue;
espnowDevices[id] = dev;
const opt = document.createElement('option');
opt.value = id;
opt.textContent = `${dev.name || id} (${id})`;
espnowDevice.appendChild(opt);
}
espnowSend.disabled = !espnowDevice.options.length;
showEspnowDevice();
showOtaTargets();
}
function espnowChanges() {
const dev = espnowDevices[espnowDevice.value] || {};
const out = {};
espnowFields.forEach((el) => {
const key = el.getAttribute('data-espnow');
const raw = el.value.trim();
if (raw === '' || raw === String(dev[key] ?? '')) return;
if (el.type === 'number') out[key] = parseInt(raw, 10);
else if (key === 'reversed') out[key] = raw === 'true';
else out[key] = raw;
});
return out;
}
espnowDevice.addEventListener('change', showEspnowDevice);
espnowSend.addEventListener('click', async () => {
const id = espnowDevice.value;
const body = espnowChanges();
if (!Object.keys(body).length) {
flash('Nothing has changed.', true);
return;
}
espnowSend.disabled = true;
try {
const res = await fetch(`/devices/${encodeURIComponent(id)}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || `Send failed (${res.status})`);
espnowDevices[id] = data;
espnowDevice.selectedOptions[0].textContent = `${data.name || id} (${id})`;
flash(`Sent to ${data.name || id}.`, false);
} catch (e) {
flash(errorMessage(e), true);
} finally {
espnowSend.disabled = false;
}
});
// Driver code: the session tools/driver_ota.py runs, one driver at a time
const otaTarget = document.getElementById('ota-target');
const otaStart = document.getElementById('ota-start');
const otaStatus = document.getElementById('ota-status');
function showOtaTargets() {
otaTarget.innerHTML = '<option value="all">All drivers</option>';
for (const [id, dev] of Object.entries(espnowDevices)) {
const opt = document.createElement('option');
opt.value = id;
opt.textContent = `${dev.name || id} (${id})`;
otaTarget.appendChild(opt);
}
otaStart.disabled = !Object.keys(espnowDevices).length;
}
async function otaRequest(action, mac, sess, params = '', body) {
// The controller does not URL-decode, so the query goes as it is
const res = await fetch(`/drivers/ota/${action}?mac=${mac}&sess=${sess}${params}`, {
method: 'POST',
headers: body ? { 'Content-Type': 'application/octet-stream' } : {},
body,
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || `${action} failed (${res.status})`);
return data[mac] || { result: 'error', code: 'missing from reply' };
}
async function otaFile(path) {
const res = await fetch(`/static/driver/${path}`);
if (!res.ok) throw new Error(`${path}: ${res.status}`);
return res.arrayBuffer();
}
// Resolves once the driver acks the link again after its reset
async function otaWaitBack(id) {
const t0 = Date.now();
await new Promise((r) => setTimeout(r, 2000));
while (Date.now() - t0 < 30000) {
const st = await fetch('/devices/status').then((r) => r.json()).catch(() => ({}));
const age = st[id] ? st[id].last_ack_ms_ago : -1;
if (age >= 0 && age < Date.now() - t0) return true;
await new Promise((r) => setTimeout(r, 1000));
}
return false;
}
async function otaDriver(id, files, label) {
const mac = espnowDevices[id].address;
const sess = 1 + Math.floor(Math.random() * 0xffff);
let written = 0;
try {
for (let i = 0; i < files.length; i++) {
const f = files[i];
otaStatus.textContent = `${label}: ${i + 1}/${files.length} ${f.path}`;
const r = await otaRequest('file', mac, sess, `&path=${f.path}&sha=${f.sha}`, await otaFile(f.path));
if (r.result === 'error') throw new Error(`${f.path}: ${r.code}`);
if (r.result === 'written') written++;
}
} catch (e) {
await otaRequest('abort', mac, sess).catch(() => {});
throw e;
}
const r = await otaRequest('commit', mac, sess);
if (r.result !== 'ok') throw new Error(`commit: ${r.code || r.result}`);
if (!written) return `${label}: already up to date`;
otaStatus.textContent = `${label}: ${written} files written, waiting for the reset`;
const back = await otaWaitBack(id);
return `${label}: ${written} files written, ${back ? 'back online' : 'not back within 30 s'}`;
}
otaStart.addEventListener('click', async () => {
const ids = otaTarget.value === 'all' ? Object.keys(espnowDevices) : [otaTarget.value];
otaStart.disabled = true;
const done = [];
let failed = false;
try {
const res = await fetch('/static/driver/manifest.json');
if (!res.ok) throw new Error(`manifest: ${res.status}`);
const { files } = await res.json();
for (const id of ids) {
const label = espnowDevices[id].name || id;
try {
done.push(await otaDriver(id, files, label));
} catch (e) {
failed = true;
done.push(`${label}: ${errorMessage(e)}`);
}
}
} catch (e) {
failed = true;
done.push(errorMessage(e));
}
otaStatus.textContent = done.join('; ');
flash(failed ? 'Driver update failed.' : 'Driver update finished.', failed);
otaStart.disabled = false;
});
loadEspnowDevices().catch((e) => flash(e.message, true));
})();
+11 -1
View File
@@ -1073,7 +1073,7 @@
<li><strong>Settings</strong> (Edit mode): the controller's name, the ESP-NOW channel, its mDNS hostname and the static IPs it tries on the Ethernet link.</li> <li><strong>Settings</strong> (Edit mode): the controller's name, the ESP-NOW channel, its mDNS hostname and the static IPs it tries on the Ethernet link.</li>
<li>Network changes apply after the controller restarts.</li> <li>Network changes apply after the controller restarts.</li>
<li>The controller talks to the drivers over ESP-NOW itself; there is no bridge to set up.</li> <li>The controller talks to the drivers over ESP-NOW itself; there is no bridge to set up.</li>
<li>Configure a driver over USB with <code>led-cli</code> on a computer.</li> <li>Configure a driver with <strong>Driver</strong> in Settings, over ESP-NOW, or over USB with <code>led-cli</code> on a computer.</li>
</ul> </ul>
</div> </div>
@@ -1143,6 +1143,12 @@
<div id="settings-modal" class="modal"> <div id="settings-modal" class="modal">
<div class="modal-content"> <div class="modal-content">
<h2>Device Settings</h2> <h2>Device Settings</h2>
<div class="settings-tabs" role="tablist" aria-label="Settings sections">
<button type="button" class="settings-tab-btn active" role="tab" id="settings-tab-controller" data-settings-tab="controller" aria-selected="true" aria-controls="settings-panel-controller">Controller</button>
<button type="button" class="settings-tab-btn" role="tab" id="settings-tab-led-tool" data-settings-tab="led-tool" aria-selected="false" aria-controls="settings-panel-led-tool">Driver</button>
</div>
<div id="settings-panel-controller" class="settings-tab-panel active" data-settings-panel="controller" role="tabpanel" aria-labelledby="settings-tab-controller">
<p class="muted-text">Controller name, ESP-NOW channel and network.</p> <p class="muted-text">Controller name, ESP-NOW channel and network.</p>
<div id="settings-message" class="message"></div> <div id="settings-message" class="message"></div>
@@ -1188,7 +1194,11 @@
<small>Network changes apply after the controller restarts.</small> <small>Network changes apply after the controller restarts.</small>
</form> </form>
</div> </div>
</div>
<div id="settings-panel-led-tool" class="settings-tab-panel" data-settings-panel="led-tool" role="tabpanel" aria-labelledby="settings-tab-led-tool" hidden>
<iframe id="led-tool-iframe" title="LED device settings editor" src="about:blank" class="settings-led-tool-iframe"></iframe>
</div>
<div class="modal-actions"> <div class="modal-actions">
<button class="btn btn-secondary" id="settings-close-btn">Close</button> <button class="btn btn-secondary" id="settings-close-btn">Close</button>
+146
View File
@@ -0,0 +1,146 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>LED device settings</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
:root {
color-scheme: dark;
--text: #e5e7eb;
--muted: #9ca3af;
--border: #374151;
--accent: #3b82f6;
--danger: #f87171;
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: system-ui, sans-serif;
background: #0b1020;
color: var(--text);
padding: 1rem;
}
h1 { font-size: 1.15rem; margin: 0 0 0.35rem; }
.muted { color: var(--muted); font-size: 0.9rem; margin-bottom: 1rem; }
.card {
border: 1px solid var(--border);
border-radius: 8px;
padding: 1rem;
margin-bottom: 1rem;
background: #111827;
}
label { display: block; font-size: 0.85rem; margin-bottom: 0.25rem; color: var(--muted); }
input, select, textarea {
width: 100%;
padding: 0.5rem;
border-radius: 4px;
border: 1px solid var(--border);
background: #1f2937;
color: var(--text);
margin-bottom: 0.65rem;
}
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 10rem; }
.btn {
padding: 0.45rem 0.85rem;
border: none;
border-radius: 4px;
cursor: pointer;
background: #4b5563;
color: #fff;
font-size: 0.9rem;
}
.btn-primary { background: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
gap: 0 0.5rem;
}
#status { font-size: 0.85rem; margin-top: 0.5rem; }
#status.error { color: var(--danger); }
.flash {
display: none;
padding: 0.5rem 0.75rem;
border-radius: 4px;
margin-bottom: 0.75rem;
background: #14532d;
color: #86efac;
}
.flash.error { background: #5e1b1b; color: #fca5a5; }
.flash.show { display: block; }
[hidden] { display: none !important; }
</style>
</head>
<body>
<h1>Device settings</h1>
<div id="flash" class="flash"></div>
<div class="card" id="espnow-wrap">
<h2 style="font-size:1rem;margin:0 0 0.5rem;">Over ESP-NOW</h2>
<p class="muted">Sent to the driver through the controller, no cable. Blank fields stay as they are on the driver.</p>
<label for="espnow-device">Driver</label>
<select id="espnow-device"></select>
<div class="grid">
<div>
<label for="espnow-name">Name</label>
<input id="espnow-name" data-espnow="name" type="text" />
</div>
<div>
<label for="espnow-num-leds">Num LEDs</label>
<input id="espnow-num-leds" data-espnow="num_leds" type="number" min="1" max="2048" />
</div>
<div>
<label for="espnow-color-order">Colour order</label>
<select id="espnow-color-order" data-espnow="color_order">
<option value=""></option>
<option value="rgb">RGB</option>
<option value="rbg">RBG</option>
<option value="grb">GRB</option>
<option value="gbr">GBR</option>
<option value="brg">BRG</option>
<option value="bgr">BGR</option>
</select>
</div>
<div>
<label for="espnow-startup-mode">Startup mode</label>
<select id="espnow-startup-mode" data-espnow="startup_mode">
<option value=""></option>
<option value="default">Default preset</option>
<option value="last">Last preset</option>
<option value="off">Off</option>
</select>
</div>
<div>
<label for="espnow-max-brightness">Max brightness</label>
<input id="espnow-max-brightness" data-espnow="max_brightness" type="number" min="0" max="255" />
</div>
<div>
<label for="espnow-reversed">Direction</label>
<select id="espnow-reversed" data-espnow="reversed">
<option value=""></option>
<option value="false">Normal</option>
<option value="true">Reversed</option>
</select>
</div>
</div>
<div class="row" style="margin-top:0.75rem;">
<button type="button" class="btn btn-primary" id="espnow-send">Send to driver</button>
</div>
</div>
<div class="card" id="ota-wrap">
<h2 style="font-size:1rem;margin:0 0 0.5rem;">Update driver code over ESP-NOW</h2>
<p class="muted">Sends the led-driver files built into this controller. Drivers skip files they already have, and reset if anything changed. Keep this page open until it finishes.</p>
<label for="ota-target">Update</label>
<select id="ota-target"></select>
<div class="row" style="margin-top:0.75rem;">
<button type="button" class="btn btn-primary" id="ota-start">Update code</button>
</div>
<p id="ota-status" class="muted"></p>
</div>
<script src="/static/settings_editor.js"></script>
</body>
</html>