Firmware is the small program on the ESP32. It reads beam sensors, remembers the precise local time of a beam break, then reports that event to the Raspberry Pi. This chapter also works as a specification for a developer or AI agent.
module_role: start|finish, not four special builds.The configuration file makes the same ESP32 program become a start or finish module. Do not change it during a race, and do not keep Wi-Fi passwords in publicly shared example files.
device_id: start-01
module_role: start
gpio:
lane_1: 16
lane_2: 17
sensor:
active_level: 0
debounce_us: 15000
network:
ssid: RacingManager
server_url: ws://192.168.50.1:8080/hardware/esp32/ws
transport:
primary: wifi
rs485_fallback: false
The finish module uses device_id: finish-01 and module_role: finish. Verify active_level with the actual sensor: the health view must say clear when the beam is clear. With the ADA2167 and an internal pull-up, a broken beam reads LOW, so active_level: 0 is correct. GPIO 16/17 are the free inputs on the ESP32 board with the integrated LCD; on a plain DevKit, 32/33 also work — see Wiring.
On the Racing Manager side, this is the ESP32_WEBSOCKET_DIRECT race-device mode (“ESP32 WebSocket Direct Connect” in the settings UI): the Pi hosts the WebSocket server at /hardware/esp32/ws and the modules dial in as clients — the reverse of the older HARDWARE mode, which dialed out to a separate Raspberry Pi controller. The shipped default expects 4 single-sensor modules (lane-1-start, lane-1-finish, lane-2-start, lane-2-finish, one GPIO input each) rather than the 2 dual-lane modules (start-01/finish-01) shown above — both module counts speak the same protocol; the expectedDeviceIds setting controls which device_ids the server accepts. The backend does not yet implement the race.arm/race.armed/race.start/race.reset handshake or time.sync_request/time.sync_response: it currently only consumes device.register, device.heartbeat, and sensor.event, timing each lane from the receipt-time delta between its start and finish beam_broken events.
The ESP32 sensor firmware guide contains complete, ready-to-flash Arduino sketches for one sensor input — one for a plain DevKit and one for the board with the integrated display, including board settings, the required libraries, and the display pin map. It is the fastest way to prove the hardware works, and a useful starting point before implementing the full ESP-IDF module described here. That guide exists in English only and is shared by both language editions.
Boot → sensor self-test → connect Wi-Fi/RS485 → register → heartbeat
→ race.arm → collect local sensor events → race.start → send events
→ race.reset
On network loss, retain events with event_id and sequence in a bounded queue. After reconnect, resend until the server returns event.ack. The server must deduplicate on device_id + boot_id + sequence.
Only the first valid beam_broken for a race_id, role, and lane counts. Ignore later edges for at least debounce_us and until race.reset for that measurement. Report sensor state independently of a race as sensor.status.
Show module role, Wi-Fi/RS485 state, server contact, L1/L2 clear/blocked, current race_id, last event, and firmware version. Only hard-wire a display board after its actual pinout is documented and compared to WIRING.md.
Navigation: ← Wiring · Next: Protocol → · Deutsch
Shared resources: CAD package · ESP32 sensor firmware guide
All topics: Project overview · Materials · Architecture · Wiring · Firmware · Protocol · Setup · Testing · ESP agent brief · Racing Manager integration