Repository navigation
feat(lan): serve LAN direct on ESP WiFi builds - #136
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
…covery core-interface gets lan.rs: connection slots, frames in and out per connection (command responses, a system state with the client's command availability and the LAN address, the full vehicle state), the UDP discovery reply and the mDNS TXT records. Sessions now know whether their link is LAN or relay, and handshake inits are rate-limited before any X25519 work. SystemState.lan_address goes out over BLE too. The PC board serves it with [network.lan] (non-blocking sockets polled from one task, mDNS through mdns-sd), and tools/lan_client.py plays the app's part for an end-to-end test. Closes #120 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
Enrolling a client key needs a validated phone, so the LAN tests validate both phones, enroll them, then end the validations by approving another car, like the secure channel tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
With [network.lan] enabled on a WiFi build, xtask enables board-esp's `lan` feature and spawns start_lan on the WiFi stack: - a task per connection plus a spare, each with its own TcpSocket, so lan_accept can replace a connection without a session; - the UDP discovery responder; - an address task that reports SystemState.lan_address on DHCP changes and runs a minimal mDNS responder (core-interface lan_mdns.rs: PTR, SRV, TXT and A, legacy unicast for the app's one-shot query). Logs the free heap on each connection and the handshake time, for the C3 measurements. LTE builds leave LAN out with a warning. CI lints and builds the example config with LAN on. Closes #121 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
Hardware test: WiCAN (ESP32-C3) + virtual-carTested together with contracts#52, firmware#135 (included in this build) and mobile-app#138. Requested changes
ResultsSetup (2026-12-06)
1. [Analysis] Boot, and Bluetooth with the new app: passThe boot log shows 2. [PR] Bluetooth off → Wi-Fi, commands, connection log, settings: pass, but see the tier change below
Lock and unlock work over Wi-Fi. The connection log shows Wi-Fi connected, and Settings hides the Bluetooth-only sections and shows the Wi-Fi address row. The availability over LAN follows the dev lock (dimmed while locked), and the dev lock can only be unlocked over Bluetooth, as expected for a system command. 3. [PR] Discovery, from the container: pass
4. [Analysis] Strangers on the LAN can't push the phone off: pass (twice)With the phone's session in slot 0, three raw TCP connections were opened one second apart and never handshaked. Each took slot 1 from the previous one, and the last was closed 10.0 s after connecting. The phone's session never dropped. The free heap was 66380 B with the phone alone and 65892 B with the phone and one stranger. 5. [PR] Board reset while on Wi-Fi: pass, but slow on the direct path
Through the VPN, the subnet router reset the dead connection quickly. On the direct path nothing tells the app the board is gone, so it waits for its idle keepalive (see mobile-app#138). 6. [Analysis] Bluetooth back on → LAN released: pass (twice)Direct: BLE connected at 01:36:45.9, the app subscribed at 01:36:47.46, and the LAN connection was 7. [PR] Manual Wi-Fi address: pass as built, but the requested behaviour changes (see mobile-app#138)With 10. [Analysis] Screen lock and unlock on Wi-Fi: passScreen off at 01:33:53, and Android cut the app's network about 4 s after it stopped (board: 8. [PR] Flash and RAM cost on the C3: measuredSame config,
At runtime the free heap stays around 66 KB with one or two LAN connections open, and a handshake takes 183–205 ms (11 handshakes). The heap with MQTT over TLS wasn't measured. Not tested: an address change from DHCP or a WiFi reconnection, the heap with MQTT over TLS, two real phones on the LAN at once (the second session was a PC client), iOS, LTE builds (LAN is left out by design), E-GMP in the car, and the 0x310 frame on |
…racts#52) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
- A secure channel session gets the basic vehicle state only, and its client's advanced commands are reported unavailable and refused with REJECTED_UNAVAILABLE: reaching the device over a network is no proof of being at the car. - The system state repeats every LAN_SYSTEM_STATE_REPEAT_MS (from the contract), which the app's receive timeout relies on. - lan_mdns_instance_name: the BLE name and the key ID's first four characters, so the PC board announces the same name as the ESP. - lan_is_open, for the boards' logs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
|
Merged #135 in (c5fa22f). CI is green, including both ESP builds and the "ESP, LAN direct" clippy and build.
The mDNS responder now uses the shared Generated by Claude Code |
Hardware retest: WiCAN (ESP32-C3) + virtual-carRetest after c5fa22f, together with contracts#52 All the requested changes check out. Nothing is left to change from the hardware side. Setup (2026-12-06, same bench as the first test)
R1. Wi-Fi is the remote tier, in the app: passBluetooth off at 04:38:29.19 → LAN connected at 29.39, handshake 190 ms. The pill says Remote, and the dashboard is the remote one (car picture, Doors, Driving, Odometer; no Gear, Speed or Custom 1). Doors lock and unlock work. The connection log says it's Wi-Fi, and Settings still hides the Bluetooth-only sections. Bluetooth back on: BLE connected at 04:56:05.30, and the LAN connection was closed by the app at 06.82. R7. mDNS instance name: passESP: R8. Log reason for a replaced connection: passThree raw TCP connections from the container while the phone held slot 0: both replacements logged as R9. Where the ~128 KB of flash goesImage with LAN on: 1,483,480 B (about 1 KB more than the first round). By symbol, LAN off → on, with
Your reading was right: most of it is the secure channel, which the relay will reuse. Display instead of Debug would save under 3 KB, and dropping UDP discovery only a few KB, so no trimming is needed for now. Not retested (code unchanged): the probe byte format and its rate limit, the 10 s handshake timeout. Still not tested: an address change from DHCP or a WiFi reconnection, the heap with MQTT over TLS, two real phones, iOS, LTE builds, E-GMP in the car, |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
Requested by Michaël · project thread
What and why
LAN direct on ESP WiFi builds. Closes #121, part of OpenCarControls/contracts#44. Stacked on #135 (the core LAN part, PC board): it targets
mainso that CI runs (CI only runs on PRs tomain), so the diff also shows #135's commits until that merges. The last commit is the ESP work.boards/esp/src/lan.rs(lanfeature): one task per connection plus a spare, solan_acceptcan replace a connection without a session or refuse a new one. Each connection runs its reader, writer and a once-a-secondlan_should_closecheck side by side. TCP keepalive 20 s, timeout 60 s.lan_discovery_reply.SystemState.lan_addresswhen DHCP changes the address, and runs the mDNS responder: it joins 224.0.0.251, announces twice on each new address, and answers queries.core-interface/src/lan_mdns.rs: a minimal mDNS responder (PTR, SRV, TXT, A for_opencar._tcp). It handles legacy unicast queries, which is what the app sends: answered by unicast with the ID and question echoed, a 10 s TTL and no cache-flush bit. Host-tested.lanand spawnsstart_lanon WiFi builds. An LTE build leaves LAN out with a warning. The stack getsLAN_MAX_CLIENTS + 3more sockets.LAN: handshake answered in … ms).lanfeature is compiled.docs/lan.md(ESP board, the mDNS responder),docs/architecture.md,config.toml.example.How it was tested
core-interface/tests/lan.rs: the mDNS answer to a legacy unicast and a multicast query, record by record, the announcement, and silence for other names, responses, truncated or looping names, and no identity. xtask tests coverlan_on_uplink.cargo test -p xtaskandcargo fmt --checkpass locally.lanfeature and thestart_lanspawn for a WiFi config with LAN on.lan.Checklist
feat(scope):,fix(scope):,docs:,chore:)cargo fmt --all -- --check,cargo xtask clippyandcargo xtask testpass (fmt passes; clippy and tests left to CI)docs/or README) updated if behaviour changedconfig.toml, credentials, build artifacts or.binfiles committedSafety
The board only moves bytes. Authorization and the secure channel are in core-interface, unchanged here.
https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
Generated by Claude Code