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
@@ -0,0 +1,20 @@
#pragma once
#include <ArduinoJson.h>
// The Dingtian-shaped config served by /api/v2/config.cgi, persisted to LittleFS.
// Holds exactly the keys the booth driver reads/writes (relay_connect, input_link_relay,
// input_link_url) — a faithful-enough subset, not a byte copy of the real device.
class ConfigStore {
public:
JsonDocument cfg;
String webUser, webPass; // web-UI login (userset.cgi), kept out of config.cgi
void begin();
bool save();
bool saveWeb();
void makeDefaults();
uint16_t relayPw() const;
bool stringProtoEnabled() const; // udp2.p != 255
bool linkRelayEnabled() const; // input_link_relay flag (factory: on)
};
+7
View File
@@ -0,0 +1,7 @@
#pragma once
#include <Arduino.h>
// HTTP GET with RFC 2617 Digest (MD5, qop=auth) — what the booth's push route
// requires. First GET takes the 401 challenge, second carries the response.
// With an empty user it is a plain GET. Returns the final HTTP status (<0 = no connection).
int digestGet(const String& host, uint16_t port, const String& path, const String& user, const String& pass);
+20
View File
@@ -0,0 +1,20 @@
#pragma once
#include <Arduino.h>
constexpr int CHANNELS = 4;
// Relay/input IO behind one tiny interface. Business code never touches pins, so
// porting to the real Dingtian board (74HC595 relays / 74HC165 inputs) swaps only
// the Io implementation file.
class Io {
public:
void begin();
void setRelay(int ch, bool on); // 1-based
bool relay(int ch) const; // 1-based
bool inputHigh(int ch); // raw line level, 1-based
uint8_t relayMask() const; // bit0 = relay 1
uint8_t inputMask(); // bit0 = input 1, bit set = line HIGH
private:
bool relays_[CHANNELS] = {};
};
@@ -0,0 +1,12 @@
// Copy to include/secrets.h (gitignored) and fill in.
#pragma once
#define WIFI_SSID "your-ssid"
#define WIFI_PASS "your-password"
// Ephemeral cloud stand-in (poc/cloud-standin.mjs), plain HTTP for the PoC.
#define CLOUD_URL "http://10.0.10.203:9099"
// Booth server health endpoint the watchdog probes.
#define BOOTH_HEALTH_URL "http://10.0.10.198/health"
// Optional fixed address (the booth only accepts pushes from the registered host IP).
// #define STATIC_IP "10.0.10.240"
// #define STATIC_GW "10.0.10.1"
// #define STATIC_MASK "255.255.255.0"