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/timestart_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§
- Access
Point Info - Information about a detected Wi-Fi access point.
- Credentials
- Network credentials. An empty password selects an open network.
- Date
Time - A calendar date and time.
- Scan
Config - Scan configuration.
- Scanner
- A Wi-Fi scanner. Dropping it switches the radio off again.
- Server
Time - Time reported by a server.
- Wall
Clock - Wall-clock time anchored to the monotonic clock at one SNTP sample.
- Wifi
Controller - Wi-Fi controller.
Enums§
- Authentication
Method - Supported Wi-Fi authentication methods.
- Error
- Errors from
start_stationandscanner. - Time
Error - 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_timeand anchor the result.