Erwin FitenandClaude Opus 5 229bbf656c fix: a failed config fetch no longer silently disables the whole session
Two field logs traced to one root cause: config.json is fetched exactly once at
DOMContentLoaded and never retried, so a single transient failure at startup left
getConfig() returning null (or a stale cached copy) for the rest of the session.

Log A: no config at all. connectAll took its else branch, never built a Publisher,
and then reported "All connected - capturing" anyway. An hour of receptions queued
and nothing published. The Push button answered "nothing pending / not connected"
because drain() returns 0 for a null publisher exactly as it does for an empty
queue - and its reconnect branch was guarded on `publisher && !connected()`, which
skipped the one case needing recovery. The only message naming the cause went to
els('status'), which the next connect cleared with log('').

Log B: a config.json cached before rfSampler/regionDiscovery existed. Absent flags
normalize to false, so both features were dead while the served config said on -
publishing worked, everything looked green, and nothing reported it. A stale config
is worse than none: none is detectable, stale is not.

- sw.js: config.json bypasses the cache in both directions, and the
  caches.match('/') fallback is limited to navigations. Serving index.html for a
  JSON request is what turned an offline start into "invalid JSON: Unexpected
  token '<'".
- config.js: loadConfig dedupes concurrent attempts, caches only on success so a
  retry actually re-fetches, and names an HTML body instead of leaking a parse error.
- uplink.js (new, pure): uplinkState / uplinkWarning / pushOutcome /
  regionInertReason / buildLogHeader.
- app.js: retries the config on every connect, on `online`, and once a minute while
  missing; startPublisher() split out so a late config brings uploading up without
  reconnecting; a red Home banner while receptions are buffered but not uploaded;
  the progress list no longer claims an uplink it does not have; pushNow reports
  queue depth independently of link health and picks the matching repair.
- Region discovery names which of its four gates is holding it, once, in the log -
  "no regions lines" was consistent with all four and distinguished none. Its
  re-entry throttle is now stamped before the gates instead of after.
- Every exported log carries a header with app version, EFFECTIVE config flags,
  firmware version, region-discovery status, uplink state and queue depth. Both
  field logs arrived unattributable to a version; the header is built at share time
  so it cannot roll out of the 200-line ring buffer the way a startup line does.

Tests: 217 pass (+41). sw.js is driven in a node:vm ServiceWorkerGlobalScope so the
shipped file is tested, not a copy of its logic.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 09:45:09 +02:00
2026-07-09 16:34:30 +02:00
2026-06-13 21:48:47 +02:00

coredrive-rx

Mobile RX-coverage capture for CoreScope. A mobile PWA that connects over BLE to a MeshCore companion radio, captures which nodes it hears (SNR/RSSI), tags each reception with the phone's GPS, and publishes to MQTT so a CoreScope ingestor stores it in client_receptions and renders per-node hex coverage on the Reach page.

Supported browsers

The app needs Web Bluetooth, which not every browser has:

  • Android: Chrome.
  • iOS / iPadOS: the Bluefy browser — Safari (and every other normal iOS browser) has no Web Bluetooth, so the app cannot connect there. Opening the app in plain iOS Safari shows an in-app notice pointing to Bluefy.
  • Desktop (for testing): Chrome or Edge.

The screen is kept awake while capturing (native Screen Wake Lock where available, with a video fallback for Bluefy), so the phone won't dim/lock mid-drive.

How it works

companion ──BLE 0x88 (snr+rssi+raw)──▶ frames.js ──▶ meshpacket.js (path[last] / advert pubkey)
                                                          │
