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>
647 lines
36 KiB
HTML
647 lines
36 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<meta name="theme-color" content="#0e0c0b">
|
||
<title>Nixie Clock</title>
|
||
<link rel="icon" href="favicon.ico">
|
||
<!-- Web UI for ESP_UniClock on the RetroModding NixieIN12v2 clock. Source file: firmware/uniclock/web/.
|
||
The build gzips it to data/index.html.gz (gzip_web.py). Opened from disk or localhost it runs on
|
||
sample data and only logs what it would save. -->
|
||
<style>
|
||
:root{--bg:#0e0c0b;--card:#181514;--card2:#221e1b;--line:#2e2825;--text:#ece5de;--muted:#978d85;
|
||
--glow:#ff8a3d;--glow2:#ffb47a;--dim:rgba(255,138,61,.15);--ok:#4cc38a;--warn:#f2b84b;--bad:#ef5b5b}
|
||
*{box-sizing:border-box}
|
||
html{background:var(--bg);color:var(--text);font:15px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;-webkit-text-size-adjust:100%}
|
||
body{margin:0;min-height:100vh;background:radial-gradient(900px 420px at 50% -180px,#2b1a0e 0,transparent 70%)}
|
||
[hidden]{display:none!important}
|
||
.wrap{max-width:760px;margin:0 auto;padding:0 14px}
|
||
.muted{color:var(--muted)}
|
||
header.wrap{padding:24px 14px 12px;text-align:center}
|
||
.tubes{display:inline-flex;gap:8px;align-items:center;transition:opacity .3s}
|
||
.tubes.dark{opacity:.35}
|
||
.tube{width:54px;height:84px;border-radius:26px 26px 10px 10px;background:linear-gradient(#1f1a17,#110e0c);
|
||
border:1px solid #3b312b;box-shadow:inset 0 0 18px rgba(255,140,60,.07);display:flex;align-items:center;
|
||
justify-content:center;font:200 60px/1 "Segoe UI","Helvetica Neue",Helvetica,Arial,sans-serif;color:var(--glow2);
|
||
text-shadow:0 0 5px var(--glow),0 0 16px rgba(255,120,40,.75),0 0 34px rgba(255,100,20,.45)}
|
||
.tube.off{color:transparent;text-shadow:none}
|
||
.neon{display:flex;flex-direction:column;gap:18px}
|
||
.neon i{width:9px;height:9px;border-radius:50%;background:#ff7a2e;box-shadow:0 0 6px #ff7a2e,0 0 14px rgba(255,110,40,.8)}
|
||
.neon.off i{background:#3a2a20;box-shadow:none}
|
||
.secs{font-size:15px;color:var(--muted);align-self:flex-end;font-variant-numeric:tabular-nums;width:22px}
|
||
.date{margin-top:10px;color:var(--muted)}
|
||
.name{font-weight:600;margin-top:2px}
|
||
.chips{display:flex;flex-wrap:wrap;gap:6px;justify-content:center;margin-top:12px;min-height:24px}
|
||
.chip{font-size:12.5px;padding:3px 10px;border-radius:99px;background:var(--card2);border:1px solid var(--line);color:var(--muted)}
|
||
.chip::before{content:"";display:inline-block;width:7px;height:7px;border-radius:50%;background:currentColor;margin-right:6px;vertical-align:1px}
|
||
.chip.ok{color:var(--ok)}.chip.warn{color:var(--warn)}.chip.bad{color:var(--bad)}
|
||
nav{position:sticky;top:0;z-index:5;background:rgba(14,12,11,.93);backdrop-filter:blur(6px);border-bottom:1px solid var(--line)}
|
||
nav .wrap{display:flex;overflow-x:auto}
|
||
nav button{flex:1 0 auto;background:none;border:0;border-bottom:2px solid transparent;color:var(--muted);font:inherit;font-weight:600;padding:12px 10px;cursor:pointer}
|
||
nav button:hover{color:var(--text)}
|
||
nav button[aria-selected=true]{color:var(--glow);border-color:var(--glow)}
|
||
main{padding:16px 0 30px}
|
||
main>section{display:none}main>section.on{display:block}
|
||
.card{background:var(--card);border:1px solid var(--line);border-radius:12px;margin-bottom:14px;overflow:hidden}
|
||
.card h2{margin:0;padding:13px 16px 5px;font-size:12.5px;text-transform:uppercase;letter-spacing:.08em;color:var(--glow)}
|
||
.row{display:flex;align-items:center;gap:14px;padding:11px 16px;border-top:1px solid var(--line)}
|
||
.row.first{border-top:0}
|
||
.lbl{flex:1;min-width:0}
|
||
.lbl label,.lbl b{display:block;font-weight:500}
|
||
.lbl small{display:block;color:var(--muted);font-size:12.5px;margin-top:1px}
|
||
.ctl{flex:0 0 auto;display:flex;align-items:center;gap:10px;justify-content:flex-end}
|
||
.ctl.wide{flex:0 1 320px;width:320px}
|
||
.val{font-variant-numeric:tabular-nums;color:var(--text);text-align:right}
|
||
output{min-width:86px;white-space:nowrap;text-align:right;font-variant-numeric:tabular-nums;color:var(--glow2)}
|
||
.sw{appearance:none;-webkit-appearance:none;width:46px;height:26px;border-radius:99px;background:#3d3531;position:relative;cursor:pointer;transition:background .2s;margin:0;flex:none}
|
||
.sw::after{content:"";position:absolute;top:3px;left:3px;width:20px;height:20px;border-radius:50%;background:#d2c9c2;transition:left .2s}
|
||
.sw:checked{background:var(--glow)}.sw:checked::after{left:23px;background:#fff}
|
||
input[type=range]{-webkit-appearance:none;appearance:none;width:100%;height:6px;border-radius:9px;margin:0;cursor:pointer;
|
||
background:linear-gradient(90deg,var(--glow) var(--p,0%),#3d3531 var(--p,0%))}
|
||
input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:20px;height:20px;border-radius:50%;background:var(--glow);border:3px solid #fff1e6}
|
||
input[type=range]::-moz-range-thumb{width:15px;height:15px;border-radius:50%;background:var(--glow);border:3px solid #fff1e6}
|
||
input[type=range].hue::-webkit-slider-thumb{background:transparent;border-color:#fff;box-shadow:0 0 0 1px #000}
|
||
input[type=range].hue::-moz-range-thumb{background:transparent;border-color:#fff}
|
||
.swatch{width:26px;height:26px;border-radius:50%;flex:none;border:2px solid #fff3;box-shadow:0 0 12px currentColor}
|
||
select,input[type=text],input[type=password],input[type=time],input[type=number]{width:100%;background:var(--card2);color:var(--text);
|
||
border:1px solid var(--line);border-radius:8px;padding:8px 10px;font:inherit;outline:0;color-scheme:dark}
|
||
select:focus,input:focus-visible{border-color:var(--glow)}
|
||
input[type=time]{width:auto}
|
||
input.num{width:64px;text-align:center}
|
||
.pw{position:relative;width:100%}.pw input{padding-right:58px}
|
||
.pw button{position:absolute;right:4px;top:4px;bottom:4px;background:none;border:0;color:var(--muted);font:inherit;font-size:12.5px;cursor:pointer}
|
||
.seg{display:inline-flex;border:1px solid var(--line);border-radius:9px;overflow:hidden}
|
||
.seg button{background:var(--card2);border:0;color:var(--muted);padding:7px 13px;font:inherit;cursor:pointer}
|
||
.seg button+button{border-left:1px solid var(--line)}
|
||
.seg button.on{background:var(--dim);color:var(--glow)}
|
||
.btn{background:var(--card2);border:1px solid var(--line);color:var(--text);padding:8px 16px;border-radius:9px;font:inherit;font-weight:600;cursor:pointer;white-space:nowrap}
|
||
.btn:hover{border-color:var(--muted)}
|
||
.btn.pri{background:var(--glow);border-color:var(--glow);color:#1c0e04}
|
||
.btn.danger{color:var(--bad);border-color:rgba(239,91,91,.45)}
|
||
.btn.sm{padding:5px 10px;font-size:13px}
|
||
.acts{display:flex;gap:10px;align-items:center;justify-content:flex-end;padding:11px 16px;border-top:1px solid var(--line);background:var(--card2)}
|
||
.acts span{margin-right:auto;color:var(--warn);font-size:13px}
|
||
.details{padding:12px 16px;font:12.5px/1.6 ui-monospace,Consolas,monospace;color:var(--muted);border-top:1px solid var(--line);overflow-x:auto}
|
||
.details br:first-child,.details br:first-child+br{display:none}
|
||
#msg{padding:40px 0;text-align:center;color:var(--muted)}
|
||
#toast{position:fixed;left:50%;bottom:22px;transform:translate(-50%,20px);opacity:0;transition:.25s;pointer-events:none;z-index:20;
|
||
background:#2a2421;border:1px solid var(--line);padding:9px 16px;border-radius:9px;box-shadow:0 6px 24px #0008}
|
||
#toast.on{opacity:1;transform:translate(-50%,0)}#toast.err{border-color:var(--bad);color:#ffc9c9}
|
||
#overlay{position:fixed;inset:0;background:#0e0c0bee;z-index:30;display:flex;align-items:center;justify-content:center;text-align:center;padding:20px}
|
||
#overlay div{max-width:420px}#overlay b{display:block;font-size:20px;margin-bottom:8px;color:var(--glow)}
|
||
footer{text-align:center;color:var(--muted);font-size:12.5px;padding:0 0 30px}
|
||
footer a{color:var(--muted)}
|
||
@media (max-width:560px){
|
||
.row{flex-wrap:wrap}.ctl.wide{flex:1 1 100%;width:100%}
|
||
.tube{width:42px;height:68px;font-size:46px;border-radius:20px 20px 8px 8px}.tubes{gap:6px}.neon{gap:14px}
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<header class="wrap">
|
||
<div id="tubes" class="tubes"></div>
|
||
<div id="date" class="date"> </div>
|
||
<div id="name" class="name"></div>
|
||
<div id="chips" class="chips"></div>
|
||
</header>
|
||
<nav><div class="wrap" id="tabs" role="tablist"></div></nav>
|
||
<main class="wrap" id="main"><div id="msg">Loading…</div></main>
|
||
<footer class="wrap">
|
||
© 2020-22 Peter Gautier · <a href="https://github.com/gpeter62/ESP_UniClock" target="_blank">ESP_UniClock</a><br>
|
||
Modified by Claude for the RetroModding NixieIN12v2 clock · <a href="https://mangavalk.com/mangavalk/nixie-clock" target="_blank">mangavalk.com/mangavalk/nixie-clock</a>
|
||
</footer>
|
||
<div id="toast"></div>
|
||
<div id="overlay" hidden><div><b id="ovT"></b><span id="ovM" class="muted"></span></div></div>
|
||
<script>
|
||
"use strict";
|
||
const TEST = location.protocol == "file:" || /^(localhost|127\.0\.0\.1)$/.test(location.hostname);
|
||
const $ = s => document.querySelector(s);
|
||
const pad = n => String(n).padStart(2, "0");
|
||
let cfg = {}, online = true;
|
||
|
||
// Sample data for TEST mode, in the format /getConfiguration and /getCurrentInfos send.
|
||
const SAMPLE = {
|
||
version: "IN-12 Nixie Clock", FW: "fw90", tubeDriver: "NIXIE595_MULTIPLEX", maxDigits: 4, maxBrightness: 100,
|
||
currentDate: "2026.10.28", currentTime: "21:47", currentSec: 12, ip: "10.1.1.97",
|
||
temperature: 255, temperature2: 255, humidity: 255, humidity2: 255, pressure: 255, lux: 41, rssi: -58,
|
||
uptime: 93780, heap: 21456, mqtt: 2, wledLive: false, hasAlarm: false, hasRadar: false,
|
||
utc_offset: 1, enableDST: true, set12_24: true, showZero: true, enableBlink: true, enableDoubleBlink: false, interval: 15,
|
||
enableAutoShutoff: true, dayTime: "07:00", nightTime: "22:30", dayBright: 72, nightBright: 10, manualOverride: false,
|
||
animMode: 6, alarmEnable: false, alarmTime: "06:30", alarmPeriod: 15, enableRadar: false, radarTimeout: 5,
|
||
rgbEffect: 1, rgbBrightness: 120, rgbFixColor: 30, rgbSpeed: 50, rgbDir: false, rgbMinBrightness: 8,
|
||
wledEnable: true, wledDarkWithTubes: true, wledUseBrightness: true,
|
||
wifiMode: true, wifiSsid: "dlink-iot", wifiPsw: "", wifiPswSet: true, ApSsid: "UNICLOCK", ApPsw: "", ApPswSet: false,
|
||
NtpServer: "pool.ntp.org", firmware: "", mqttBrokerAddr: "10.1.1.175", mqttBrokerUser: "mqtt", mqttBrokerPsw: "",
|
||
mqttBrokerPswSet: true, mqttEnable: true, mqttBrokerRefresh: 30, dateMode: 0, dateRepeatMin: 3, tempRepeatMin: 1,
|
||
tempCF: false, enableTimeDisplay: true, dateStart: 45, dateEnd: 50, tempStart: 35, tempEnd: 40, humidStart: 40,
|
||
humidEnd: 45, enableAutoDim: true, corrT0: 0, corrT1: 0, corrH0: 0, corrH1: 0, cathProtMin: 5
|
||
};
|
||
const SAMPLE_DETAILS = "<br><br><strong>FirmwareID:fw90<br> Tube driver:NIXIE595_MULTIPLEX<br> Mac:30:83:98:99:BF:DE</strong><br>MAXBRIGHTNESS:100<br>Used pins: 12 NEOPIXEL_PIN, 13 SPI MOSI, 14 SPI SCK, 15 PIN_LATCH, A0 LIGHT_SENSOR_PIN<br>";
|
||
|
||
// ---------- talking to the clock ----------
|
||
function timeout(ms) { const c = new AbortController(); setTimeout(() => c.abort(), ms); return c.signal; }
|
||
async function getJSON(url) {
|
||
if (TEST) {
|
||
const t = new Date();
|
||
return url == "/getConfiguration" ? { ...SAMPLE } : { currentDate: SAMPLE.currentDate, currentTime: pad(t.getHours()) + ":" +
|
||
pad(t.getMinutes()), currentSec: t.getSeconds(), lux: 30 + (t.getSeconds() % 20), rssi: -58, uptime: SAMPLE.uptime += 5,
|
||
heap: 21456, mqtt: 2, wledLive: false };
|
||
}
|
||
const r = await fetch(url, { signal: timeout(6000), cache: "no-store" });
|
||
if (!r.ok) throw Error("HTTP " + r.status);
|
||
return r.json();
|
||
}
|
||
let queue = Promise.resolve(); // one request at a time: the ESP8266 writes its EEPROM on every setting
|
||
function post(url, data) {
|
||
const p = queue.then(() => TEST ? (console.log("POST", url, data || ""), { ok: true, status: 200 })
|
||
: fetch(url, { method: "POST", body: new URLSearchParams(data || {}), signal: timeout(8000) }));
|
||
queue = p.catch(() => {});
|
||
return p;
|
||
}
|
||
// dayTime/nightTime/alarmTime are stored as two settings each
|
||
const expand = (k, v) => /Time$/.test(k) ? [[k + "Hours", +v.split(":")[0]], [k + "Minutes", +v.split(":")[1]]] : [[k, v]];
|
||
async function saveAll(pairs) {
|
||
try {
|
||
for (const [k, v] of pairs) {
|
||
const r = await post("/saveSetting", { key: k, value: String(v) });
|
||
if (!r.ok) throw Error(r.status == 404 ? "the clock doesn't know '" + k + "'" : "HTTP " + r.status);
|
||
}
|
||
toast("Saved");
|
||
return true;
|
||
} catch (e) {
|
||
toast("Not saved: " + (e.name == "AbortError" ? "no answer from the clock" : e.message), true);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
// ---------- formatting ----------
|
||
const val = x => typeof x == "function" ? x() : x;
|
||
const has = k => cfg[k] !== undefined && cfg[k] != 255;
|
||
const hasTemp = () => has("temperature") || has("temperature2");
|
||
const opts = o => val(o).map((x, i) => Array.isArray(x) ? x : [i, x]);
|
||
const fmtB = v => v == 0 ? "off" : cfg.maxBrightness == 100 ? v + "%" : v + " / " + cfg.maxBrightness;
|
||
const fmtPct = v => Math.round(v * 100 / 255) + "%";
|
||
const fmtMin = (v, zero) => v == 0 ? zero : "every " + v + " min";
|
||
const fmtT = v => cfg.tempCF ? (v * 1.8 + 32).toFixed(1) + " °F" : (+v).toFixed(1) + " °C";
|
||
function fmtUp(s) {
|
||
const d = Math.floor(s / 86400), h = Math.floor(s / 3600) % 24, m = Math.floor(s / 60) % 60;
|
||
return d ? d + " d " + h + " h" : h ? h + " h " + m + " min" : m + " min";
|
||
}
|
||
function fmtDate(t) {
|
||
const d = pad(t.getDate()), m = pad(t.getMonth() + 1), y = t.getFullYear();
|
||
const s = cfg.dateMode == 1 ? m + "/" + d + "/" + y : cfg.dateMode == 2 ? y + "/" + m + "/" + d : d + "/" + m + "/" + y;
|
||
return t.toLocaleDateString("en", { weekday: "long" }) + " " + s;
|
||
}
|
||
// Same colour wheel as WheelRaw() in z_neopixel.ino; 192 is white
|
||
function wheel(p) {
|
||
if (p == 192) return "rgb(255,255,255)";
|
||
p = 255 - p;
|
||
const c = p < 85 ? [255 - p * 3, 0, p * 3] : p < 170 ? [0, (p - 85) * 3, 255 - (p - 85) * 3] : [(p - 170) * 3, 255 - (p - 170) * 3, 0];
|
||
return "rgb(" + c + ")";
|
||
}
|
||
const HUE_BG = "linear-gradient(90deg," + Array.from({ length: 18 }, (_, i) => wheel(Math.min(255, i * 15) == 192 ? 191 : Math.min(255, i * 15))) + ")";
|
||
|
||
// ---------- what is on the page ----------
|
||
// Row types: sw (switch), range, hue, select, seg (segmented buttons), time, text, pass, pair (two 0..59
|
||
// fields), info (read-only), btn, html. k = setting key, l = label, h = help (text or function),
|
||
// show = only shown when it returns true, inv = switch shows the inverse of the setting.
|
||
const ANIM = ["Off", "Count up", "Count down", "Shift right", "Shift left", "Transition", "Random (1–5)", "Random (1–4)"];
|
||
const FX = ["Off", "Fixed colour", "Rainbow flow", "Rainbow stepper", "Colour dimmer", "Colour changer", "Colour flow",
|
||
"Colour flow, random", "Colour flow, random per tube", "Random per tube", "Knight Rider"];
|
||
const ZONES = Array.from({ length: 27 }, (_, i) => [i - 12, "UTC" + (i < 12 ? "−" : "+") + pad(Math.abs(i - 12)) + ":00"]);
|
||
const hasRGB = () => cfg.rgbEffect != 255;
|
||
const fxOn = () => cfg.rgbEffect > 0;
|
||
const fxAnim = () => cfg.rgbEffect > 1;
|
||
|
||
const R = {
|
||
tubes: { t: "sw", k: "manualOverride", inv: 1, l: "Tubes", h: "Switch the display on or off" },
|
||
autoDim: { t: "sw", k: "enableAutoDim", l: "Auto dim", h: () => has("lux") ? "Follows the light sensor, now " + cfg.lux + " lux" : "Follows the light sensor" },
|
||
dayBright: { t: "range", k: "dayBright", l: "Day brightness", min: 1, max: () => cfg.maxBrightness, f: fmtB },
|
||
effect: { t: "select", k: "rgbEffect", l: "Backlight", o: FX },
|
||
colour: { t: "hue", k: "rgbFixColor", l: "Colour", show: () => cfg.rgbEffect == 1 },
|
||
rgbBright: { t: "range", k: "rgbBrightness", l: "Backlight brightness", min: () => cfg.rgbMinBrightness || 0, max: 255, f: fmtPct, show: fxOn },
|
||
cathode: { t: "btn", l: "Cathode protection", h: () => "Cycles every digit for " + cfg.cathProtMin + " min to keep the tubes healthy", b: "Run now", a: runCathode }
|
||
};
|
||
|
||
const PAGES = [
|
||
{ id: "home", l: "Home", cards: [
|
||
{ l: "Quick controls", rows: [R.tubes, R.autoDim, R.dayBright, { ...R.effect, show: hasRGB }, R.colour, R.rgbBright] },
|
||
{ l: "Sensors", show: () => hasTemp() || has("humidity") || has("pressure"), rows: [
|
||
{ t: "info", k: "temperature", l: "Temperature", f: fmtT, show: () => has("temperature") },
|
||
{ t: "info", k: "temperature2", l: "Temperature 2", f: fmtT, show: () => has("temperature2") },
|
||
{ t: "info", k: "humidity", l: "Humidity", f: v => (+v).toFixed(1) + " %", show: () => has("humidity") },
|
||
{ t: "info", k: "humidity2", l: "Humidity 2", f: v => (+v).toFixed(1) + " %", show: () => has("humidity2") },
|
||
{ t: "info", k: "pressure", l: "Pressure", f: v => (+v).toFixed(1) + " hPa", show: () => has("pressure") }] },
|
||
{ l: "Maintenance", rows: [R.cathode] }
|
||
] },
|
||
{ id: "tubes", l: "Tubes", cards: [
|
||
{ l: "Time", rows: [
|
||
{ t: "seg", k: "set12_24", l: "Clock", o: [[false, "12 h"], [true, "24 h"]] },
|
||
{ t: "sw", k: "showZero", l: "Leading zero", h: "Show 07:30 instead of 7:30" },
|
||
{ t: "sw", k: "enableBlink", l: "Blinking dots", h: "Off: the dots stay lit" },
|
||
{ t: "sw", k: "enableDoubleBlink", l: "Double blink", h: "For clocks with separately wired dots", show: () => cfg.enableBlink },
|
||
{ t: "select", k: "animMode", l: "Digit animation", h: "When the minute changes", o: ANIM }] },
|
||
{ l: "Time zone", rows: [
|
||
{ t: "select", k: "utc_offset", l: "Time zone", h: "Offset in winter", o: ZONES },
|
||
{ t: "sw", k: "enableDST", l: "Summer time", h: "EU rules: last Sunday of March to last Sunday of October" },
|
||
{ t: "text", k: "NtpServer", l: "Time server", h: "NTP server name", max: 29 }] },
|
||
{ l: "Date", rows: [
|
||
{ t: "sw", k: "enableTimeDisplay", l: "Show time and date", h: "Off: the clock only shows sensor values", show: hasTemp },
|
||
{ t: "range", k: "dateRepeatMin", l: "Show the date", min: 0, max: 10, f: v => fmtMin(v, "never") },
|
||
{ t: "pair", k: "dateStart", k2: "dateEnd", l: "During seconds", h: "From – to, within that minute", show: () => cfg.dateRepeatMin > 0 },
|
||
{ t: "seg", k: "dateMode", l: "Format", o: ["dd/mm/yy", "mm/dd/yy", "yy/mm/dd"] }] },
|
||
{ l: "Temperature and humidity", show: hasTemp, rows: [
|
||
{ t: "seg", k: "tempCF", l: "Unit", o: [[false, "°C"], [true, "°F"]] },
|
||
{ t: "range", k: "tempRepeatMin", l: "Show the values", min: 0, max: 10, f: v => fmtMin(v, "never") },
|
||
{ t: "pair", k: "tempStart", k2: "tempEnd", l: "Temperature during seconds", show: () => cfg.tempRepeatMin > 0 },
|
||
{ t: "pair", k: "humidStart", k2: "humidEnd", l: "Humidity during seconds", show: () => cfg.tempRepeatMin > 0 && has("humidity") }] },
|
||
{ l: "Cathode protection", rows: [
|
||
{ t: "range", k: "interval", l: "Automatic", h: "Short run of all digits", min: 0, max: 60, f: v => fmtMin(v, "off") },
|
||
{ t: "range", k: "cathProtMin", l: "Manual run length", min: 1, max: 60, f: v => v + " min" },
|
||
{ ...R.cathode, l: "Manual run", h: "Full brightness, every digit" }] },
|
||
{ l: "Alarm", show: () => cfg.hasAlarm, rows: [
|
||
{ t: "sw", k: "alarmEnable", l: "Alarm" },
|
||
{ t: "time", k: "alarmTime", l: "Time" },
|
||
{ t: "range", k: "alarmPeriod", l: "Rings for", min: 1, max: 240, f: v => v + " s" }] },
|
||
{ l: "Presence sensor", show: () => cfg.hasRadar, rows: [
|
||
{ t: "sw", k: "enableRadar", l: "Switch the tubes off when nobody is there" },
|
||
{ t: "range", k: "radarTimeout", l: "After", min: 1, max: 60, f: v => v + " min" }] }
|
||
] },
|
||
{ id: "light", l: "Light", cards: [
|
||
{ l: "Tube brightness", rows: [R.autoDim, R.dayBright,
|
||
{ t: "sw", k: "enableAutoShutoff", l: "Night mode", h: "Night brightness between the times below" },
|
||
{ t: "range", k: "nightBright", l: "Night brightness", min: 0, max: () => cfg.maxBrightness, f: fmtB, show: () => cfg.enableAutoShutoff },
|
||
{ t: "time", k: "nightTime", l: "Night starts", show: () => cfg.enableAutoShutoff },
|
||
{ t: "time", k: "dayTime", l: "Day starts", show: () => cfg.enableAutoShutoff }] },
|
||
{ l: "Backlight", show: hasRGB, rows: [R.effect, R.colour, R.rgbBright,
|
||
{ t: "range", k: "rgbSpeed", l: "Speed", min: 1, max: 255, show: fxAnim },
|
||
{ t: "seg", k: "rgbDir", l: "Direction", o: [[false, "Left"], [true, "Right"]], show: fxAnim }] },
|
||
{ l: "SignalRGB", show: () => cfg.wledEnable !== undefined, rows: [
|
||
{ t: "sw", k: "wledEnable", l: "SignalRGB control", h: "The clock shows up in SignalRGB as a WLED device" },
|
||
{ t: "sw", k: "wledDarkWithTubes", l: "Off with the tubes", h: "LEDs stay dark while the tubes are off" },
|
||
{ t: "sw", k: "wledUseBrightness", l: "Use backlight brightness", h: "Off: colours exactly as SignalRGB sends them" },
|
||
{ t: "info", k: "wledLive", l: "Receiving colours", f: v => v ? "yes" : "no" }] }
|
||
] },
|
||
{ id: "network", l: "Network", cards: [
|
||
{ l: "WiFi", save: 1, restart: "Restart now to use the new WiFi settings?", rows: [
|
||
{ t: "seg", k: "wifiMode", l: "Mode", o: [[true, "Join network"], [false, "Access point"]] },
|
||
{ t: "text", k: "wifiSsid", l: "Network name", max: 19 },
|
||
{ t: "pass", k: "wifiPsw", l: "Password", max: 19 },
|
||
{ t: "text", k: "ApSsid", l: "Access point name", h: "Used when there is no network", max: 19 },
|
||
{ t: "pass", k: "ApPsw", l: "Access point password", h: "At least 8 characters", max: 19 }] },
|
||
{ l: "MQTT / Home Assistant", save: 1, restart: "Restart now? The clock reads the MQTT settings at startup.",
|
||
show: () => cfg.mqttBrokerRefresh != 0, rows: [
|
||
{ t: "sw", k: "mqttEnable", l: "MQTT" },
|
||
{ t: "text", k: "mqttBrokerAddr", l: "Broker address", max: 29 },
|
||
{ t: "text", k: "mqttBrokerUser", l: "User", max: 19 },
|
||
{ t: "pass", k: "mqttBrokerPsw", l: "Password", max: 19 },
|
||
{ t: "range", k: "mqttBrokerRefresh", l: "Sensor updates", min: 10, max: 100, f: v => "every " + v + " s" }] }
|
||
] },
|
||
{ id: "system", l: "System", cards: [
|
||
{ l: "Status", rows: [
|
||
{ t: "info", k: "version", l: "Clock" },
|
||
{ t: "info", k: "FW", l: "Firmware", f: v => v + " · " + cfg.tubeDriver },
|
||
{ t: "info", k: "ip", l: "IP address" },
|
||
{ t: "info", k: "rssi", l: "WiFi signal", f: v => v + " dBm" },
|
||
{ t: "info", k: "uptime", l: "Uptime", f: fmtUp },
|
||
{ t: "info", k: "heap", l: "Free memory", f: v => (v / 1024).toFixed(1) + " KB" },
|
||
{ t: "info", k: "stalls", l: "Loop stalls", show: () => cfg.stalls !== undefined },
|
||
{ t: "html", id: "details" }] },
|
||
{ l: "Sensor calibration", show: () => hasTemp() || has("humidity"), rows: [
|
||
{ t: "range", k: "corrT0", l: "Temperature", min: -5, max: 5, step: .1, f: v => (v > 0 ? "+" : "") + v + " °C", show: () => has("temperature") },
|
||
{ t: "range", k: "corrT1", l: "Temperature 2", min: -5, max: 5, step: .1, f: v => (v > 0 ? "+" : "") + v + " °C", show: () => has("temperature2") },
|
||
{ t: "range", k: "corrH0", l: "Humidity", min: -25, max: 25, step: .1, f: v => (v > 0 ? "+" : "") + v + " %", show: () => has("humidity") },
|
||
{ t: "range", k: "corrH1", l: "Humidity 2", min: -25, max: 25, step: .1, f: v => (v > 0 ? "+" : "") + v + " %", show: () => has("humidity2") }] },
|
||
{ l: "Update over HTTP", rows: [
|
||
{ t: "text", k: "firmware", l: "Firmware URL", h: "Normal updates use ArduinoOTA", max: 77 },
|
||
{ t: "btn", l: "Download and install", h: "From the URL above", b: "Update", a: firmwareUpdate, show: () => !!cfg.firmware }] },
|
||
{ l: "Restart and reset", rows: [
|
||
{ t: "btn", l: "Restart", h: "Settings are kept", b: "Restart", a: () => confirm("Restart the clock?") && restart() },
|
||
{ t: "btn", l: "Factory reset", h: "Erases all settings, WiFi included", b: "Factory reset", cls: "danger", a: factoryReset }] }
|
||
] }
|
||
];
|
||
|
||
// ---------- building the page ----------
|
||
const binds = [], rows = [], cards = [];
|
||
let uid = 0;
|
||
function h(tag, props, ...kids) {
|
||
const e = document.createElement(tag);
|
||
for (const k in props || {}) {
|
||
const v = props[k];
|
||
if (k == "class") e.className = v; else if (k in e) e[k] = v; else e.setAttribute(k, v);
|
||
}
|
||
for (const c of kids.flat()) if (c != null && c !== false) e.append(c);
|
||
return e;
|
||
}
|
||
const cast = (k, s) => typeof cfg[k] == "boolean" ? s == "true" : typeof cfg[k] == "number" ? +s : s;
|
||
const bind = (r, k, set, node, live) => binds.push({ r, k, set, node, live });
|
||
|
||
function makeRow(d, card) {
|
||
const r = { d, card }, id = "c" + ++uid;
|
||
if (d.t == "html") { r.el = h("div", { class: "details", id: d.id }); rows.push(r); return r.el; }
|
||
r.help = h("small");
|
||
const ctl = h("div", { class: "ctl" });
|
||
const lbl = ["info", "btn", "seg"].includes(d.t) ? h("b", {}, d.l) : h("label", { htmlFor: id }, d.l);
|
||
r.el = h("div", { class: "row" }, h("div", { class: "lbl" }, lbl, r.help), ctl);
|
||
const change = (k, v) => onChange(r, k, v);
|
||
switch (d.t) {
|
||
case "sw": {
|
||
const n = h("input", { type: "checkbox", class: "sw", id, onchange: () => change(d.k, d.inv ? !n.checked : n.checked) });
|
||
bind(r, d.k, v => n.checked = d.inv ? !v : !!v, n);
|
||
ctl.append(n);
|
||
break;
|
||
}
|
||
case "range": {
|
||
ctl.classList.add("wide");
|
||
const n = h("input", { type: "range", id, step: d.step || 1 }), o = h("output");
|
||
const upd = () => {
|
||
o.textContent = d.f ? d.f(+n.value) : n.value;
|
||
n.style.setProperty("--p", (n.value - n.min) / ((n.max - n.min) || 1) * 100 + "%");
|
||
};
|
||
n.oninput = upd;
|
||
n.onchange = () => change(d.k, +n.value);
|
||
bind(r, d.k, v => { n.min = val(d.min); n.max = val(d.max); n.value = v; upd(); }, n);
|
||
ctl.append(n, o);
|
||
break;
|
||
}
|
||
case "hue": {
|
||
ctl.classList.add("wide");
|
||
const n = h("input", { type: "range", id, min: 0, max: 255, class: "hue" }), s = h("span", { class: "swatch" });
|
||
n.style.background = HUE_BG;
|
||
const upd = () => { s.style.background = s.style.color = wheel(+n.value); };
|
||
n.oninput = upd;
|
||
n.onchange = () => change(d.k, +n.value);
|
||
const w = h("button", { type: "button", class: "btn sm", onclick: () => { n.value = 192; upd(); change(d.k, 192); } }, "White");
|
||
bind(r, d.k, v => { n.value = v; upd(); }, n);
|
||
ctl.append(n, s, w);
|
||
break;
|
||
}
|
||
case "select": {
|
||
ctl.classList.add("wide");
|
||
const n = h("select", { id, onchange: () => change(d.k, cast(d.k, n.value)) }, opts(d.o).map(([v, t]) => h("option", { value: v }, t)));
|
||
bind(r, d.k, v => n.value = String(v), n);
|
||
ctl.append(n);
|
||
break;
|
||
}
|
||
case "seg": {
|
||
const o = opts(d.o), g = h("div", { class: "seg", role: "group" });
|
||
const sel = v => [...g.children].forEach((b, i) => b.classList.toggle("on", String(o[i][0]) == String(v)));
|
||
o.forEach(([v, t]) => g.append(h("button", { type: "button", onclick: () => { sel(v); change(d.k, cast(d.k, String(v))); } }, t)));
|
||
bind(r, d.k, sel, null);
|
||
ctl.append(g);
|
||
break;
|
||
}
|
||
case "time": {
|
||
const n = h("input", { type: "time", id, onchange: () => n.value && change(d.k, n.value) });
|
||
bind(r, d.k, v => n.value = v ? v.split(":").map(x => pad(+x)).join(":") : "", n);
|
||
ctl.append(n);
|
||
break;
|
||
}
|
||
case "text": case "pass": {
|
||
ctl.classList.add("wide");
|
||
const n = h("input", { type: d.t == "pass" ? "password" : "text", id, maxLength: d.max || 64, autocomplete: "off", spellcheck: false });
|
||
n.onchange = () => change(d.k, n.value);
|
||
if (card.save) n.oninput = n.onchange;
|
||
bind(r, d.k, v => {
|
||
n.value = v == null ? "" : v;
|
||
if (d.t == "pass") n.placeholder = cfg[d.k + "Set"] ? "unchanged" : "not set";
|
||
}, n);
|
||
if (d.t == "pass") {
|
||
const eye = h("button", { type: "button", onclick: () => { n.type = n.type == "password" ? "text" : "password"; eye.textContent = n.type == "password" ? "show" : "hide"; } }, "show");
|
||
ctl.append(h("div", { class: "pw" }, n, eye));
|
||
} else ctl.append(n);
|
||
break;
|
||
}
|
||
case "pair": {
|
||
const num = (k, first) => {
|
||
const n = h("input", { type: "number", min: 0, max: 59, class: "num", id: first ? id : "" });
|
||
n.onchange = () => { const v = Math.max(0, Math.min(59, parseInt(n.value) || 0)); n.value = v; change(k, v); };
|
||
bind(r, k, v => n.value = v, n);
|
||
return n;
|
||
};
|
||
ctl.append(num(d.k, 1), h("span", { class: "muted" }, "–"), num(d.k2));
|
||
break;
|
||
}
|
||
case "info": {
|
||
const o = h("span", { class: "val" });
|
||
bind(r, d.k, v => o.textContent = v === undefined ? "–" : d.f ? d.f(v) : v, null, true);
|
||
ctl.append(o);
|
||
break;
|
||
}
|
||
case "btn":
|
||
ctl.append(h("button", { type: "button", class: "btn " + (d.cls || ""), onclick: d.a }, d.b));
|
||
break;
|
||
}
|
||
rows.push(r);
|
||
return r.el;
|
||
}
|
||
|
||
function build() {
|
||
const main = $("#main");
|
||
main.textContent = "";
|
||
for (const p of PAGES) {
|
||
const sec = h("section", { id: "p-" + p.id, role: "tabpanel" });
|
||
for (const c of p.cards) {
|
||
c.dirty = {};
|
||
c.el = h("div", { class: "card" }, h("h2", {}, c.l), c.rows.map(d => makeRow(d, c)));
|
||
if (c.save) {
|
||
c.bar = h("div", { class: "acts", hidden: true }, h("span", {}, "Unsaved changes"),
|
||
h("button", { type: "button", class: "btn", onclick: () => discard(c) }, "Discard"),
|
||
h("button", { type: "button", class: "btn pri", onclick: () => commit(c) }, "Save"));
|
||
c.el.append(c.bar);
|
||
}
|
||
cards.push(c);
|
||
sec.append(c.el);
|
||
}
|
||
main.append(sec);
|
||
$("#tabs").append(h("button", { type: "button", role: "tab", id: "t-" + p.id, onclick: () => { location.hash = p.id; } }, p.l));
|
||
}
|
||
window.onhashchange = showTab;
|
||
showTab();
|
||
}
|
||
|
||
function showTab() {
|
||
const id = PAGES.some(p => p.id == location.hash.slice(1)) ? location.hash.slice(1) : "home";
|
||
for (const p of PAGES) {
|
||
$("#p-" + p.id).classList.toggle("on", p.id == id);
|
||
$("#t-" + p.id).setAttribute("aria-selected", p.id == id);
|
||
}
|
||
if (id == "system") loadDetails();
|
||
}
|
||
|
||
// ---------- keeping the page and the clock in step ----------
|
||
function onChange(r, k, v) {
|
||
const c = r.card;
|
||
if (c.save) { c.dirty[k] = v; c.bar.hidden = false; return; }
|
||
const old = cfg[k];
|
||
cfg[k] = v;
|
||
applyKey(k);
|
||
saveAll(expand(k, v)).then(ok => { if (!ok) { cfg[k] = old; applyKey(k); } });
|
||
}
|
||
async function commit(c) {
|
||
const pairs = Object.entries(c.dirty).flatMap(([k, v]) => expand(k, v));
|
||
if (!pairs.length || !await saveAll(pairs)) return;
|
||
for (const [k, v] of Object.entries(c.dirty)) {
|
||
if (k + "Set" in cfg) { cfg[k + "Set"] = v !== ""; cfg[k] = ""; } else cfg[k] = v; //passwords are never sent back
|
||
}
|
||
discard(c);
|
||
if (c.restart && confirm(c.restart)) restart();
|
||
}
|
||
function discard(c) { c.dirty = {}; c.bar.hidden = true; applyAll(); }
|
||
|
||
function applyKey(k) { binds.forEach(b => b.k == k && b.set(cfg[b.k])); refresh(); }
|
||
function applyAll() {
|
||
for (const b of binds) {
|
||
if (b.k in b.r.card.dirty) continue;
|
||
if (b.node && b.node === document.activeElement && b.node.type != "checkbox" && b.node.type != "range") continue; //being typed in
|
||
b.set(cfg[b.k]);
|
||
}
|
||
refresh();
|
||
}
|
||
function applyLive() { binds.forEach(b => b.live && b.set(cfg[b.k])); refresh(); }
|
||
// Visibility, help texts that depend on values, header chips
|
||
function refresh() {
|
||
for (const r of rows) {
|
||
r.el.hidden = !!r.d.show && !r.d.show();
|
||
if (r.help) r.help.textContent = val(r.d.h) || "";
|
||
}
|
||
for (const c of cards) {
|
||
c.el.hidden = (c.show && !c.show()) || c.rows.every(d => d.show && !d.show());
|
||
let first = true; //no divider above the first visible row
|
||
for (const e of c.el.querySelectorAll(".row")) { e.classList.toggle("first", first && !e.hidden); if (!e.hidden) first = false; }
|
||
}
|
||
$("#name").textContent = cfg.version || "";
|
||
document.title = cfg.version || "Nixie Clock";
|
||
$("#tubes").classList.toggle("dark", !!cfg.manualOverride || !online);
|
||
const chips = [];
|
||
if (!online) chips.push(["bad", "Offline, retrying"]);
|
||
else {
|
||
if (cfg.rssi != null) chips.push([cfg.rssi > -67 ? "ok" : cfg.rssi > -78 ? "warn" : "bad", "WiFi " + cfg.rssi + " dBm"]);
|
||
if (cfg.mqtt != null) chips.push(cfg.mqtt == 2 ? ["ok", "MQTT connected"] : cfg.mqtt == 1 ? ["warn", "MQTT not connected"] : ["", "MQTT off"]);
|
||
if (cfg.wledEnable) chips.push(cfg.wledLive ? ["ok", "SignalRGB live"] : ["", "SignalRGB idle"]);
|
||
if (cfg.manualOverride) chips.push(["warn", "Tubes off"]);
|
||
}
|
||
$("#chips").replaceChildren(...chips.map(([c, t]) => h("span", { class: "chip " + c }, t)));
|
||
}
|
||
|
||
// ---------- the clock in the header ----------
|
||
let base = 0, baseAt = 0, tubeCount = 0;
|
||
function syncClock() {
|
||
const [y, mo, d] = String(cfg.currentDate).split(".").map(Number), [hh, mm] = String(cfg.currentTime).split(":").map(Number);
|
||
if (!y) return;
|
||
base = new Date(y, mo - 1, d, hh, mm, cfg.currentSec || 0).getTime();
|
||
baseAt = Date.now();
|
||
}
|
||
function buildTubes() {
|
||
tubeCount = cfg.maxDigits == 6 ? 6 : 4;
|
||
const el = $("#tubes");
|
||
el.textContent = "";
|
||
for (let i = 0; i < tubeCount; i++) {
|
||
if (i && i % 2 == 0) el.append(h("div", { class: "neon" }, h("i"), h("i")));
|
||
el.append(h("div", { class: "tube" }, "0"));
|
||
}
|
||
el.append(h("span", { class: "secs" }));
|
||
}
|
||
function tick() {
|
||
setTimeout(tick, 1000 - Date.now() % 1000 + 10);
|
||
if (!base) return;
|
||
if (tubeCount != (cfg.maxDigits == 6 ? 6 : 4)) buildTubes();
|
||
const t = new Date(base + Date.now() - baseAt);
|
||
let hr = t.getHours();
|
||
if (cfg.set12_24 === false) hr = hr % 12 || 12;
|
||
const s = (pad(hr) + pad(t.getMinutes()) + pad(t.getSeconds())).slice(0, tubeCount);
|
||
document.querySelectorAll(".tube").forEach((e, i) => {
|
||
e.textContent = s[i];
|
||
e.classList.toggle("off", i == 0 && s[0] == "0" && cfg.showZero === false);
|
||
});
|
||
document.querySelectorAll(".neon").forEach(e => e.classList.toggle("off", cfg.enableBlink !== false && t.getSeconds() % 2 == 1));
|
||
$(".secs").textContent = tubeCount == 4 && cfg.currentSec !== undefined ? pad(t.getSeconds()) : "";
|
||
$("#date").textContent = fmtDate(t);
|
||
}
|
||
|
||
// ---------- loading ----------
|
||
async function loadConfig(first) {
|
||
try {
|
||
Object.assign(cfg, await getJSON("/getConfiguration"));
|
||
if (first) build();
|
||
syncClock();
|
||
applyAll();
|
||
} catch (e) {
|
||
if (first) { $("#msg").textContent = "Can't reach the clock (" + e.message + "). Retrying…"; setTimeout(() => loadConfig(true), 3000); }
|
||
}
|
||
}
|
||
async function poll() {
|
||
try {
|
||
Object.assign(cfg, await getJSON("/getCurrentInfos"));
|
||
online = true;
|
||
syncClock();
|
||
} catch (e) { online = false; }
|
||
if (cards.length) applyLive();
|
||
setTimeout(poll, 5000);
|
||
}
|
||
let detailsLoaded = false;
|
||
async function loadDetails() {
|
||
if (detailsLoaded) return;
|
||
try {
|
||
const html = TEST ? SAMPLE_DETAILS : await (await fetch("/getClockDetails", { signal: timeout(6000) })).text();
|
||
$("#details").innerHTML = html;
|
||
detailsLoaded = true;
|
||
} catch (e) {}
|
||
}
|
||
|
||
// ---------- actions ----------
|
||
let toastTimer;
|
||
function toast(msg, err) {
|
||
const t = $("#toast");
|
||
t.textContent = msg;
|
||
t.className = "on" + (err ? " err" : "");
|
||
clearTimeout(toastTimer);
|
||
toastTimer = setTimeout(() => t.className = "", err ? 5000 : 1800);
|
||
}
|
||
function overlay(title, msg) { $("#ovT").textContent = title; $("#ovM").textContent = msg; $("#overlay").hidden = false; }
|
||
// Waits until the clock answers again (after a restart), then reloads the page
|
||
function waitForClock(title, msg) {
|
||
overlay(title, msg);
|
||
if (TEST) { setTimeout(() => $("#overlay").hidden = true, 2500); return; }
|
||
const start = Date.now();
|
||
setTimeout(async function check() {
|
||
try { await getJSON("/getCurrentInfos"); location.reload(); }
|
||
catch (e) {
|
||
if (Date.now() - start > 60000) $("#ovM").textContent = msg + " It's taking long: if you changed the WiFi settings, the clock may be on another network now.";
|
||
setTimeout(check, 2000);
|
||
}
|
||
}, 5000);
|
||
}
|
||
async function restart() {
|
||
post("/reset").catch(() => {});
|
||
waitForClock("Restarting…", "The page reloads when the clock is back.");
|
||
}
|
||
async function factoryReset() {
|
||
if (!confirm("Factory reset: all settings are erased, WiFi included. The clock then starts its own access point and has to be set up again. Continue?")) return;
|
||
post("/factoryreset").catch(() => {});
|
||
overlay("Factory reset", "The clock restarts with default settings. Connect to its access point to set up WiFi again.");
|
||
}
|
||
async function firmwareUpdate() {
|
||
if (!confirm("Download and install the firmware from " + cfg.firmware + "?")) return;
|
||
try {
|
||
const r = await post("/firmwareupdate");
|
||
if (!r.ok) throw Error("HTTP " + r.status);
|
||
waitForClock("Updating firmware…", "Don't unplug the clock. It restarts when the update is done.");
|
||
} catch (e) { toast("Update not started: " + e.message, true); }
|
||
}
|
||
async function runCathode() {
|
||
try {
|
||
const r = await post("/cathodeProtect");
|
||
if (!r.ok) throw Error("HTTP " + r.status);
|
||
toast("Cathode protection runs for " + cfg.cathProtMin + " min");
|
||
} catch (e) { toast("Not started: " + (e.name == "AbortError" ? "no answer from the clock" : e.message), true); }
|
||
}
|
||
|
||
loadConfig(true).then(() => { poll(); tick(); });
|
||
setInterval(() => document.hidden || loadConfig(), 60000); //settings can also change from Home Assistant
|
||
document.addEventListener("visibilitychange", () => document.hidden || loadConfig());
|
||
</script>
|
||
</body>
|
||
</html>
|