Replace the web UI with a single-file page

The upstream jQuery page (147 KB, 3-column grid, slider values hidden,
help behind label clicks, no save feedback) is replaced by
firmware/uniclock/web/index.html: one file, no jQuery, gzipped by
web/gzip_web.py to data/index.html.gz (12 KB) before every build.

- Tabs Home / Tubes / Light / Network / System, rows with label, help
  line and control; sliders always show their value
- "Saved" / "Not saved" after each change, reverted on failure; offline
  indicator with automatic retry (the old poll stopped after one error)
- WiFi and MQTT settings only save with a Save button, then offer a
  restart; password fields are write-only
- Controls for hardware this clock lacks (alarm, radar, sensors) hidden
- Runs on sample data when opened from disk

Firmware: one serveStatic route (gzip, no-cache + ETag) replaces the
per-file routes; /getConfiguration no longer returns passwords and adds
ip, hasAlarm, hasRadar and the real cathProtMin; /getCurrentInfos adds
currentSec and mqtt state and sends "lux" instead of "lx" when there is
no sensor; /cathodeProtect and /firmwareupdate now answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-10-29 00:06:35 +01:00
1 parent ae87849e75
commit b40b5f680c
14 files changed
+724 -1661

No files matched your search

@@ -269,8 +269,7 @@ extern char tubeDriver[]; //human-readable driver name string, shown on the web
char webName[] = WEBNAME;
AsyncWebServer server(80);
#define CACHE_MAX_AGE "max-age=31536000" //maximum is: 31536000
#define CACHE_REVALIDATE "no-cache" //page.js and site.css change with web UI updates (uploadfs): don't let browsers keep an old copy
#define CACHE_REVALIDATE "no-cache" //the web UI changes with uploadfs: don't let browsers keep an old copy
#ifdef USE_WIFIMANAGER
#include <ESPAsyncWiFiManager.h>
@@ -1140,14 +1139,13 @@ void doCathodeProtect() {
cathodeProtRunning = false;
}
// Sets up the ESPAsyncWebServer instance (port 80) that backs the web admin UI: static file routes
// serve the SPA's HTML/CSS/JS straight out of SPIFFS (uploaded separately via the IDE's filesystem
// uploader from the repo's data/ folder - see file header), plus a handful of action routes
// Sets up the ESPAsyncWebServer instance (port 80) that backs the web admin UI: a static route serves
// the single-file page out of SPIFFS (uploadfs from the data/ folder), plus a handful of action routes
// (/reset, /factoryreset, /firmwareupdate, /cathodeProtect) and the JSON/form REST-ish API
// (handleConfigChanged/handleSendConfig/handleSendCurrentInfos/handleSendClockDetails, defined below).
// Optional password for the web UI (WEB_PASSWORD, and WEB_USER, default "admin", in secrets.h).
// Everything except /generate_204 (captive-portal check) and /getCurrentInfos (time and sensor
// values only) needs it; /getConfiguration returns the stored WiFi and MQTT passwords.
// values only) needs it. /getConfiguration no longer sends the stored passwords (only whether one is set).
#ifdef WEB_PASSWORD
#ifndef WEB_USER
#define WEB_USER "admin"
@@ -1160,71 +1158,6 @@ void doCathodeProtect() {
void startServer() {
DPRINTLN("Starting Async Webserver...");
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
DPRINTLN("Webserver: / -> index.html");
if(SPIFFS.exists("/index.html")) {
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/index.html", "text/html");
request->send(response);
}
else {
request->send( 204, "text/html", "File Not Found" );
DPRINTLN("/index.html not found");
}
}) WEB_AUTH;
server.on("/jquery_351.js", HTTP_GET, [](AsyncWebServerRequest * request) {
DPRINTLN("Webserver: /jquery_351.js");
if (SPIFFS.exists("/jquery_351.js")) {
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/jquery_351.js", "text/js");
response->addHeader("Cache-Control", CACHE_MAX_AGE);
request->send(response);
}
else {
request->send( 204, "text/html", "File Not Found" );
DPRINTLN("/jquery_351.js not found");
}
}) WEB_AUTH;
server.on("/jquery_360.js", HTTP_GET, [](AsyncWebServerRequest * request) {
DPRINTLN("Webserver: /jquery_360.js");
if (SPIFFS.exists("/jquery_360.js")) {
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/jquery_360.js", "text/js");
response->addHeader("Cache-Control", CACHE_MAX_AGE);
request->send(response);
}
else {
request->send( 204, "text/html", "File Not Found" );
DPRINTLN("/jquery_360.js not found");
}
}) WEB_AUTH;
server.on("/page.js", HTTP_GET, [](AsyncWebServerRequest * request) {
DPRINTLN("Webserver: /page.js");
if (SPIFFS.exists("/page.js")) {
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/page.js", "text/js");
response->addHeader("Cache-Control", CACHE_REVALIDATE);
request->send(response);
}
else {
request->send( 204, "text/html", "File Not Found" );
DPRINTLN("/page.js not found");
}
}) WEB_AUTH;
server.on("/favicon.ico", HTTP_GET, [](AsyncWebServerRequest * request) {
DPRINTLN("Webserver: /favicon.ico");
if (SPIFFS.exists("/favicon.ico")){
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/favicon.ico", "image/png");
response->addHeader("Cache-Control", CACHE_MAX_AGE);
request->send(response);
}
else {
request->send( 204, "text/html", "File Not Found" );
DPRINTLN("/favicon.ico not found");
}
}) WEB_AUTH;
server.on("/generate_204", HTTP_GET, [](AsyncWebServerRequest * request) {
DPRINTLN("Webserver: /generate_204");
AsyncWebServerResponse *response = request->beginResponse(302); //
@@ -1243,19 +1176,6 @@ void startServer() {
*/
});
//____________________________________________________________________________
server.on("/site.css", HTTP_GET, [](AsyncWebServerRequest * request) {
DPRINTLN("Webserver: /site.css");
if (SPIFFS.exists("/site.css")) {
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/site.css", "text/css");
response->addHeader("Cache-Control", CACHE_REVALIDATE);
request->send(response);
}
else {
request->send( 204, "text/html", "File Not Found" );
DPRINTLN("/site.css not found");
}
}) WEB_AUTH;
//____________________________________________________________________________
server.on("/reset", HTTP_POST, [] (AsyncWebServerRequest *request) {
DPRINTLN("/reset:");
@@ -1277,10 +1197,12 @@ void startServer() {
//____________________________________________________________________________
server.on("/firmwareupdate", HTTP_POST, [](AsyncWebServerRequest * request) {
makeFirmwareUpdate = true;
request->send(200, "text/plain", "OK"); //FIXED: no answer was sent, so the browser waited until it timed out
}) WEB_AUTH;
//____________________________________________________________________________
server.on("/cathodeProtect", HTTP_POST, [](AsyncWebServerRequest * request) {
makeCathodeProtect = true;
request->send(200, "text/plain", "OK");
}) WEB_AUTH;
@@ -1289,6 +1211,10 @@ void startServer() {
server.on("/getCurrentInfos", HTTP_GET, handleSendCurrentInfos);
server.on("/getClockDetails", HTTP_GET, handleSendClockDetails) WEB_AUTH;
wledRoutes(); //WLED JSON API for SignalRGB, without password (wled.ino)
// The web UI (data/: index.html.gz, built from web/index.html, and favicon.ico). Registered last: it
// matches every GET path, and the routes above must win. A missing file falls through to handleNotFound.
// For "/" it sends index.html.gz with Content-Encoding: gzip; no-cache + ETag makes reloads a cheap 304.
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html").setCacheControl(CACHE_REVALIDATE) WEB_AUTH;
server.onNotFound(handleNotFound);
server.begin();
@@ -1632,6 +1558,13 @@ void handleSendConfig(AsyncWebServerRequest *request) {
doc["tubeDriver"] = tubeDriver;
doc["maxDigits"] = maxDigits; //number of digits (tubes)
doc["maxBrightness"] = MAXBRIGHTNESS; //Maximum tube brightness usually 10, sometimes 12
doc["ip"] = ip.toString();
doc["hasAlarm"] = (ALARMSPEAKER_PIN >= 0); //the web page hides the alarm and presence settings without the hardware
#if (RADAR_PIN >= 0) || defined(USE_MASTER_RADAR)
doc["hasRadar"] = true;
#else
doc["hasRadar"] = false;
#endif
//Actual time and environment data
sprintf(buf, "%4d.%02d.%02d", year(), month(), day());
@@ -1717,15 +1650,20 @@ if (useTemp > 1)
#endif
doc["wifiMode"] = prm.wifiMode;
doc["wifiSsid"] = prm.wifiSsid;
doc["wifiPsw"] = prm.wifiPsw;
// Passwords are write-only: the page gets "" plus whether one is stored, and only sends a field the
// user typed in (so "" here never overwrites a stored password).
doc["wifiPsw"] = "";
doc["wifiPswSet"] = prm.wifiPsw[0] != 0;
doc["ApSsid"] = prm.ApSsid;
doc["ApPsw"] = prm.ApPsw;
doc["ApPsw"] = "";
doc["ApPswSet"] = prm.ApPsw[0] != 0;
doc["NtpServer"] = prm.NtpServer;
doc["firmware"] = prm.firmwareServer;
doc["mqttBrokerAddr"] = prm.mqttBrokerAddr;
doc["mqttBrokerUser"] = prm.mqttBrokerUser;
doc["mqttBrokerPsw"] = prm.mqttBrokerPsw;
doc["mqttBrokerPsw"] = "";
doc["mqttBrokerPswSet"] = prm.mqttBrokerPsw[0] != 0;
doc["mqttEnable"] = prm.mqttEnable;
#if defined(USE_MQTT)
doc["mqttBrokerRefresh"] = prm.mqttBrokerRefresh;
@@ -1756,9 +1694,10 @@ if (useTemp > 1)
doc["corrT1"] = prm.corrT1;
doc["corrH0"] = prm.corrH0;
doc["corrH1"] = prm.corrH1;
doc["cathProtMin"] = 3; //default value for cathProtMin slider
doc["cathProtMin"] = cathProtMin; //FIXED: was always 3, whatever was set (not stored in EEPROM: 5 after a restart)
String json;
serializeJson(doc, json);
if (doc.overflowed()) DPRINTLN("handleSendConfig: JSON document too small, fields missing!");
request->send(200, "application/json", json);
}
@@ -1792,7 +1731,7 @@ void handleSendClockDetails(AsyncWebServerRequest *request) {
// ("temperature1"/"humidity1") and legacy ("temperature"/"humidity") key names for backwards
// compatibility with older versions of the web front-end.
void handleSendCurrentInfos(AsyncWebServerRequest *request) {
StaticJsonDocument<400> doc;
StaticJsonDocument<512> doc; //400 was tight with "stalls", "mqtt" and "currentSec"
//StaticJsonDocument<512> doc;
char buf[20]; //conversion buffer
@@ -1802,6 +1741,7 @@ void handleSendCurrentInfos(AsyncWebServerRequest *request) {
doc["currentDate"] = buf;
sprintf(buf, "%02d:%02d", hour(), minute());
doc["currentTime"] = buf;
doc["currentSec"] = second(); //the web page runs its clock from this between polls
//DPRINT("useTemp:"); DPRINT(useTemp); DPRINT("useHumid:"); DPRINT(useHumid);
if (useTemp > 0) {
doc["temperature1"] = temperature[0] + prm.corrT0;
@@ -1837,8 +1777,11 @@ if (useTemp > 1)
doc["lux"] = lx;
}
else
doc["lx"] = 255;
doc["lux"] = 255; //FIXED: was "lx"
doc["rssi"] = WiFi.RSSI();
#ifdef USE_MQTT
doc["mqtt"] = !prm.mqttEnable ? 0 : mqttIsConnected() ? 2 : 1; //0 = off, 1 = not connected, 2 = connected
#endif
doc["uptime"] = millis() / 1000;
doc["heap"] = ESP.getFreeHeap();
#ifdef USE_WLED_REALTIME