Expand description
WiFi radio and TCP/IP stack (esp-radio + embassy-net).
One of two modes is chosen at boot from Config::connection:
- Access point (default): static IPv4
192.168.4.1/24plus a DHCP server handing out leases to AP clients (dhcp). - Station: joins the configured network and gets its address via
DHCP. If the association does not come up within
STA_CONNECT_TIMEOUTโ or the DHCP lease does not arrive withinSTA_DHCP_TIMEOUTโ the device switches to AP mode instead so it stays reachable. After a successful station boot, a lost association is retried everySTA_RECONNECT_DELAY(the device then stays in station mode, so reachability depends on the AP coming back).
The event loop at the end of task doubles as the controller
keep-alive: dropping WifiController de-initializes the radio.
In both modes the HTTP/WebSocket server (http, ws) is started
on the stack once the interface is up.
Modulesยง
- dhcp ๐
- Minimal
DHCPv4server for access-point clients. - http
- Minimal HTTP/1.1 server with fixed connection slots.
- ws ๐
- Minimal WebSocket server (RFC 6455 subset) with JSON envelopes.
Constantsยง
- AP_IP
- Static IPv4 address of the access point โ also the DHCP server identifier handed out in option 54.
- AP_
PREFIX - Prefix length of the access-point subnet.
- SOCKETS ๐
- Socket slots in the network stack โ four HTTP connection slots plus the DHCP server (AP mode) or DHCP client (station mode), with headroom.
- STA_
CONNECT_ ๐TIMEOUT - Maximum time to wait for a station association before falling back to access-point mode.
- STA_
DHCP_ ๐TIMEOUT - Maximum time to wait for the station DHCP lease before falling back to access-point mode.
- STA_
RECONNECT_ ๐DELAY - Pause between station re-association attempts after a runtime disconnect (the boot-time fallback does not apply here โ the device keeps retrying).
Staticsยง
- STACK_
AP ๐ - Socket storage for the AP-mode stack, kept separate from
STACK_STAso a DHCP-timeout fallback can bring the AP up beside the idle station stack (both cells always cost ~2 KiB of.bss). - STACK_
STA ๐ - Socket storage for the station-mode stack โ used when the boot path attempts a station lease (the cell is abandoned if DHCP times out).
Functionsยง
- ap_ssid ๐
- Resolves the AP SSID: the configured one, or a MAC-derived default.
- build_
ap ๐ - Builds the access-point configuration for
esp-radio. - build_
sta ๐ - Builds the station configuration for
esp-radio. - runner_
task ๐ - Drives the network device event loop (spawned by
spawn_runner). - spawn_
runner ๐ - Spawns the embassy-net driver loop (logged, non-fatal on failure).
- stack_
seed ๐ - Deterministic seed for the network stack, derived from the factory MAC address (keeps ephemeral port selection stable across reboots).
- start_
ap ๐ - Brings up the embassy-net stack on the access-point interface with a static address and spawns the DHCP server for AP clients.
- start_
station ๐ - Brings up the embassy-net stack on the station interface with a DHCP client and waits for the lease.
- task
- Network task: brings up
WiFiin station or AP mode and runs the event loop. - try_
station ๐ - Races the station association against
STA_CONNECT_TIMEOUT.