feat(firmware): relay-proxy PoC — NodeMCU as a Dingtian DT-R004 + cloud proxy/watchdog

A NodeMCU v3 (ESP8266) that speaks the Dingtian wire contract (binary UDP 60000 with
relay_pw, string UDP 60001, config CGI incl. the setconfig gotcha, userset.cgi, Digest
input push) so the booth's existing driver needs no change, plus a heartbeat/command/
watchdog path to an ephemeral cloud stand-in (poc/cloud-standin.mjs). Verified at park-lab:
the booth's assign flow configured it like real hardware and a button press reached the
booth (401→Digest→200) and the cloud with the booth's status. Watchdog probes /health and
power-cycles the PC via a spare relay with backoff. IO behind one interface for the ESP32/
Dingtian port.

wiki: relay-proxy-firmware page; esp32-flashability-test runbook (esptool lock test);
dingtian-relay "can we flash our own firmware" (vendor locks the standard SKU);
site-device-installation: booth ufw must allow device-net → 3000 (push targets PORT, not
Caddy's 80); open-questions: cloud takeover vs signed ledger (parked).

.gitignore: firmware venv/.pio/secrets.h.
This commit is contained in:
2026-10-22 12:08:20 +02:00
parent e842f036e2
commit c08e232339
19 changed files with 1162 additions and 1 deletions
+28 -1
View File
@@ -2,7 +2,7 @@
type: entity
tags: [parking, hardware, access-control, relay]
sources: []
updated: 2026-06-14
updated: 2026-10-22
---
# Dingtian Relay Controller
@@ -170,6 +170,33 @@ On assign the driver runs `harden()` (the [[device-registry|HardenableDevice]] c
> drop connections (ECONNRESET), locking out the API the driver depends on — recoverable only by
> factory reset. `harden()` deliberately never touches it.
## Can we flash our own firmware? (2026-10-22)
The DT-R0xx boards are **ESP32-WROOM-32D** designs (the module is visible in product photos; the
community ESPHome/Tasmota configs target ESP32). Relays/inputs are behind **74HC595 / 74HC165
shift registers** (SDI GPIO13, CLK GPIO14, RCK GPIO15, PL GPIO32, Q7 GPIO16); Ethernet is a
**JL1101 PHY** (MDC 23, MDIO 18, clock out 17, power 0). Community firmware exists: Tasmota
templates (Dingtian ships them in its own download centre) and an ESPHome external component
`dtr0xx_io`.
**But the vendor sells two SKUs.** The *Standard Firmware Version* (default shipment) is locked —
dtwonder: "The standard finished firmware version is not intended for user firmware flashing";
ESPHome devices page: "ask for relay board with test firmware, otherwise the ESP32 will be locked".
The *Development Board Version* ships with a bare "GPIO test firmware" and is meant for ESPHome /
Tasmota / ESP-IDF. The lock mechanism is not documented publicly (flash encryption, secure boot,
or UART-download-disable eFuses are all plausible on an ESP32 — eFuses are irreversible). No
forum post reports successfully unlocking a standard unit. Flashing a dev unit is plain ESP32
serial flashing (NRST↔DTR, 3.3 V USB-UART, hold the boot switch while powering).
**Implication for us:** our bench unit (DT-R004, V3.1.5461A, standard SKU) should be assumed
**not flashable** until tested — runbook: [[esp32-flashability-test]]; a dev-SKU unit would be. Custom firmware would let us close the open CGI/UDP
control plane (the hardening gaps above) by putting [[challenge-response-auth]] on the device —
effectively the [[esp32-custom-controller]] path on vendor hardware (no [[atecc608]] footprint,
so the key would live in ESP32 eFuse/NVS under flash encryption). That remains **deferred**
([[open-questions]] #6); if revisited, order the dev SKU and note the relay-GPIO pull-down
"relays blip on at boot" report on Tasmota — a boot-time relay pulse on a barrier is unacceptable
([[barrier-not-a-door]]) and must be verified before any field use.
## `relayPassword` field + the "offline despite ping" gotcha (2026-06-24)
`relay_pw` is in **every** binary frame — control AND the status read `healthCheck()` uses. With a
+73
View File
@@ -0,0 +1,73 @@
---
type: entity
tags: [parking, hardware, firmware, esp8266, dingtian, cloud, watchdog, poc]
sources: []
updated: 2026-10-22
status: poc
---
# relay-proxy — Dingtian emulator + cloud proxy/watchdog firmware (PoC)
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.
## 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.