Files
parking_solution/wiki/concepts/printer-status-monitoring.md
T
julian 552d87d75b feat(devices): K200L printer driver — live cover/paper status from the J-Speed LAN board
The park-buzi printer is a K200L (Xprinter/ICS XP-K200L; its LAN board and USB
descriptor call it "POS-80"). Its board serves the Rongta's five-row status table
under /prt_status.htm — but the reply carries no HTTP status line or headers, which
node:http rejects, so the Rongta driver could never read it and the unit was filed
in July as "no status page → generic driver" (reachability only).

New `k200l` driver (printer-k200l.ts): prints through the generic ESC/POS device
(same bytes, TCP 9100 or usblp) and reads the page over a raw socket, tolerant of
both the headerless and a proper HTTP reply. Mapping mirrors the Rongta: board
unreachable → offline; page not understood → degraded, never ready; any fault →
degraded naming it; USB → reachability floor. The Rongta driver is untouched.
Tests replay the captured headerless page (devices suite 76). Live against the
lab unit: ready; with the cover open the board reports cover open, paper out,
off-line.

Wiki: new k200l-printer entity (names, network setup from factory
192.168.123.100, board quirks, status page, what it means for park-buzi — over
USB the app never saw cover/paper state at all), cross-links on the Rongta,
status-monitoring, USB-transport and WSL-networking pages (parking-net pinned to
eth1 while the LAN NIC is eth0), index.

Claude-Session: https://claude.ai/code/session_01FWncR69HgGPuei1dLrW3cU
2026-09-09 12:34:59 +02:00

107 lines
6.2 KiB
Markdown

---
type: concept
tags: [parking, printer, device, monitoring, reliability]
sources: []
updated: 2026-09-09
---
# Printer status monitoring
> **Generalised 2026-06-18:** the booth's all-device status **footer** is a separate, unified
> monitor across every category (relays/readers/cameras/printers) — see
> [[device-status-monitoring]]. This page remains the authority for the *printer-specific* rich
> status (paper/cover/cutter) + its SSE stream; both monitors run.
The booth must know a printer is in trouble **before** a driver presses the entry button and no
ticket comes out. So the system polls each printer's live status (paper out, cover open, cutter
jam, off-line) and pushes changes to the operator UI. A reliability control, like
[[printer-roles-failover]] — not a threat-model one.
## Where the status comes from (the safe-decode decision)
The raw print socket (TCP 9100) is write-only for us — it returns no paper/cover feedback. ESC/POS
printers expose status via real-time queries (`DLE EOT n`). On the [[rongta-printer]] clone we
probed, **`DLE EOT` replies do NOT follow the canonical ESC/POS bit layout** (the spec's fixed
validation bits were wrong, verified on hardware 2026-06-14). Decoding those bits ourselves risked
a **false-healthy** — reporting "paper OK" when it's empty — which is the dangerous direction for
an entry lane.
Instead we scrape the device's **own status web page** (`http://<host>/prn_stat.htm`). The board
decodes the bits itself into labelled Yes/No rows (Cover Is Open, Cutter Error, Paper End, Paper
Near End, Printer Off-Line). We trust the device's decode over hand-decoding an undocumented clone.
This is captured as a device capability: `MonitorableDevice.readStatus(): PrinterStatus` in
`packages/devices`. The Rongta driver implements it; the monitor is device-agnostic via
`isMonitorable()`. A future printer with a different status mechanism just implements the same
interface.
**A clone WITHOUT a trustworthy status mechanism must NOT implement `readStatus`.** The **Cashino**
80mm printer prints via the identical ESC/POS stream (shared in `drivers/printer-escpos.ts`) but
serves **no** `/prn_stat.htm` page. Running it on the Rongta driver made the monitor scrape a page
that isn't there → a bogus `degraded`/page-error verdict even while the printer was fine (the
incident that prompted this). Fix: a dedicated `cashino` driver that is **not** `MonitorableDevice`
(no `readStatus`), so `isMonitorable()` is false and the monitor falls back to the generic
`healthCheck()` — a plain **TCP reachability ping** of the print socket: reachable → `ready`,
unreachable → `offline`, and **never** a guessed paper/cover state it cannot sense. This is the
correct floor for any ESC/POS printer that can't report consumables: report only what you can
actually observe. The shared ESC/POS rendering/transport (`renderTicket`/`renderReport`/
`renderSubscriptionCard`/`sendRaw`/`probe`) was extracted to `printer-escpos.ts` so both drivers
share the print path and only status differs.
## Status mapping (fail safe)
`readStatus()` maps to `ready | degraded | offline`:
- status page unreachable / times out → **offline** (same signal as a dead printer; never throws),
- page reachable but a recognised field is missing → **degraded** ("unexpected status page") —
we do NOT claim "ready" off a page we didn't fully parse,
- any fault flag true (paper end, cover open, cutter error, off-line) → **degraded** + a detail
string ("paper out", …),
- all five clear → **ready**.
## The monitor (server)
`PrinterMonitor` (`apps/server/src/printer-monitor.ts`):
- reloads the monitored set from `devices` each tick (so a newly-assigned printer is picked
up without a restart), keeping only enabled, monitorable printers;
- polls every `PRINTER_POLL_MS` (default 5000ms), never overlapping ticks;
- caches the latest status per device id;
- emits a `printer-status` event on the device bus **only when status changes** (deduped).
## API / live UI
- `GET /api/printers/status` — cached snapshot of all printers (no device round-trip).
- `GET /api/printers/status/stream` — **Server-Sent Events**: full snapshot on connect, then one
event per change. The booth SPA subscribes for real-time paper-out / offline indicators.
- Any authenticated role may read (operational, not a setup action).
## Verified on hardware (2026-06-14)
`readStatus()` against 10.0.10.6 → `ready` (all flags false); against an unreachable host →
`offline` with "status page timeout" (no throw); bus emits on change and suppresses unchanged
reads. Full repo typechecks.
## Open / not yet done
- **Fault-state capture**: we've only observed the all-clear page. The exact label text for an
active fault (e.g. does "Paper End" flip to "Yes"?) should be confirmed by physically removing
paper / opening the cover, to be 100% sure the scrape catches it. The parser is built to match
Yes/No and degrade on anything unexpected, so this is a confidence check, not a blocker.
- Tying a `degraded`/`offline` entry-dispenser into [[printer-roles-failover]] failover and the
(not-yet-built) entry flow's all-printers-down policy ([[device-input-flow]]).
## K200L — a second status-page board, and a fetch that node:http can't do (2026-09-09)
The park-buzi printer turned out to be a **K200L** (Xprinter/ICS XP-K200L; LAN board "J-Speed
Ethernet WebConfig 1.02", self-named "POS-80"). Its board serves the **same five decoded Yes/No
rows** as the Rongta page — under **`/prt_status.htm`**. Two things kept it invisible until now:
the Rongta driver only knew `/prn_stat.htm` (so in July the unit was filed as "no status page →
generic driver"), and the board's reply carries **no HTTP status line or headers** (HTTP/0.9
style), which `node:http` rejects outright and `curl` shows as an empty `000`. The new **`k200l`**
driver (`printer-k200l.ts`) prints through the generic ESC/POS path and reads the page over a raw
TCP socket, tolerant of both reply shapes; mapping is the Rongta one (unreachable → offline; page
not understood → degraded, never ready; any fault → degraded naming it; else ready; USB →
reachability floor). Bench-verified: cover open → amber "cover open, paper out, printer off-line".
Tests replay the captured headerless reply. Full device notes: [[k200l-printer]].