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.
3.6 KiB
relay-proxy — Dingtian emulator + cloud proxy/watchdog (PoC)
A NodeMCU v3 (ESP8266) that is a Dingtian DT-R004 to the booth server and, on top, a
proxy and watchdog toward a cloud service. The booth's existing dingtian driver talks to
it unchanged. It is the seed of the custom firmware for the real Dingtian board (ESP32); the IO
layer is the only board-specific file.
Why: park-2's booth PC died twice unnoticed. The device that already owns the barrier relay and
the button inputs becomes the resilient core: it reports to the cloud independently of the PC,
can power-cycle the PC, and keeps accepting commands from the cloud when the PC is dead.
See wiki/entities/dingtian-relay.md and wiki/decisions/cloud-service-saas.md.
What it emulates (the booth sees a DT-R004)
| Surface | Behaviour |
|---|---|
| UDP 60000 binary | FF AA s cmd pwLo pwHi …: 00 status, 01 write (mask,set), 03 jog. Reply FF AA s cmd relayByte inputByte. Wrong relay_pw → dropped silently. |
| UDP 60001 string | 00, 1N, 2N, 1N*. Password-less. Enabled at factory; harden() turns it off (udp2.p=255). |
GET /api/v2/config.cgi |
The config JSON (relay_connect, input_link_relay, input_link_url). |
POST /api/v2/config_set.cgi |
Applies + persists (LittleFS). Requires "command":"setconfig" like the real device. |
GET /userset.cgi?u&old&u&new& |
Web-login rotation, &0& ok / &2& wrong old password. |
| Input push | On input change, Digest-authenticated GET to the booth's on_path/off_path. |
input_link_relay |
Factory ON (input auto-fires its relay) until the booth's precondition fix clears it. |
Extra, PoC-only: GET / status text, POST /poc/factory_reset.
Proxy / watchdog (toward CLOUD_URL)
- Heartbeat every 10 s: IP, booth health, relay/input state, config flags.
- Every input change is mirrored to the cloud (
/event) with the booth push result. - Command poll every 2 s:
{"pulse":ch,"ms":500},{"watchdog":false},{"reboot_pc":true}. - Watchdog: probes
BOOTH_HEALTH_URLevery 5 s; after 6 failures in a row it pulses relay 2 for 3 s (meant for an NC contact in series with the PC's mains, with BIOS AC Recovery = On), then backs off 10 min. The cloud can disable it.
Pins (NodeMCU v3) — no wiring needed to start
| Function | Pin |
|---|---|
| Relay 1 (barrier) | D1 / GPIO5, mirrored on the on-board LED |
| Relay 2 (PC power) | D2 / GPIO4 |
| Relay 3, 4 | D5 / GPIO14, D6 / GPIO12 |
| Input 1 (button) | the on-board FLASH button (GPIO0), active LOW |
| Input 2 | D7 / GPIO13, short to GND |
Build / flash
cd firmware/relay-proxy
copy include\secrets.h.example include\secrets.h # fill in; gitignored
..\.venv\Scripts\pio run -t upload
..\.venv\Scripts\pio device monitor
Cloud stand-in (throwaway): node poc/cloud-standin.mjs on a host the device can reach.
Register it in the booth
Devices → add Dingtian relay controller: host = the NodeMCU's IP (give it a DHCP
reservation or set STATIC_IP; the booth only accepts pushes from the registered IP),
channels 4, binary port 60000, string port 60001, HTTP port 80. On save the booth runs the
normal flow: precondition fix (clears input_link_relay), harden() (random relay_pw,
disables udp2, rotates the web login), and configureInputPush() (Digest creds + URLs).
The serial log shows each step land.
Limits of the PoC
- Wi-Fi only; the real target has Ethernet.
- HTTP calls block the loop briefly (~100 ms); fine for a demo, not for production.
- The config JSON mirrors the keys the booth driver uses, not the full device schema.
- Plain HTTP to the cloud stand-in; the real cloud link needs TLS.