1efa77bf56
A parking lot is one pool of spaces with a flexible set of entry/exit
points — no "lane". Direction is a property of each RELAY inside an access
controller; readers/cameras bind to a controller relay and inherit it.
Schema:
- drop `lane` from ledger_events, device_events, sessions
- rename lane_devices -> devices (no lane/direction columns)
- access config.relays=[{relay,direction,button?}]; reader/camera
config.controllerId+relay binding
- fresh 0000_baseline migration (history reset; dev data was throwaway)
Signed ledger:
- remove `lane` from canonicalize(); bump signer keyId sw-hmac-v1 -> v2
(v1 events won't verify under v2 — intentional, gated per-event by keyId)
Server:
- new device-resolve.ts (replaces lane-map.ts): relayForButton,
relayForDevice, firstRelayByDirection, devicesByDirection
- entry-flow: button terminal -> its relay; exit/permit: reader's bound
relay; dispatcher resolves the bound relay + inherited direction
- camera snapshots fire by direction site-wide, async, never block open
- DeviceConfig widened to nested JSON for relays[]
Web:
- wizard: no lane selector; add controllers (relay map + entry-button
terminal) first, then bind readers/cameras/printers to a controller relay
Wiki: new entry-exit-points.md (replaces lane-direction); reworked
entry-exit-readers, parking-session, first-run-setup, device-registry,
append-only-event-chain, device-events; removed stale lane/LaneMap mentions.
75 lines
3.7 KiB
Markdown
75 lines
3.7 KiB
Markdown
---
|
|
type: concept
|
|
tags: [parking, printer, device, monitoring, reliability]
|
|
sources: []
|
|
updated: 2026-06-14
|
|
---
|
|
|
|
# Printer status monitoring
|
|
|
|
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.
|
|
|
|
## 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]]).
|