feat(app): recently-heard nodes list (latest SNR, colour-coded) + debug log toggle

Clean list of the last 20 heard nodes with their latest SNR (green→red), hit
count; raw debug log collapsed behind a toggle. Node-name lookup deferred (needs
a CORS allowance for rx.on8ar.eu on the analyzer API + full node-list fetch).
This commit is contained in:
efiten committed 2026-06-09 19:14:56 +02:00
1 parent 26a6cb429e
commit a39504826d
2 files changed
+58 -5

No files matched your search

+14 -4
View File
@@ -28,7 +28,13 @@
.row button { flex: 1; }
label.inline { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; font-size: 13px; color: #e6e6e6; }
label.inline input { width: auto; }
#log { background: #0a0c10; border: 1px solid #2a2f3a; border-radius: 6px; padding: 8px; font: 11px/1.4 ui-monospace, monospace; white-space: pre-wrap; word-break: break-all; max-height: 300px; overflow: auto; color: #9fe6b8; }
#log { background: #0a0c10; border: 1px solid #2a2f3a; border-radius: 6px; padding: 8px; font: 11px/1.4 ui-monospace, monospace; white-space: pre-wrap; word-break: break-all; max-height: 300px; overflow: auto; color: #9fe6b8; margin-top: 8px; }
.recent { display: flex; flex-direction: column; gap: 4px; }
.rr { display: flex; align-items: center; gap: 8px; padding: 7px 9px; background: #11141a; border: 1px solid #2a2f3a; border-radius: 6px; font-size: 13px; }
.rr .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.rr .rk { font-family: ui-monospace, monospace; }
.rr .rsnr { margin-left: auto; font-weight: 600; }
.rr .rc { color: #9aa4b2; font-size: 11px; min-width: 34px; text-align: right; }
</style>
</head>
<body>
@@ -47,9 +53,13 @@
<div class="muted" id="status"></div>
</div>
<div class="card">
<button id="btnClear" class="btn2">Clear log</button>
<label>Debug log (frames in, parsed result, outgoing payload)</label>
<pre id="log"></pre>
<label>Recently heard nodes (latest SNR)</label>
<div id="recent" class="recent"><div class="muted">— nothing yet —</div></div>
<div class="row" style="margin-top:10px">
<button id="btnDbg" class="btn2">Show debug log</button>
<button id="btnClear" class="btn2">Clear log</button>
</div>
<pre id="log" style="display:none"></pre>
</div>
<script type="module" src="/src/app.js"></script>
</body>
+44 -1
View File
@@ -12,7 +12,42 @@ import { Queue } from './queue.js';
import { Publisher } from './publisher.js';
const els = (id) => document.getElementById(id);
const state = { transport: null, gps: new Gps(), queue: new Queue(), publisher: null, heard: 0, companionPubkey: '', connected: false };
const state = { transport: null, gps: new Gps(), queue: new Queue(), publisher: null, heard: 0, companionPubkey: '', connected: false, recent: [] };
const RECENT_MAX = 20;
// SNR → colour bucket (LoRa-ish). Returns a CSS colour.
function snrColor(snr) {
if (snr == null) return '#95a5a6';
if (snr >= 5) return '#2ecc71';
if (snr >= -3) return '#f1c40f';
if (snr >= -10) return '#e67e22';
return '#e74c3c';
}
// noteHeard upserts a heard node into the recent list (most-recent first).
function noteHeard(key, keylen, snr, rssi, src) {
let e = state.recent.find((x) => x.key === key);
if (e) state.recent = state.recent.filter((x) => x !== e);
else e = { key, keylen, count: 0, src };
e.count++; e.snr = snr; e.rssi = rssi; e.last = Date.now();
state.recent.unshift(e);
state.recent = state.recent.slice(0, RECENT_MAX);
renderRecent();
}
function renderRecent() {
const el = els('recent');
if (!state.recent.length) { el.innerHTML = '<div class="muted">— nothing yet —</div>'; return; }
el.innerHTML = state.recent.map((e) => {
const snr = e.snr != null ? e.snr.toFixed(1) + ' dB' : 'no sig';
return '<div class="rr">' +
'<span class="dot" style="background:' + snrColor(e.snr) + '"></span>' +
'<span class="rk">' + e.key + '</span>' +
'<span class="rsnr" style="color:' + snrColor(e.snr) + '">' + snr + '</span>' +
'<span class="rc">×' + e.count + '</span></div>';
}).join('');
}
// MQTT config from build-time env (Vite); never the UI. Treat as a shared,
// publish-only ingest account (EMQX ACL); not a real secret.
@@ -65,6 +100,7 @@ async function processFrame(dv) {
const hk = deriveHeardKey('rx', pkt);
if (!hk) { dbg(' → not attributable (tx / 1-byte hop / no advert) — skip'); return; }
dbg(' → heard ' + hk.heardKey + ' (' + hk.heardKeyLen + 'B, ' + hk.src + ')');
noteHeard(hk.heardKey, hk.heardKeyLen, f.snr, f.rssi, hk.src); // show in the list even without a GPS fix
const fix = currentFix();
if (!fix) { dbg(' → no GPS fix — skip'); return; }
const rec = { rx_at: new Date().toISOString(), raw: rawHex, snr: f.snr, rssi: f.rssi, lat: fix.lat, lon: fix.lon, acc_m: fix.acc_m };
@@ -152,6 +188,13 @@ window.addEventListener('DOMContentLoaded', () => {
setButton();
els('btnConnect').addEventListener('click', () => (state.connected ? disconnectAll() : connectAll()));
els('btnClear').addEventListener('click', () => { els('log').textContent = ''; });
els('btnDbg').addEventListener('click', () => {
const log = els('log');
const show = log.style.display === 'none';
log.style.display = show ? 'block' : 'none';
els('btnDbg').textContent = show ? 'Hide debug log' : 'Show debug log';
});
renderRecent();
refreshCounters();
drainLoop();
if ('serviceWorker' in navigator) {