# Architecture Overland Controller is a distributed monitoring and control platform for mobile power systems and overland vehicles. Core principle: Cargo ESP32 = controller / source of truth Waveshare ESP32-S3 dashboard = local touchscreen client Phone/laptop WebUI = configuration interface Home server = future optional remote access layer The system must work locally without internet. ## Cargo ESP32 Controller The Cargo ESP32 owns critical control state and configuration. Responsibilities: - Read JBD/Xiaoxiang BMS data over BLE - Read DS18B20 temperature sensors - Control relay trigger outputs - Store configuration - Serve HTTP API - Serve local WebUI - Run WiFi AP mode - Maintain status, alarms, and fault state The Cargo ESP32 should not depend on the dashboard, phone, home server, or internet for core operation. ## Waveshare ESP32-S3 Dashboard Target hardware: - Waveshare ESP32-S3 Touch LCD 5B - 5 inch 1024x600 capacitive touchscreen - ESP32-S3 - 16MB flash - 8MB PSRAM - WiFi + BLE - CAN with onboard TJA1051 transceiver - microSD - 7-36V VIN support Responsibilities: - Native LVGL dashboard - Connect to Cargo ESP32 AP as WiFi client - Poll Cargo ESP32 HTTP API - Send simple control commands through HTTP API - Display battery, relay, temp, vehicle, and alert data - Future CAN vehicle data - Future transmission temperature sender display The dashboard is a client only. It must not own relay state, BMS config, alarms, or persistent configuration. ## WebUI The WebUI remains hosted by the Cargo ESP32. Use WebUI for: - Setup/configuration - Relay names - Temperature sensor names - BMS setup - Recovery - API testing Avoid complex configuration on the touchscreen dashboard. ## Network Cargo ESP32 runs WPA2 AP mode continuously. Expected local URL: http://192.168.4.1 Dashboard connects to that AP and talks HTTP. No UART cable is planned between dashboard and Cargo ESP32. ## HTTP API HTTP is the primary integration contract for: - WebUI - Dashboard - Simulator - Future home server - Future MQTT/Home Assistant/Grafana integrations Preferred direction: GET /api/v1/health GET /api/v1/capabilities GET /api/v1/status GET /api/v1/config GET /api/v1/config/export POST /api/v1/config/import POST /api/v1/relay/set Only `/api/v1` routes are registered; root-route compatibility aliases are not part of the current API. ## Generic IDs Firmware uses generic IDs. Relays: relay_1 relay_2 relay_3 relay_4 relay_5 relay_6 Temperature sensors: temp_1 through temp_4 Install-specific names belong in saved configuration only. Examples: Fridge Starlink Cabin Outside House Battery ## Status Model Dashboard should be able to render from status/config responses without duplicating business logic. Expected status groups: battery temps relays vehicle network alarms system config ## Vehicle Data Use standard OBD-II over CAN first. Planned standard PIDs: 0105 coolant temperature 010C RPM 010D vehicle speed Transmission temperature is planned through a dedicated sender rather than Nissan CAN reverse engineering. ## Future Home Server Future optional architecture: Phone/PWA -> Home server HTTPS -> MQTT/WebSocket/HTTPS bridge -> Cargo ESP32 outbound connection Remote features must not break local operation. ## Cargo-led AP Pairing and Credential Migration The Cargo ESP32 owns the local overland network. It is the AP owner, source of truth, and configuration authority. Target behavior: 1. Cargo ESP32 starts a WPA2-protected AP. 2. Cargo OLED shows setup credentials and critical recovery/status information. 3. Phone connects to the Cargo AP and uses the WebUI for setup/admin. 4. Dashboard ESP32-S3 joins the Cargo AP as a client. 5. If the user changes the Cargo AP SSID/password, the Cargo ESP stages the new credentials and coordinates dashboard migration. 6. Dashboard stores the new credentials before the Cargo AP restarts. 7. Cargo AP applies the new credentials. 8. Dashboard reconnects automatically. The dashboard should not own network authority. A temporary dashboard setup AP may exist only as a recovery/fallback mechanism, not the normal pairing path. Recovery target: - A setup/status button on the Cargo ESP enclosure can show AP credentials on the OLED. - A long hold can restore factory AP credentials or enter recovery mode. ## Current communications and GPIO decision Active dashboard communication is WiFi/HTTP using `/api/v1`. The old Pico/dashboard UART path is retired from active hardware use. USB Serial remains available for development, debug, and manual configuration from a computer. The active LILYGO Cargo profile uses its onboard 74HC595 for relay control. GPIO4 is the relay output-enable pin and the DS18B20 OneWire bus uses GPIO15. See `docs/HARDWARE.md` for the complete current pin map. ## Role Boundary Summary See `docs/controller-roles.md` for the authoritative role split. Committed v1 architecture: Dashboard ESP32-S3 <-> WiFi / HTTP REST Cargo ESP32 AP <-> control outputs Automotive load-switching layer <-> fused loads Fridge / Starlink / lights / spare outputs The Cargo ESP32 owns power-system control. The Dashboard ESP32-S3 renders the touchscreen UI and future vehicle visualization. For v1, controller-to-dashboard communication is WiFi/HTTP only. ESP-NOW, MQTT, UART, and CAN-between-controllers are not part of the v1 dashboard link. The load-switching hardware is not finalized. Bosch relays, WUPP-style modules, smart high-side switching, or a future custom PCB remain implementation options until explicitly selected. ## Dashboard Hardware Target The current dashboard hardware target is the Waveshare ESP32-S3 Touch LCD 5B. Selected dashboard hardware: - Waveshare ESP32-S3 Touch LCD 5B - 5-inch touchscreen - 1024x600 display resolution - Capacitive touch - Native WiFi - LVGL-capable ESP32-S3 platform - Integrated CAN transceiver available for future vehicle integration This replaces the earlier Pico dashboard concept as the active dashboard architecture. The Dashboard ESP32-S3 communicates with the Cargo ESP32 over WiFi/HTTP REST for v1. CAN/OBD-II support remains a future dashboard-side vehicle-visualization feature and is not part of the Cargo ESP32 role. ## Existing DS18B20 Temperature Support DS18B20 temperature sensor support is already part of the Cargo ESP architecture. Current responsibility split: - Cargo ESP32 owns DS18B20 sensor reading. - Cargo ESP32 exposes temperature state through the WebUI/API path. - Dashboard ESP32-S3 should consume temperature data from the Cargo ESP API. - Dashboard ESP32-S3 should not wire directly to cargo-area DS18B20 sensors for v1. This means future dashboard work should display existing Cargo ESP temperature telemetry rather than reimplementing temperature sensing on the dashboard. ## Cargo ESP API Contract The Cargo ESP API contract is documented in `docs/API.md`. The Cargo ESP32 is the source of truth for: - Relay/output state - DS18B20 temperature readings - BMS telemetry - Alarm/fault state - Local configuration The ESP32-S3 dashboard should consume Cargo ESP API data over WiFi/HTTP REST instead of directly owning cargo sensors or relay state. ## Cargo ESP Hardware Profile The active Cargo profile is `lilygo_trelay_s3_6ch`: six outputs driven through the LILYGO T-Relay-S3 onboard 74HC595. Clients must render the output list returned by the API rather than assuming a fixed relay count. Bench test relay boot state and CH1–CH6 mapping before connecting vehicle loads. ## Planned WebSocket Push Layer The project may add a WebSocket push layer in addition to the current `/api/v1` REST API. This is intended as an additive transport, not a replacement for the REST API. Recommended model: ```text Dashboard ESP <-- WebSocket /ws live status -- Cargo ESP Dashboard ESP -- REST /api/v1 relay commands -> Cargo ESP Dashboard ESP -- REST /api/v1/status fallback -> Cargo ESP ``` The REST API remains the canonical, human-debuggable contract for snapshots, testing, and compatibility. WebSockets should be used for live status pushes so dashboard UI elements can update immediately after sensor changes, relay state changes, and future vehicle telemetry updates. Initial implementation should preserve existing polling as a fallback path. If the WebSocket connection is unavailable or stale, the dashboard should continue to use `/api/v1/status`.