Skip to main content

Module net

Module net 

Source
Expand description

Wi-Fi: scanning, and station networking (connect, DHCP, DNS, UDP/TCP via embassy-net) plus network time. Requires the wifi feature.

ⓘ
let stack = net::start_station(spawner, board.radio.wifi, Credentials { ssid, password })?;
stack.wait_config_up().await;               // associated + DHCP lease
let clock = net::sync_clock(stack, net::DEFAULT_NTP_SERVER).await?;
let now = clock.now(utc_offset_minutes);    // calendar date/time

start_station spawns two tasks: one keeps the link up (reconnecting every 5 s after a drop), the other runs the IP stack. Link state and signal strength are published in atomics (link), so any task can show them without owning the radio. It takes the radio for the rest of the boot.

Scanning is separate and repeatable: scanner borrows the radio and releases it when the Scanner is dropped.

ⓘ
let mut scanner = net::scanner(board.radio.wifi.reborrow())?;
for ap in scanner.scan().await? {
    info!("{} dBm ch {} {}", ap.signal_strength, ap.channel, ap.ssid);
}

Re-exports§

pub use embassy_net;

Modules§

link
Wi-Fi link status, readable from anywhere.

Structs§

AccessPointInfo
Information about a detected Wi-Fi access point.
Credentials
Network credentials. An empty password selects an open network.
DateTime
A calendar date and time.
ScanConfig
Scan configuration.
Scanner
A Wi-Fi scanner. Dropping it switches the radio off again.
ServerTime
Time reported by a server.
WallClock
Wall-clock time anchored to the monotonic clock at one SNTP sample.
WifiController
Wi-Fi controller.

Enums§

AuthenticationMethod
Supported Wi-Fi authentication methods.
Error
Errors from start_station and scanner.
TimeError
Errors from query_time.

Constants§

DEFAULT_NTP_SERVER
A public NTP pool; any SNTP server name or IPv4 literal works.
SOCKETS
Sockets available to the application (DHCP and DNS use their own).

Functions§

query_time
Asks an SNTP server for the time (one UDP round trip, 3 s timeout).
scan_config
A scan configuration that finds networks reliably: active probing with 30–120 ms per channel (ESP-IDF’s maximum; esp-radio’s 10–20 ms default misses access points whose beacons come every ~100 ms), hidden networks included, at most 32 results.
scanner
Starts the radio for scanning. Takes about 1.5 s per Scanner::scan.
start_station
Starts Wi-Fi in station mode with DHCP and returns the IP stack. Await stack.wait_config_up() before opening sockets.
sync_clock
query_time and anchor the result.