Files
parking_solution/wiki/entities/relay-proxy-firmware.md
julian 6eb65361a8 docs(wiki): park-2 event-loop stall incident + bounded-request-cost decision; Dingtian firmware retired, dev-board pinout, edge-controller memo
- concepts/park-2-event-loop-stall: /api/sessions/active ~2 s synchronous (quote() per open
  unpaid transient x664, unindexed ledger scans) froze the loop; Node runs expired timers before
  queued UDP replies, so healthy Dingtian pulses reported "timeout" and signed entries lost
  their snapshot/session row. Standing decision: bounded request cost whatever the operator data.
- Dingtian: custom firmware retired (2026-10-23), runbook shelved, vendor pinout in raw/,
  relay-proxy PoC marked retired; edge-controller hardware memo (open).
2026-10-24 11:17:30 +02:00

84 lines
5.1 KiB
Markdown

---
type: entity
tags: [parking, hardware, firmware, esp8266, dingtian, cloud, watchdog, poc]
sources: []
updated: 2026-10-23
status: retired
---
# relay-proxy — Dingtian emulator + cloud proxy/watchdog firmware (PoC, retired)
> **Retired 2026-10-23.** The Dingtian-firmware path this PoC seeded is dropped (user decision:
> focus on mini PCs for booth resilience). The code stays in `firmware/relay-proxy/` as a working
> Dingtian protocol emulator — still useful as a **bench stand-in when no real relay board is on
> hand** — and the watchdog/heartbeat ideas carry over to whatever runs beside the booth PC.
Code: `firmware/relay-proxy/` (PlatformIO, Arduino framework; NodeMCU v3 / ESP8266 now, ESP32
env planned for the real [[dingtian-relay]]). Throwaway cloud stand-in: `poc/cloud-standin.mjs`.
## Why
park-2's booth PC died twice unnoticed ([[appliance-provisioning]] incident 2026-10-17). The
idea (2026-10-22): the device that already owns the barrier relay and the button inputs becomes
the resilient core — it reports to a multi-tenant cloud independently of the PC, can
power-cycle the PC, and keeps taking relay commands from the cloud when the PC is dead. Custom
firmware on the Dingtian is the natural home ([[esp32-flashability-test]] gates that); the
NodeMCU is the stand-in while no flashable Dingtian is on hand. Ledger implications of a cloud
takeover mode are **deliberately parked** (see [[open-questions]]).
## What it is to the booth: a DT-R004
The firmware speaks the Dingtian wire contract so the booth's `dingtian` driver is unchanged:
binary UDP 60000 (`00` status / `01` write / `03` jog, `relay_pw` checked, wrong password
dropped silently), string UDP 60001 (password-less; disabled when `udp2.p=255`),
`GET /api/v2/config.cgi`, `POST /api/v2/config_set.cgi` (requires `"command":"setconfig"`,
exactly like the hardware gotcha), `GET /userset.cgi` (`&0&` / `&2&`), and Digest-authenticated
input push to `on_path`/`off_path`. Config persists in LittleFS; factory state has
`input_link_relay` ON so the booth's precondition fix is exercised.
**Verified 2026-10-22 from the dev PC** (board at 10.0.10.101 on the ArtServis Wi-Fi, which lands
on the park-lab device net): status reply `ff aa s 00 <relay> <input>`, jog/write/release, string
`00`→`0000:1111:4`, setconfig-only writes, login rotation codes, cloud → relay pulse.
## What it adds: proxy + watchdog
Heartbeat to the cloud every 10 s (IP, booth health, relay/input state, config flags); every input
change mirrored to the cloud regardless of booth push config; cloud command poll (`pulse`,
`watchdog`, `reboot_pc`); watchdog probes the booth `/health` every 5 s and after 6 misses pulses
relay 2 for 3 s (NC contact in series with the PC mains + BIOS AC Recovery=On = reboot), 10-min
backoff, cloud can disable. This is the detect+remediate layer park-2 lacked.
## Booth integration — VERIFIED end to end (2026-10-22, park-lab)
After `ufw allow from 10.0.10.0/24 to any port 80,3000 proto tcp` on park-lab (see
[[site-device-installation]] "Booth host firewall"): the admin added the board in park-lab's setup
as a Dingtian controller (host 10.0.10.101). The booth's assign flow landed on the board exactly as
on hardware — `input_link_relay` cleared, random `relay_pw`, every channel but UDP1 set to 255
(udp2 really off: `00` on 60001 times out), web login rotated (`admin/admin` → `&2&`), Digest push
to `10.0.10.198:3000/api/devices/dingtian/<id>/input/N/{on,off}`. A FLASH-button press then
produced: board → booth `401` challenge → Digest retry → `200`, booth log
`[dingtian:<id>] input 1 on (push)` + `off`, and the cloud stand-in received `input_on` /
`input_off` with `booth_status=200` — the same event seen by booth and cloud independently. The
watchdog flipped to `booth UP` the moment port 80 opened.
## Open
- The booth's ufw rule set is root-only and undocumented — belongs in [[appliance-provisioning]].
- The booth accepts pushes only from the registered host IP → the board needs a DHCP reservation
or `STATIC_IP`.
- ESP8266 limits (Wi-Fi only, ~40 KB heap, blocking HTTP) are PoC-only; the target is the ESP32
on the Dingtian with Ethernet. Camera traffic is never proxied by the microcontroller.
- **Superseded as a hardware target (2026-10-22):** the takeover only works if the controller also
fronts the readers and the printer, which needs a Linux box with a Node runtime; the microcontroller
cannot. Hardware options and the watchdog policy (take over at one missed probe, power-cycle only when
the PC is dead at every layer) are on [[edge-controller-hardware]]. The emulation and watchdog logic
here carry over to the port.
## Bench note: NodeMCU v3 clone CH340 vs WCH driver
The board's USB-serial reports `USB\VID_1A86&PID_7523&REV_0254` and WCH drivers 3.9/4.0 refuse it
("A device attached to the system is not functioning" on every open). Fix applied 2026-10-22:
WCH driver **3.4.2014.08** (SparkFun mirror, WHQL catalog + Qinheng-signed setup verified),
staged with `pnputil /add-driver`, newer package exported to scratch then deleted from the store
so the port rebinds. Windows Update may push 4.0 back; repeat if the port fails again.