firmware: retarget camera-node MQTT bridge to XIAO ESP32-C6

The MCU changed from ESP32 Dev Board to a Seeed Studio XIAO ESP32-C6,
but the firmware still targeted esp32dev. Retarget it and fix the
build so it compiles and flashes for the C6.

platformio.ini:
- env esp32-mqtt -> seeed_xiao_esp32c6 on the pioarduino platform fork
  (mainline espressif32 lags the Arduino-core 3.x the C6 needs)
- add ARDUINO_USB_MODE=1 / ARDUINO_USB_CDC_ON_BOOT=1 for Serial over
  the C6 native USB
- fix build_src_filter ordering in BOTH envs: -<*.cpp> ran last and
  re-excluded the target, leaving setup()/loop() undefined at link

esp32-mqtt-bridge.cpp:
- UART Serial2 RX16/TX17 -> Serial1 RX=D7/TX=D6 (XIAO C6 mapping)
- status LED GPIO2 -> D1 (green channel of the RGB STAT LED)
- fix pre-existing ArduinoJson v7 / PubSubClient build errors
  (.c_str() on a const char*, String topic where const char* required)

Verified: builds clean and boots on hardware (native-USB serial banner
confirmed).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Joshua King
2026-06-04 18:12:01 -04:00
parent a478f7d478
commit 2fb73ec8c4
2 changed files with 49 additions and 33 deletions
+24 -17
View File
@@ -19,10 +19,10 @@
* ESP32 → ESP8266: {"type":"cmd","command":"ping"}\n
*
* Hardware:
* - ESP32 Dev Board (or D1 Mini ESP32)
* - UART2: RX=GPIO16, TX=GPIO17 (connected to ESP8266)
* - Seeed Studio XIAO ESP32-C6
* - Serial1: RX=D7, TX=D6 (crossed to the ESP-01S TX/RX)
* - 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>
@@ -80,13 +80,19 @@ bool saveConfig() {
}
// ────────────────────────────────────────────
// UART to ESP8266 (HardwareSerial2)
// UART to ESP-01S (HardwareSerial1)
// ────────────────────────────────────────────
// ESP32 UART2: RX=GPIO16, TX=GPIO17
// Connect: ESP32 RX(16) ← ESP8266 TX
// ESP32 TX(17) → ESP8266 RX
// XIAO ESP32-C6 Serial1: RX=D7, TX=D6 (Serial = native USB CDC)
// Connect: XIAO RX(D7) ← ESP-01S TX
// 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) {
JsonDocument doc;
@@ -187,7 +193,8 @@ bool connectMQTT() {
JsonArray caps = doc["capabilities"].to<JsonArray>();
caps.add("start_stop"); caps.add("status");
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");
}
@@ -204,14 +211,14 @@ void setup() {
Serial.println("\n[BRIDGE] ESP32 MQTT Bridge v1.0");
bootMs = millis();
pinMode(2, OUTPUT); // built-in LED
digitalWrite(2, LOW);
pinMode(STAT_LED_PIN, OUTPUT); // RGB STAT LED — green = camera online
digitalWrite(STAT_LED_PIN, LOW);
loadConfig();
// UART to ESP8266
UART_ESP8266.begin(115200, SERIAL_8N1, 16, 17); // RX=16, TX=17
Serial.println("[UART] ESP8266 link on RX16/TX17 @ 115200");
// UART to ESP-01S
UART_ESP8266.begin(115200, SERIAL_8N1, UART_RX_PIN, UART_TX_PIN);
Serial.println("[UART] ESP-01S link on Serial1 (RX=D7, TX=D6) @ 115200");
// Connect to travel router — the ONLY network we touch
Serial.printf("[WIFI] Connecting to: %s\n", cfg.wifi_ssid.c_str());
@@ -278,7 +285,7 @@ void loop() {
if (online != cameraOnline) {
cameraOnline = online;
digitalWrite(2, online ? HIGH : LOW);
digitalWrite(STAT_LED_PIN, online ? HIGH : LOW);
}
if (cfg.camera_id.length() > 0) {
@@ -297,13 +304,13 @@ void loop() {
}
}
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") {
Serial.printf("[UART] ESP8266 pong (uptime=%d)\n", doc["uptime_ms"] | 0);
}
else if (type == "error") {
Serial.printf("[UART] ESP8266 error: %s\n", (doc["msg"] | "?").c_str());
Serial.printf("[UART] ESP8266 error: %s\n", doc["msg"] | "?");
}
}