Cathode RayAdmin

ICD-001 — Cathode Ray viewer protocol, version 2

Interface Cathode Ray server ⇄ viewer (the G2 app: glasses side and phone side)
Protocol version 2
Document revision 2.2 (draft for review)
Replaces ICD-001 v1 rev 1.2. No compatibility: server and app move to v2 together.
Normative artefacts this document, schema/icd-001-v2.schema.json, examples/
Related ICD-002 (producer API: push, activities, Grafana alerts)

The key words MUST, MUST NOT, SHOULD, SHOULD NOT and MAY are used as in RFC 2119. Where this document and the JSON schema disagree on message shape, the schema wins. Where they disagree on behaviour, this document wins.


1. Purpose and scope

Cathode Ray is a head-up "cyberdeck" for the G2 glasses: a menu of live views on homelab data, ad-hoc values pushed from anywhere, alerts, things in progress, and (later) controls.

This ICD defines the interface between the server and the viewer app. It does not define how data gets into the server; that is ICD-002.

1.1 What changed from v1

v1 v2
Flat list of dashboards, swipe to cycle Menu tree of views (§6)
Values keyed by widget Values keyed by channel (§7.1), the system-wide unit of data
Value text included the unit text and unit are separate (the multimeter changes unit on the fly)
Hero was a widget style Hero is a view layout (§9.3)
No alerts Now feed: alerts and activities, independent of the open view (§8)
Read-only Actions with confirmation tiers (§10). Specified now, implemented in phase 4.
Dashboards only from server config Quick views built on the phone (§11)
One shared token Keys with scopes (§12)

2. System context and responsibilities

 producers (ICD-002)                 server                                viewer (this ICD)
 ───────────────────                 ──────                                ─────────────────
 OctoPrint, Influx, HA, plugins ──▶  channel registry ──▶ views ─────────▶ glasses: menu, views
 push API (scripts, devices)    ──▶  (latest value only) ─▶ now feed ────▶ glasses: banner, Now
 Grafana alerting (webhook)     ──▶  alert store ────────┘                  phone: quick-view editor
                                     actions ◀───────────── invoke/confirm ─ glasses: Control
Concern Server Viewer
Talking to data sources, Grafana, Home Assistant ✅ ❌ never
Formatting numbers (text), units ✅ renders verbatim
Thresholds, staleness → state ✅ visualises
Alert evaluation ✅ (Grafana for stack data, server for push staleness) ❌
Menu tree and view definitions ✅ owns renders
Whether an action is allowed, and executing it ✅ ❌ only asks
Pixel layout, containers, paging, banners ❌ ✅
Navigation state (which view is open, scroll position) ❌ ✅
Link loss detection and reconnect ❌ ✅

3. Transport

3.1 WebSocket

Item Value
Production URL wss://crt.lucavs.nl/ws/v2
Frames Text only, one UTF-8 JSON object per frame
Max frame size 512 KiB server→viewer (up to 1000 pushed plus 120 configured channel-picker entries), 32 KiB viewer→server (100-item quick views)
Binary frames MUST NOT be sent. Receiver closes with 1003.

3.2 Helper endpoints

Not used by the app; for humans, scripts and debugging. Same key as the viewer (§12), sent as Authorization: Bearer <key>.

Endpoint Returns
GET /api/v2/health {"status":"ok","version":"…"} (no key needed, public)
GET /api/v2/menu The menu message payload
GET /api/v2/views/{id} The view message the viewer would receive
GET /api/v2/now The now message payload

