How drrcastro/esp-lego-loco works
ESP-lego-loco is a modular firmware and control system for autonomous model trains: a Master coordinates locomotive and smart-station nodes, while a browser dashboard configures and monitors the layout. The main workflow runs from beacon and station sensing, through node telemetry and topology tracking, to dispatch controls and locomotive motion. The repository also documents a standalone browser firmware flasher. Several implementation excerpts are partial; edges are limited to README-documented relationships or visible source references and calls, with uncertain wiring omitted.
Main entry points: ESPNowManager.cpp ESP-NOW Messaging · loco/main.cpp Locomotive Firmware · track/main.cpp Station Firmware · TopologyManager.cpp Topology Manager
Components 20
Master Coordination
- Master Firmware
src/master/main.cpp - Topology Manager
src/master/TopologyManager.cpp - ESP-NOW Messaging
lib/ESPNowManager/ESPNowManager.cpp - Message Protocol
lib/ESPNowManager/ProtocolMessages.h - Configuration Store
lib/ConfigStore/ConfigStore.cpp
Train Firmware
- Locomotive Firmware
src/loco/main.cpp - Station Firmware
src/track/main.cpp
Device Services
- Motor Control
lib/MotorController/MotorController.cpp - Lighting System
lib/LightingSystem/LightingSystem.cpp - IR Telemetry
lib/IRTelemetry/IRTelemetry.cpp - Track Manager
lib/TrackManager/TrackManager.cpp - Station Display
lib/StationDisplay/StationDisplay.cpp
Web Control
- Web Server API
lib/WebServer/LocoWebServer.cpp - Dispatch Dashboard
data/app.js - Web UI Assets
data/index.html
Browser Flasher
- Web Flasher
tools/web-flasher/flasher.js - Merged Firmware Images
tools/web-flasher/binaries
Other components
- Layout Operator
- Operator Browser
- ESP Boards
Connections 22
- Layout Operator → Operator Browser: operates
README.md - Operator Browser → Dispatch Dashboard: loads
README.md - Web UI Assets → Web Server API: served by
README.md - Dispatch Dashboard → Web Server API: controls and monitors
README.md - Master Firmware → Web Server API: hosts
README.md - Master Firmware → Topology Manager: coordinates topology
README.md - Topology Manager → Configuration Store: loads and saves
src/master/TopologyManager.cpp - Topology Manager → Web Server API: broadcasts telemetry
src/master/TopologyManager.cpp - Topology Manager → ESP-NOW Messaging: sends commands
src/master/TopologyManager.cpp - Locomotive Firmware → Motor Control: initializes
src/loco/main.cpp - Locomotive Firmware → Lighting System: sets lighting
src/loco/main.cpp - Locomotive Firmware → ESP-NOW Messaging: sends telemetry
src/loco/main.cpp - Station Firmware → Track Manager: controls switch and dwell
src/track/main.cpp - Station Firmware → Station Display: updates display
src/track/main.cpp - Station Firmware → ESP-NOW Messaging: sends telemetry
src/track/main.cpp - Locomotive Firmware → IR Telemetry: uses beacon sensing
- Station Firmware → IR Telemetry: uses beam sensing
- ESP-NOW Messaging → Message Protocol: encodes messages
- Master Firmware → ESP-NOW Messaging: uses node messaging
- Operator Browser → Web Flasher: opens
README.md - Web Flasher → Merged Firmware Images: flashes image
README.md - Web Flasher → ESP Boards: programs over USB
README.md