phone GPS (gps.js) ───────────────────────────────────────┤
                                                          ▼
                                          queue.js (IndexedDB, offline) ──▶ publisher.js (MQTT/WSS)
                                                          │
                                          meshcore/client/{PUBLIC_KEY}/packets ──▶ CoreScope ingestor
  • Capture source: the companion's PUSH_CODE_LOG_RX_DATA (0x88) frame — emitted for every received packet on stock firmware, carrying SNR + RSSI + the raw packet.
  • Direct-only rule: records only path[last] (last forwarder, FLOOD routes) or a 0-hop advert's full pubkey. Upstream hops are discarded.
  • Auto-discover: a zero-hop node-discover request is sent automatically while connected so nodes in direct range reply with their ID. It backs off for 15 s whenever organic traffic is overheard (no point polling a busy channel) and is suspended while stationary.
  • GPS: the phone's (navigator.geolocation), not the companion's.
  • Trust: the companion pubkey is the identity; the EMQX ACL binds each client to its own topic.

Screens

  • 🏠 Home — a live monitor: session counters (distinct nodes / hex cells covered / total receptions), a status strip (GPS accuracy, pending uploads, upload health + last-upload age, capture rate), the last reception's SNR on a peak-hold meter, and the recently-heard list.
  • 🗺️ Map — live per-cell coverage for this session.
  • ⚙️ Settings — the Connect/Disconnect button (with connection progress), CoreScope broker status + a Push pending now button, companion info, and diagnostics (verbose toggle, debug log, share/mail the log). The app opens here until a companion is connected, then jumps to Home.

Self-hosting (for a CoreScope sysop)

You host this app for your own CoreScope environment so your users can contribute RX coverage. There is no central server — you point the app at your own MQTT broker and CoreScope.

1. Prerequisites

  • A running CoreScope deployment with its ingestor.
  • An MQTT broker (EMQX) reachable over WSS with a valid TLS certificate — Web Bluetooth and PWA install both require a secure (HTTPS) context. Connect via the hostname (not an IP).

2. EMQX: a publish-only account

