feat(v2): move web UI into v2, remove legacy MicroPython app

Move the web assets and templates under v2/web, drop the old src/, lib/
and scripts, and update firmware, tools, docs and db files. Add the audio
page, LED test scripts and VPN autoconnect script.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Sonnet 5.5 committed 2026-11-02 20:30:02 +13:00
1 parent 6c16998691
commit 71bd320661
193 files changed
+5605 -18860

No files matched your search

+26 -20
View File
@@ -1,19 +1,16 @@
#!/usr/bin/env bash
# Minify and gzip the web UI into v2/www_dist for the `www` LittleFS partition.
# Usage: tools/build_web.sh (needs node/npx; WWW_MAX = partition size in bytes)
# Minify and gzip the web UI into v2/www_dist and pack it into www_dist/www.pack, which the
# firmware embeds (main/CMakeLists.txt). Usage: tools/build_web.sh (needs node/npx; WWW_MAX = size limit in bytes)
set -euo pipefail
cd "$(dirname "$0")/.."
SRC=../src
SRC=web
OUT=www_dist
MAX=${WWW_MAX:-1048576}
MAX=${WWW_MAX:-524288}
rm -rf "$OUT"; mkdir -p "$OUT/static"
# Legacy files the v2 UI does not load
SKIP=" app.js main.js rgb-slider.js styles.css "
for f in "$SRC"/static/*; do
[[ -f $f ]] || continue
b=$(basename "$f"); [[ $SKIP == *" $b "* ]] && continue
b=$(basename "$f")
case $b in
*.min.js) cp "$f" "$OUT/static/$b" ;;
*.js|*.css) npx --yes esbuild@0.25.0 "$f" --minify --target=es2019 --legal-comments=none \
@@ -21,20 +18,10 @@ for f in "$SRC"/static/*; do
*) cp "$f" "$OUT/static/$b" ;;
esac
done
# The Pi does not serve /audio, so the Audio menu entries are added for this build only
# (desktop button row and the mobile dropdown, both just before Help).
tmp=$(mktemp -d)
sed -e "s|<button class=\"btn btn-secondary\" id=\"help-btn\">Help</button>|<button class=\"btn btn-secondary\" id=\"audio-btn\" onclick=\"location.href='/audio'\">Audio</button>\n&|" \
-e "s|<button type=\"button\" data-target=\"help-btn\">Help</button>|<button type=\"button\" data-target=\"audio-btn\">Audio</button>\n&|" \
"$SRC/templates/index.html" > "$tmp/index.html"
cp "$SRC/templates/settings.html" "$tmp/settings.html"
grep -q 'id="audio-btn"' "$tmp/index.html" && [ "$(grep -c 'audio-btn' "$tmp/index.html")" -eq 2 ] \
|| { echo "ERROR: could not add the Audio menu entries to index.html" >&2; exit 1; }
for p in index settings; do
npx --yes html-minifier-terser@7.2.0 --collapse-whitespace --remove-comments \
--minify-css true --minify-js true -o "$OUT/$p.html" "$tmp/$p.html"
--minify-css true --minify-js true -o "$OUT/$p.html" "$SRC/templates/$p.html"
done
rm -rf "$tmp"
# Live audio and beat page (served at /audio)
npx --yes html-minifier-terser@7.2.0 --collapse-whitespace --remove-comments \
@@ -46,4 +33,23 @@ find "$OUT" -name '*.gz' -exec gzip -t {} \;
total=$(find "$OUT" -name '*.gz' -printf '%s\n' | paste -sd+ | bc)
echo "www_dist: $(find "$OUT" -name '*.gz' | wc -l) files, $total bytes (limit $MAX)"
(( total <= MAX )) || { echo "ERROR: web UI exceeds www partition" >&2; exit 1; }
(( total <= MAX )) || { echo "ERROR: web UI exceeds the size limit" >&2; exit 1; }
# One blob for the firmware: "WWW1", then per file u16 name length, u32 data length, name (no .gz),
# data; a zero name length ends it. Little-endian, read by main/web.c.
python3 - "$OUT" <<'PY'
import os, struct, sys
root = sys.argv[1]
out = bytearray(b"WWW1")
for dirpath, _, names in sorted(os.walk(root)):
for n in sorted(names):
if not n.endswith(".gz"):
continue
full = os.path.join(dirpath, n)
name = os.path.relpath(full, root)[:-3].encode()
data = open(full, "rb").read()
out += struct.pack("<HI", len(name), len(data)) + name + data
out += struct.pack("<H", 0)
open(os.path.join(root, "www.pack"), "wb").write(out)
print("www.pack: %d bytes" % len(out))
PY
+44 -15
View File
@@ -1,26 +1,55 @@
#!/usr/bin/env python3
"""Upload a firmware image to the controller over Ethernet.
"""Upload the firmware (which includes the web UI) to the controller over Ethernet.
ota.py <host> [build/led_controller_v2.bin]
ota.py <host> [firmware.bin]
Default is build/led_controller_v2.bin next to this script. The board reboots into the new image.
"""
import http.client
import json
import os
import sys
import time
host = sys.argv[1] if len(sys.argv) > 1 else sys.exit(__doc__)
path = sys.argv[2] if len(sys.argv) > 2 else os.path.join(os.path.dirname(__file__), "..", "build", "led_controller_v2.bin")
size = os.path.getsize(path)
build = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "build")
fw = sys.argv[2] if len(sys.argv) > 2 else os.path.join(build, "led_controller_v2.bin")
conn = http.client.HTTPConnection(host, 80, timeout=60)
conn.request("GET", "/ota")
print("running:", conn.getresponse().read().decode())
print(f"uploading {path} ({size} bytes)")
with open(path, "rb") as f:
conn.request("POST", "/ota", body=f, headers={"Content-Length": str(size),
"Content-Type": "application/octet-stream"})
r = conn.getresponse()
body = r.read().decode()
print(r.status, body)
sys.exit(0 if r.status == 200 else 1)
def info():
try:
c = http.client.HTTPConnection(host, 80, timeout=5)
c.request("GET", "/ota")
r = c.getresponse()
return json.loads(r.read().decode()) if r.status == 200 else None
except (OSError, ValueError):
return None
def upload(path, url):
size = os.path.getsize(path)
print(f"uploading {path} ({size} bytes) to {url}")
c = http.client.HTTPConnection(host, 80, timeout=120)
with open(path, "rb") as f:
c.request("POST", url, body=f, headers={"Content-Length": str(size),
"Content-Type": "application/octet-stream"})
r = c.getresponse()
body = r.read().decode()
print(r.status, body)
if r.status != 200:
sys.exit(1)
time.sleep(3)
for _ in range(30):
i = info()
if i:
print("back up on", i["partition"])
return
time.sleep(1)
sys.exit("controller did not come back within 30 s")
before = info()
print("running:", before)
if before is None:
sys.exit("no OTA endpoint (is this the v2 controller?)")
upload(fw, "/ota")