Dev #26

Open
overseer wants to merge 65 commits from dev into main
2 changed files with 49 additions and 33 deletions
Showing only changes of commit 2fb73ec8c4 - Show all commits
+25 -16
View File
@@ -9,16 +9,16 @@
; (TX/RX) (RX16/TX17) ; (TX/RX) (RX16/TX17)
; ;
; Build: ; Build:
; pio run -e esp8266-camera (ESP8266 D1 Mini — camera bridge) ; pio run -e esp8266-camera (ESP8266 — GoPro camera bridge)
; pio run -e esp32-mqtt (ESP32 Dev Board — MQTT bridge) ; pio run -e seeed_xiao_esp32c6 (XIAO ESP32-C6 — MQTT bridge)
; ;
; Upload: ; Upload:
; pio run -e esp8266-camera --target upload ; pio run -e esp8266-camera --target upload
; pio run -e esp32-mqtt --target upload ; pio run -e seeed_xiao_esp32c6 --target upload
; ;
; Filesystem: ; Filesystem:
; pio run -e esp8266-camera --target uploadfs ; pio run -e esp8266-camera --target uploadfs
; pio run -e esp32-mqtt --target uploadfs ; pio run -e seeed_xiao_esp32c6 --target uploadfs
[common] [common]
lib_deps = lib_deps =
@@ -43,25 +43,34 @@ build_flags = ${common.build_flags}
board_build.flash_mode = dio board_build.flash_mode = dio
board_build.f_cpu = 160000000L board_build.f_cpu = 160000000L
build_src_filter = build_src_filter =
+<../lib/>
+<esp8266-camera-bridge.cpp>
-<*.cpp> -<*.cpp>
+<esp8266-camera-bridge.cpp>
+<../lib/>
; ── ESP32: MQTT Bridge ───────────────────────────────────── ; ── XIAO ESP32-C6: MQTT Bridge ─────────────────────────────
; Flashed onto ESP32 Dev Board. Connects to travel router, ; Flashed onto a Seeed Studio XIAO ESP32-C6. Connects to the
; publishes MQTT to Pi hub. Reads camera status from ESP8266 ; travel router, publishes MQTT to the Pi hub. Reads camera
; over UART2 (RX16/TX17). No direct camera communication. ; status from the ESP-01S over UART (Serial1: RX=D7, TX=D6).
; No direct camera communication.
;
; ESP32-C6 requires the pioarduino fork of platform-espressif32
; (mainline espressif32 lagged on the Arduino-core 3.x the C6
; needs). USB-CDC-on-boot is required for Serial over native USB.
;
; Upload fallback if it can't connect: hold B (BOOT), tap
; R (RESET), release B, then re-run upload.
[env:esp32-mqtt] [env:seeed_xiao_esp32c6]
platform = espressif32 platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
board = esp32dev board = seeed_xiao_esp32c6
framework = arduino framework = arduino
monitor_speed = 115200 monitor_speed = 115200
upload_speed = 921600
lib_deps = ${common.lib_deps} lib_deps = ${common.lib_deps}
build_flags = ${common.build_flags} build_flags = ${common.build_flags}
-D CONFIG_ARDUINO_LOOP_STACK_SIZE=8192 -D CONFIG_ARDUINO_LOOP_STACK_SIZE=8192
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
build_src_filter = build_src_filter =
+<../lib/>
+<esp32-mqtt-bridge.cpp>
-<*.cpp> -<*.cpp>
+<esp32-mqtt-bridge.cpp>
+<../lib/>
+24 -17
View File
@@ -19,10 +19,10 @@
* ESP32 → ESP8266: {"type":"cmd","command":"ping"}\n * ESP32 → ESP8266: {"type":"cmd","command":"ping"}\n
* *
* Hardware: * Hardware:
* - ESP32 Dev Board (or D1 Mini ESP32) * - Seeed Studio XIAO ESP32-C6
* - UART2: RX=GPIO16, TX=GPIO17 (connected to ESP8266) * - Serial1: RX=D7, TX=D6 (crossed to the ESP-01S TX/RX)
* - Shared GND between boards * - Shared GND between boards
* - LiPo → 3.3V buck → VIN on both boards * - 5V rail → XIAO 5V/VIN; ESP-01S on its own 3.3V buck
*/ */
#include <Arduino.h> #include <Arduino.h>
@@ -80,13 +80,19 @@ bool saveConfig() {
} }
// ──────────────────────────────────────────── // ────────────────────────────────────────────
// UART to ESP8266 (HardwareSerial2) // UART to ESP-01S (HardwareSerial1)
// ──────────────────────────────────────────── // ────────────────────────────────────────────
// ESP32 UART2: RX=GPIO16, TX=GPIO17 // XIAO ESP32-C6 Serial1: RX=D7, TX=D6 (Serial = native USB CDC)
// Connect: ESP32 RX(16) ← ESP8266 TX // Connect: XIAO RX(D7) ← ESP-01S TX
// ESP32 TX(17) → ESP8266 RX // XIAO TX(D6) → ESP-01S RX
#define UART_ESP8266 Serial2 #define UART_ESP8266 Serial1
#define UART_RX_PIN D7
#define UART_TX_PIN D6
// Camera-online indicator → green channel of the RGB STAT LED.
// (Full RGB/OLED status-panel bring-up is not implemented yet.)
#define STAT_LED_PIN D1
void sendCmdToESP8266(const String& command) { void sendCmdToESP8266(const String& command) {
JsonDocument doc; JsonDocument doc;
@@ -187,7 +193,8 @@ bool connectMQTT() {
JsonArray caps = doc["capabilities"].to<JsonArray>(); JsonArray caps = doc["capabilities"].to<JsonArray>();
caps.add("start_stop"); caps.add("status"); caps.add("start_stop"); caps.add("status");
String payload; serializeJson(doc, payload); String payload; serializeJson(doc, payload);
mqtt.publish("remoterig/cameras/announce-" + clientID(), payload.c_str(), true); String announceTopic = "remoterig/cameras/announce-" + clientID();
mqtt.publish(announceTopic.c_str(), payload.c_str(), true);
Serial.println("[MQTT] Announced for registration"); Serial.println("[MQTT] Announced for registration");
} }
@@ -204,14 +211,14 @@ void setup() {
Serial.println("\n[BRIDGE] ESP32 MQTT Bridge v1.0"); Serial.println("\n[BRIDGE] ESP32 MQTT Bridge v1.0");
bootMs = millis(); bootMs = millis();
pinMode(2, OUTPUT); // built-in LED pinMode(STAT_LED_PIN, OUTPUT); // RGB STAT LED — green = camera online
digitalWrite(2, LOW); digitalWrite(STAT_LED_PIN, LOW);
loadConfig(); loadConfig();
// UART to ESP8266 // UART to ESP-01S
UART_ESP8266.begin(115200, SERIAL_8N1, 16, 17); // RX=16, TX=17 UART_ESP8266.begin(115200, SERIAL_8N1, UART_RX_PIN, UART_TX_PIN);
Serial.println("[UART] ESP8266 link on RX16/TX17 @ 115200"); Serial.println("[UART] ESP-01S link on Serial1 (RX=D7, TX=D6) @ 115200");
// Connect to travel router — the ONLY network we touch // Connect to travel router — the ONLY network we touch
Serial.printf("[WIFI] Connecting to: %s\n", cfg.wifi_ssid.c_str()); Serial.printf("[WIFI] Connecting to: %s\n", cfg.wifi_ssid.c_str());
@@ -278,7 +285,7 @@ void loop() {
if (online != cameraOnline) { if (online != cameraOnline) {
cameraOnline = online; cameraOnline = online;
digitalWrite(2, online ? HIGH : LOW); digitalWrite(STAT_LED_PIN, online ? HIGH : LOW);
} }
if (cfg.camera_id.length() > 0) { if (cfg.camera_id.length() > 0) {
@@ -297,13 +304,13 @@ void loop() {
} }
} }
else if (type == "ack") { else if (type == "ack") {
Serial.printf("[UART] ESP8266 ack: %s\n", (doc["cmd"] | "?").c_str()); Serial.printf("[UART] ESP8266 ack: %s\n", doc["cmd"] | "?");
} }
else if (type == "pong") { else if (type == "pong") {
Serial.printf("[UART] ESP8266 pong (uptime=%d)\n", doc["uptime_ms"] | 0); Serial.printf("[UART] ESP8266 pong (uptime=%d)\n", doc["uptime_ms"] | 0);
} }
else if (type == "error") { else if (type == "error") {
Serial.printf("[UART] ESP8266 error: %s\n", (doc["msg"] | "?").c_str()); Serial.printf("[UART] ESP8266 error: %s\n", doc["msg"] | "?");
} }
} }