Create a dedicated account and an ACL so a client can only publish to its own topic:

  • Allow publish to meshcore/client/${clientid}/packets
  • Deny everything else (publish #, subscribe #)
  • Enable the WebSocket/TLS listener (default port 8084, path /ws).

The app sets clientId = the companion's pubkey, so the ACL binds each user to their own topic.

3. CoreScope server

  • Enable the coverage screen via its config flag (see CoreScope docs).
  • Ensure the ingestor subscribes to the client topic (meshcore/# or meshcore/client/#) so receptions land in client_receptions.

4. Get the app and host it

Choose (A) a prebuilt release (no Node/npm) or (B) build from source:

(A) Download a release — recommended, no build: Grab coredrive-rx-<version>.zip from Releases and unzip it into your web root.

(B) Build from source:

npm install
npm run build          # outputs static files to dist/

Copy the contents of dist/ to your web root.

Either way, serve the files over HTTPS on a subdomain (e.g. rx.yourdomain). Requirements:

  • SPA fallback: unknown paths serve /index.html (e.g. nginx try_files $uri /index.html;).
  • Cache headers: index.html, sw.js, the web-app manifest, and config.json = no-cache; /assets/* = immutable. Without this, a cached index.html pins old assets after an update.

5. config.json (runtime config — no rebuild to change)

Put a config.json in the served directory (next to index.html). Start from the example:

{
  "mqttUrl": "wss://broker.yourdomain:8084/ws",
  "mqttUsername": "coredrive-rx",
  "mqttPassword": "<your publish-only EMQX account password>",
  "resolveUrl": "https://corescope.yourdomain/api/nodes/resolve",
  "fullRfLog": false,
  "rfSampler": false,
  "regionDiscovery": false
}

mqttPassword is a publish-only, ACL-constrained account — it is shipped to browsers, so treat it as shared, not a secret. resolveUrl is optional (see CORS below); omit it and the app shows heard-key prefixes instead of node names. fullRfLog is optional (default false); when true, packets the direct-only rule can't attribute (a DIRECT-route path, or noise) are queued and published too, as diagnostic-only rows — never coverage. This is pure waste unless the CoreScope ingestor also has clientRxObservations.enabled: true: with it off, the ingestor decodes and discards every one of these packets, writing no row and logging no warning, while fullRfLog multiplies your normal upload volume. Confirm the ingestor-side flag with your CoreScope sysop before turning this on. rfSampler is optional (default false); when true, the app polls the companion's own radio counters (noise floor, RX/TX airtime, CRC errors) over local Bluetooth and publishes them on meshcore/client/<pubkey>/rf. Enable it only after your broker's ACL permits that /rf subtopic for this client — this app negotiates MQTT 3.1.1, whose PUBACK carries no reason code, so a publish denied by the ACL is still acknowledged: the app logs published N record(s) and looks healthy while the server receives zero rows. Confirm the topic is allowed (and that the CoreScope ingestor has clientRfSamples.enabled: true) with your CoreScope sysop before turning this on. regionDiscovery is optional (default false); when true, this is the only part of the app that transmits: once connected it addresses one repeater at a time, round-robin, asking for its declared flood-allowed region list roughly every 60 seconds, and publishes the answer on meshcore/client/<pubkey>/regions. It requires companion firmware v13+ — on older firmware the app logs why and never sends. Enable it only after your broker's ACL permits that /regions subtopic for this client, for the same silent-PUBACK reason as rfSampler above. Confirm the topic is allowed (and that the CoreScope ingestor has clientRegions.enabled: true) with your CoreScope sysop before turning this on — otherwise the ingestor decodes and discards every upload, same as fullRfLog off.

Changing any value later is just a config.json edit + page refresh — no rebuild.

config.json is never cached offline, so starting the app needs a live connection once. The service worker deliberately excludes it (both directions): a copy cached in an earlier era silently disables every flag added since, because an absent flag normalizes to false. That failure is invisible — it looks exactly like the feature being broken — whereas no config is a state the app detects, warns about on the Home screen, and retries (every minute and on the online event) until it loads. Capture and buffering are unaffected by a cold start with no network; only uploading waits, and the queue drains as soon as config arrives.

Because the effective flags are what matter, they are stamped into the header of every exported debug log (Share log in Settings), together with the app version, the companion firmware version, whether region discovery can transmit at all, and the queue depth. Compare that header against the served config.json to spot a client running on something else.

6. CORS (optional, for node names)

The app calls CoreScope's GET /api/nodes/resolve?prefix=… cross-origin. Set resolveUrl to either:

  • a CORS-enabled reverse-proxy location in front of the CoreScope API (adds Access-Control-Allow-Origin for the app's origin), or
  • the CoreScope API directly, if it already sends CORS headers for your app's origin.

Leave resolveUrl empty to disable name resolution entirely.

Develop

npm install
cp public/config.example.json public/config.json   # fill in your dev broker; gitignored
npm run dev      # Vite dev server (Android Chrome; Web Bluetooth needs HTTPS or localhost)
npm test         # node --test

Web Bluetooth requires a secure context (HTTPS or localhost). For phone testing over LAN, serve via HTTPS (e.g. a dev tunnel) — Chrome blocks Web Bluetooth on plain HTTP origins.

Deploy

Two optional SSH helpers — both leave the server's config.json intact:

From a prebuilt release — no Node/npm (deploy-release.sh, needs only curl + unzip):

RX_DEPLOY_HOST=user@host RX_DEPLOY_DEST=/var/www/rx.yourdomain/ bash deploy-release.sh
# defaults to the latest release; pin one with  RX_VERSION=v0.9.0

Downloads the latest release zip and scps the static files to the host. The release zip contains no config.json, so your server config is never overwritten.

From source (deploy.sh, builds locally then uploads):

RX_DEPLOY_HOST=user@host RX_DEPLOY_DEST=/var/www/rx.yourdomain/ npm run deploy

Builds, drops dist/config.json, and uploads dist/ — never touching the server's config.json.

License

GPL-3.0-or-later — see LICENSE. Companion to CoreScope.

S
Description
No description provided
Readme GPL-3.0
6.3 MiB
0 Stars 1 Watchers 0 Forks
Languages
JavaScript 95.2%
HTML 3.1%
PowerShell 0.7%
Shell 0.6%
Java 0.4%