4. Versioning and compatibility

  1. Every message carries "v": 2. Any other value is a protocol error (UNSUPPORTED_VERSION).
  2. Must-ignore: receivers MUST ignore unknown object fields.
  3. Receivers MUST ignore messages with an unknown type (log, don't fail).
  4. Unknown enum values are handled per field:
    • unknown layout: render as grid
    • unknown severity: treat as warning
    • unknown action tier: treat as critical (fail safe)
    • unknown item kind (neither channel nor action): skip the item
  5. Adding optional fields, message types or enum values is a compatible change (new revision, same v). Anything else needs v: 3.

5. Session

5.1 Lifecycle

sequenceDiagram
    participant A as Viewer
    participant S as Server
    A->>S: hello {client, key}
    S-->>A: welcome {scopes, heartbeat_s, menu, home}
    S-->>A: now {alerts, activities}
    A->>S: open {view: "printer"}
    S-->>A: view {definition, values}
    loop data changes
        S-->>A: values {view, values}
    end
    S-->>A: now {…}   (whenever alerts/activities change)
    A->>S: ack {alert}
    A->>S: invoke {action, req: 7}
    S-->>A: action_result {re: 7, status: "confirm", confirm: {token}}
    A->>S: invoke {action, req: 8, confirm: token}
    S-->>A: action_result {re: 8, status: "done"}

5.2 Handshake

  1. The viewer MUST send hello as its first frame, within 10 s of the socket opening. Otherwise: close 4003.
  2. Bad key: error AUTH_FAILED (fatal), then close 4001.
  3. Any other message before a successful hello: error NOT_READY (fatal), close 4003. A hello that fails validation: error BAD_MESSAGE (fatal), close 4003.
  4. On success the server sends, in this order:
    • welcome, with the key's scopes, the full menu tree, and the id of the view the viewer should open first (home)
    • one now message, the full alert and activity state

5.3 Requests and replies

Viewer messages MAY carry req, an integer chosen by the viewer and unique within the session. When the server answers a specific viewer message (error, action_result, channels, view_saved, pong), it echoes that integer as re. Spontaneous server messages have no re.

invoke, list_channels, save_view and delete_view MUST carry req.

5.4 Open view

  1. A session has at most one open view. open replaces the previous one.
  2. The server answers each valid open with exactly one view message: the definition and the full current values.
  3. After that the server sends values messages for that view only.
  4. Once the server has sent view for a new open, it MUST NOT send values for the previous view. The viewer MUST discard values whose view isn't the currently open one.
  5. Unknown view id: error UNKNOWN_VIEW (non-fatal). The previous view stays open.
  6. Definition changes: the server MAY send view again at any time for the currently open view when its definition changes. Typical cases are a pushed channel appearing in Live, or a quick view being edited from the phone. The viewer treats it like the reply to open: it rebuilds the page and keeps the scroll position if the view id is unchanged.
  7. Opening a menu node has no wire message. Menus are client-side navigation over the tree from welcome/menu.

5.5 Updates and rate limits

Stream Server limit Content
values ≤ 2 per second, sent as soon as a channel changes only channels whose text, unit, state or progress changed. Never empty.
now ≤ 1 per second always the complete alert and activity state (snapshot, not a diff)
menu on change always the complete tree

The viewer applies values latest-wins per channel. Older frames still waiting for the glasses are dropped, never queued.

5.6 Heartbeat and link loss

Unchanged from v1:

A reconnect is a fresh session. The viewer re-opens the view it was showing. The server keeps no per-session state, except acks (§8.4), which are per key.

5.7 Sequence numbers and timestamps

6. Menu tree

The menu is part of the protocol because the server knows what exists: which views are configured, whether anything has been pushed, and whether the key may use controls.

6.1 MenuNode

Field Type Rule
id Id unique in the tree
title string ≤ 24 shown in lists and the header
view Id present → selecting the node opens this view
children MenuNode[] 1–20 present → selecting the node shows a submenu
badge string ≤ 4 optional, e.g. "2!" on Now. Shown after the title.
hidden boolean optional, default false. Hidden nodes stay reachable via home and alert links but aren't listed.

Exactly one of view and children MUST be present.

6.2 Tree rules

6.3 Reference tree (server default; not normative)

Home
├── Now            view "now"       (layout now)
├── Indium         view "indium"    (grid)
├── Printer        view "printer"   (grid)
├── Lab
│   ├── Multimeter view "dmm"       (hero)
│   ├── Lab supply view "psu"       (hero)
│   └── Live       view "live"      (list of pushed channels)
├── Quick
│   └── …          one node per quick view
└── Control        (only with the control scope)
    ├── Lights     view "lights"    (grid of action items)
    └── Printer    view "printer-ctl"

7. Data model

7.1 Identifiers

Kind Pattern Example
Id (views, menu nodes, actions) ^[a-z0-9][a-z0-9_-]{0,31}$ printer, quick-3
ChannelId ^[a-z0-9][a-z0-9_-]{0,31}(\.[a-z0-9][a-z0-9_-]{0,31}){0,3}$, max 64 chars printer.hotend, acme.bus_v
AlertId, ActivityId ^[A-Za-z0-9._:-]{1,64}$ grafana:3f9a…, stale:acme.bus_v

Channel ids are system-wide. The same id means the same value in every view.

7.2 ChannelValue

Field Type Req. Meaning
text string ≤ 32 yes Display-ready value without unit: "214", "1h 12m", "Printing", "--"
unit string ≤ 8 no "°C", "V", "mA", "%". Absent or empty means no unit.
state State yes §7.3
ts number yes When the underlying data was sampled (server clock)
value number | null no Raw number, informational
progress number 0..1 no Fill fraction, drawn as a bar where the layout allows

7.3 States

state Set by the server when Viewer renders
ok fresh, within thresholds normal brightness
warn warn threshold crossed ! before the text, full brightness
crit crit threshold crossed !! before the text, full brightness
stale no update within the channel's freshness limit (ICD-002 ttl, or the configured limit) dimmed, ? after the text
nodata source unreachable or never reported; text SHOULD be "--" dimmed

7.4 ViewDefinition

Field Type Rule
id Id
title string ≤ 24
layout grid | hero | list | now §9
items Item[] count depends on layout (§9). Empty for now.
editable boolean optional. True for quick views the key may change (§11).

7.5 Item

An item is either a channel item or an action item.

Channel item:

Field Type Rule
channel ChannelId
label string ≤ 16 resolved by the server (a view may override the channel's own label)
span 1 | 2 grid layout only. Other layouts ignore it. Default 1.

Action item (requires the control scope; never sent otherwise):

Field Type Rule
action Id
label string ≤ 16
tier safe | guarded | critical drives the confirmation UX (§10)
channel ChannelId optional. Shows the action's current state, e.g. a light is on.
span 1 | 2 as above

values in view and in values messages are keyed by ChannelId, not by item. A channel that appears twice in a view is updated once.

8. Now feed: alerts and activities

The Now feed is global. It arrives regardless of which view is open, so the viewer can show a banner on any page.

Configured sources are polled for the Now feed while at least one viewer is connected. A configured progress widget between 0 and 1 becomes an activity linked to its view; a configured view whose channels are all nodata raises a source-down warning. The snapshot contains at most 50 alerts, ordered by unacked status, severity and firing time. If more are active (for example, many stale channels), lower-priority entries wait until space is available. Activity writes beyond 20 entries and Grafana writes beyond 50 active alerts are rejected with 413.

8.1 Alert

Field Type Req. Meaning
id AlertId yes stable for the alert's lifetime
severity info | warning | critical yes
title string ≤ 32 yes "Hotend runaway", "acme.bus_v stale"
detail string ≤ 80 no one line of context
origin grafana | server yes grafana: received through ICD-002 §6. server: raised by Cathode Ray itself (staleness, source down).
since number yes firing since (server clock)
acked boolean yes acknowledged with this key (§8.4)
interrupt none | banner | takeover yes what the viewer does when the alert first arrives (§8.3)
link {view?: Id, channel?: ChannelId} no where to go for details

Resolved alerts are simply absent from the next now message.

8.2 Activity ("in progress")

Field Type Req. Meaning
id ActivityId yes
title string ≤ 24 yes "Print", "Backup"
text string ≤ 32 yes "34% ETA 22:40"
progress number 0..1 no
state State yes same meaning as for channels
link {view?: Id} no

Activities come from configured sources (a running print) or from ICD-002 §5 (any script).

8.3 Interrupt behaviour

interrupt is decided by the server from its configuration. The default policy is critical → banner, everything else → none. Per alert rule, it can be set to takeover.

interrupt Viewer MUST
none only update the Now view and the menu badge
banner while the alert is unacked, replace the header line on every page with !! <title>, alternating with the normal header every 3 s
takeover the first time it sees this alert id unacked, open the now view. Double-tap returns to the previous view.

Neither applies to acked alerts. A takeover never happens while a confirmation dialog (§10) is on screen; it waits until the dialog closes.

8.4 Acknowledging

9. Layouts (rendering contract)

Canvas: 576 × 288 px, line height 27 px. At most 8 text/list containers and 4 image containers per page.

Header (all layouts): the view title, the link indicator and the clock, or the alert banner (§8.3).

9.1 grid

9.2 list

9.3 hero

9.4 now

9.5 Menus

9.6 Input mapping (G2 temples and R1 ring)

Gesture In a menu In a view In a confirm dialog
Swipe up / down move selection (firmware) page / move selection between action items cancel
Tap open the node now: ack. Action item: invoke. Otherwise nothing. confirm
Double tap back. At the root: exit, with the system dialog. back to the menu it was opened from cancel

While the link is lost, a tap anywhere also triggers an immediate reconnect.

10. Actions

Specified now so views and keys can be designed around them. Server support lands in phase 4. Until then, servers never send action items.

10.1 Tiers

Tier Examples Confirmation Server MUST
safe light on/off, scene none execute on invoke
guarded extruder preheat or jog, pause print one confirm within expires_s (≤ 10) require a valid confirm token
critical front door one confirm within expires_s (≤ 10). The viewer MUST use a dialog that needs a deliberate gesture: the app shows the action name and requires a swipe down followed by a tap. require a valid confirm token, enforce a per-action cooldown, write an audit log entry

The server is the authority. It MAY refuse any action at any time based on state, for example no extruder jog while printing, or the door already open.

10.2 Flow

  1. The viewer sends invoke {req, action}.
  2. The server replies action_result {re, status, …}:
status Meaning
confirm carries confirm: {token, expires_s, prompt}. The viewer shows prompt (≤ 32) and, on confirm, sends invoke {req, action, confirm: token}.
done executed
denied not allowed now; message says why ("printer is printing")
failed tried and failed; message says why
expired the confirm token is unknown, used or expired
  1. Confirm tokens are single-use, bound to the session and the action, and valid for expires_s.
  2. A safe action MAY get confirm too. The server decides; the tier only sets the viewer's dialog style.

11. Quick views (phone side)

The phone half of the app can build small views from existing channels. These messages need the edit scope.

Message Purpose
list_channels {req} → channels {re, channels}: every channel the key may see, with id, label, unit, origin (config | push) and group (menu section, informational)
save_view {req, view} Create (view.id absent) or replace (view.id given, and editable) a quick view. Layout grid, hero or list, channel items only. → view_saved {re, id}, followed by a menu update.
delete_view {req, id} Only editable views. → view_saved {re, id, deleted: true}, followed by a menu update.

Quick views are stored on the server, per key, and appear under Quick in the menu. Limits:

12. Security

  1. TLS only in production. nginx terminates it. The WebSocket is reachable from anywhere (the glasses connect over mobile data), so the key is the only gate. The server applies the failed-auth limit of ICD-002 §3 to hello as well: a client IP with 10 AUTH_FAILED per minute is refused (4001) for 5 min.
  2. Keys are configured on the server (ICD-002 §2). Each key has scopes. Viewer-relevant scopes:
Scope Allows
view connect, menu, views, Now feed (required)
ack ack
edit quick views (§11)
control action items appear; invoke
  1. Messages needing a missing scope get error FORBIDDEN (non-fatal).
  2. The key is sent only in hello, never in a URL. The server compares in constant time and never logs it.
  3. Push-only keys (ICD-002) MUST be rejected in hello with AUTH_FAILED.
  4. The server keeps an audit log of every invoke: time, key name, action, status.

13. Errors and close codes

code fatal Close Cause
AUTH_FAILED yes 4001 bad key, or a key without view
UNSUPPORTED_VERSION yes 4002 v ≠ 2
NOT_READY yes 4003 message before successful hello
BAD_MESSAGE no (yes for hello) — (4003) invalid JSON or schema violation
UNKNOWN_VIEW no — open, save_view or delete_view with an unknown or non-editable id
UNKNOWN_ALERT no — ack for an id not currently firing
UNKNOWN_ACTION no — invoke for an action not in any view of this key
FORBIDDEN no — missing scope
RATE_LIMITED no — more than 20 viewer messages per second
INTERNAL no — server bug

Other close codes: 4008 heartbeat timeout, 1001 server shutdown, 1000 normal.

14. Message catalogue

Viewer → server:

type Fields (besides v, type, optional req)
hello client{name,version}, key
open view
ack alert
invoke action, req, optional confirm
list_channels req
save_view req, view (ViewDefinition without editable; id optional)
delete_view req, id
ping nonce

Server → viewer (all carry seq and ts; replies carry re):

type Fields
welcome server{name,version}, heartbeat_s, scopes[], menu (root MenuNode), home
menu menu
view definition, values
values view, values (≥ 1 entry)
now alerts[] (≤ 50), activities[] (≤ 20)
channels channels[]
view_saved id, optional deleted
action_result action, status, optional message, optional confirm{token,expires_s,prompt}
pong nonce
error code, message, fatal

The golden examples/ cover every message; examples/invalid/ covers the rules the schema enforces.

15. Conformance

Same rules as v1 §11:

16. Change log

Rev Date Change
2.0 2026-10-05 Draft: menu tree, channels, Now feed (alerts and activities), actions with tiers, quick views, scoped keys
2.1 2026-10-06 §12: WebSocket is internet-reachable; failed-auth limit applies to hello. §3.2: health endpoint is public.
2.2 2026-12-05 §5.5: values go out as soon as a channel changes, still ≤ 2 per second. §9.3: the hero progress bar is drawn with the digits.