atomvm_gleam/network
Types
SoftAP options for start_with.
Event callbacks send these messages to notify:
ap_started{sta_connected, Mac}(6-byte MAC binary){sta_disconnected, Mac}{sta_ip_assigned, Address}(Erlang{A, B, C, D})
pub type ApConfig {
ApConfig(
ssid: option.Option(String),
psk: option.Option(String),
ap_channel: option.Option(Int),
ap_ssid_hidden: option.Option(Bool),
ap_max_connections: option.Option(Int),
notify: process.Pid,
)
}
Constructors
-
ApConfig( ssid: option.Option(String), psk: option.Option(String), ap_channel: option.Option(Int), ap_ssid_hidden: option.Option(Bool), ap_max_connections: option.Option(Int), notify: process.Pid, )
Errors from the network driver.
pub type Error {
Failed
NotSupported
Badarg
Timeout
Disconnected
Other(String)
}
Constructors
-
Failed -
NotSupported -
Badarg -
Timeout -
Disconnected -
Other(String)
Address / netmask / gateway triple from DHCP (got_ip / wait_for_sta).
pub type IpInfo {
IpInfo(
address: Ipv4Address,
netmask: Ipv4Address,
gateway: Ipv4Address,
)
}
Constructors
-
IpInfo( address: Ipv4Address, netmask: Ipv4Address, gateway: Ipv4Address, )
IPv4 address as four octets.
pub type Ipv4Address {
Ipv4Address(a: Int, b: Int, c: Int, d: Int)
}
Constructors
-
Ipv4Address(a: Int, b: Int, c: Int, d: Int)
mDNS options passed through network:start/1 as {mdns, […]}.
ttl is optional; omit to use the AtomVM default.
pub type MdnsConfig {
MdnsConfig(host: String, ttl: option.Option(Int))
}
Constructors
-
MdnsConfig(host: String, ttl: option.Option(Int))
SNTP options for start / start_with.
On sync, notify receives {synchronized, {Sec, Usec}}.
pub type SntpConfig {
SntpConfig(host: String, notify: process.Pid)
}
Constructors
-
SntpConfig(host: String, notify: process.Pid)
STA options for start / start_with.
When managed is True, the radio starts without joining until
sta_connect / sta_connect_to.
Event callbacks send these messages to notify:
connected{got_ip, IpInfo}(Erlang{IP, Netmask, Gateway}tuples)disconnected{scan_results, Results}whenscan_doneis wired tonotify
pub type StaConfig {
StaConfig(
managed: Bool,
ssid: option.Option(String),
psk: option.Option(String),
dhcp_hostname: option.Option(String),
notify: process.Pid,
)
}
Constructors
-
StaConfig( managed: Bool, ssid: option.Option(String), psk: option.Option(String), dhcp_hostname: option.Option(String), notify: process.Pid, )
STA connection status from sta_status.
Prefixed constructors avoid clashing with Error variants;
FFI maps AtomVM atoms (associated, connected, …) to these values.
pub type StaStatus {
StaAssociated
StaConnected
StaConnecting
StaDegraded
StaDisconnected
StaDisconnecting
StaInactive
}
Constructors
-
StaAssociated -
StaConnected -
StaConnecting -
StaDegraded -
StaDisconnected -
StaDisconnecting -
StaInactive
Values
pub fn sta_connect() -> Result(Nil, Error)
Connect using credentials from the last start / sta_connect_to config.
See sta_connect.
pub fn sta_connect_to(
ssid: String,
psk: String,
) -> Result(Nil, Error)
Connect to ssid with psk (empty string for open networks).
See sta_connect.
pub fn sta_disconnect() -> Result(Nil, Error)
Disconnect from the current access point.
pub fn sta_status() -> Result(StaStatus, Error)
Current STA interface status.
See sta_status.
pub fn start(
sta: StaConfig,
sntp: option.Option(SntpConfig),
) -> Result(Nil, Error)
Start the network interface (STA + optional SNTP).
Compatibility wrapper around start_with with no AP or mDNS.
See network:start/1
and the 0.7 guide.
pub fn start_with(
sta: option.Option(StaConfig),
ap: option.Option(ApConfig),
sntp: option.Option(SntpConfig),
mdns: option.Option(MdnsConfig),
) -> Result(Nil, Error)
Start the network with optional STA, AP, SNTP, and mDNS sections.
At least one of sta or ap should be provided. STA+AP is supported.
See AP mode and STA+AP mode.
pub fn wait_for_ap(
ssid: option.Option(String),
psk: option.Option(String),
timeout_ms: Int,
) -> Result(Nil, Error)
Blocking convenience: start AP and wait until ready (network:wait_for_ap/2).
Omit ssid / psk (None) to use AtomVM defaults (generated SSID / open AP).
pub fn wait_for_ap_default() -> Result(Nil, Error)
Start AP with empty config and default 15_000 ms timeout (network:wait_for_ap/0).
pub fn wait_for_ap_timeout(timeout_ms: Int) -> Result(Nil, Error)
Equivalent to wait_for_ap(None, None, timeout_ms) (network:wait_for_ap/1
timeout clause).
pub fn wait_for_sta(
ssid: String,
psk: String,
timeout_ms: Int,
) -> Result(IpInfo, Error)
Blocking convenience: start STA with ssid/psk and wait for DHCP
(network:wait_for_sta/2).
Useful for simple apps; badge-style UIs should prefer start +
event messages.
pub fn wait_for_sta_config(
ssid: option.Option(String),
psk: option.Option(String),
) -> Result(IpInfo, Error)
Blocking convenience: start STA with optional credentials and default 15_000 ms
timeout (network:wait_for_sta/1 config clause).
Omit ssid / psk (None) for an empty STA property list (NVS / last config).
pub fn wait_for_sta_default() -> Result(IpInfo, Error)
Blocking convenience: start STA with empty config and default 15_000 ms timeout
(network:wait_for_sta/0).
Useful for simple apps; badge-style UIs should prefer start +
event messages.
pub fn wait_for_sta_timeout(
timeout_ms: Int,
) -> Result(IpInfo, Error)
Blocking convenience: start STA with empty config and timeout_ms
(network:wait_for_sta/1 timeout clause).
pub fn wifi_scan(results: Int) -> Result(Nil, Error)
pub fn wifi_scan_default() -> Result(Nil, Error)
Start a Wi-Fi scan with defaults from the running STA config (network:wifi_scan/0).
Uses default_scan_results, dwell, passive, and hidden settings from the last
start STA config when available. With scan_done → notify, results arrive
as {scan_results, …} on the notify pid.
See wifi_scan.