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:
@@ -0,0 +1,50 @@
|
||||
// NodeMCU v3 pin map. Zero external wiring needed for the PoC:
|
||||
// relay 1 -> D1 (GPIO5) + mirrored on the on-board LED (GPIO2, active LOW)
|
||||
// relay 2 -> D2 (GPIO4) (the watchdog's "PC power" relay)
|
||||
// relay 3 -> D5 (GPIO14)
|
||||
// relay 4 -> D6 (GPIO12)
|
||||
// input 1 -> the on-board FLASH button (GPIO0, pulled up, LOW when pressed)
|
||||
// input 2 -> D7 (GPIO13), INPUT_PULLUP: short to GND to "press"
|
||||
// inputs 3-4 are virtual and idle HIGH.
|
||||
#include "io.h"
|
||||
|
||||
static const int8_t RELAY_PIN[CHANNELS] = {5, 4, 14, 12};
|
||||
static const int8_t INPUT_PIN[CHANNELS] = {0, 13, -1, -1};
|
||||
static const uint8_t LED_PIN = 2;
|
||||
|
||||
void Io::begin() {
|
||||
for (int i = 0; i < CHANNELS; i++) {
|
||||
pinMode(RELAY_PIN[i], OUTPUT);
|
||||
digitalWrite(RELAY_PIN[i], LOW);
|
||||
if (INPUT_PIN[i] >= 0) pinMode(INPUT_PIN[i], INPUT_PULLUP);
|
||||
}
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
digitalWrite(LED_PIN, HIGH); // LED off
|
||||
}
|
||||
|
||||
void Io::setRelay(int ch, bool on) {
|
||||
if (ch < 1 || ch > CHANNELS) return;
|
||||
relays_[ch - 1] = on;
|
||||
digitalWrite(RELAY_PIN[ch - 1], on ? HIGH : LOW);
|
||||
if (ch == 1) digitalWrite(LED_PIN, on ? LOW : HIGH);
|
||||
}
|
||||
|
||||
bool Io::relay(int ch) const { return ch >= 1 && ch <= CHANNELS && relays_[ch - 1]; }
|
||||
|
||||
bool Io::inputHigh(int ch) {
|
||||
if (ch < 1 || ch > CHANNELS) return true;
|
||||
int8_t pin = INPUT_PIN[ch - 1];
|
||||
return pin < 0 ? true : digitalRead(pin) == HIGH;
|
||||
}
|
||||
|
||||
uint8_t Io::relayMask() const {
|
||||
uint8_t m = 0;
|
||||
for (int i = 0; i < CHANNELS; i++) if (relays_[i]) m |= 1 << i;
|
||||
return m;
|
||||
}
|
||||
|
||||
uint8_t Io::inputMask() {
|
||||
uint8_t m = 0;
|
||||
for (int i = 0; i < CHANNELS; i++) if (inputHigh(i + 1)) m |= 1 << i;
|
||||
return m;
|
||||
}
|
||||
Reference in New Issue
Block a user