class WLAN – control built-in WiFi interfaces¶
The WLAN class drives the on-board WiFi radios on modern
OpenMV Cams. The same class wraps two different underlying drivers
depending on the board’s WiFi MCU:
CYW43 (Infineon CYW43xxx Murata WiFi module). Used by the OpenMV Cam N6, OpenMV Cam RT1062, Arduino Portenta H7, Arduino Nicla Vision and Arduino Giga R1 WiFi.
NINA W10 (u-blox NINA-W10 / ESP32-WROOM). Used by the Arduino Nano RP2040 Connect.
The two drivers expose the same method names but differ in a few
arguments and the set of accepted config() keys. Differences
are flagged below.
The OpenMV cameras with a legacy WINC1500 WiFi shield (M4 / M7 / H7 /
H7 Plus / Pure Thermal) use WINC instead.
Example usage:
import network
# Enable the station interface and connect to a WiFi AP.
nic = network.WLAN(network.WLAN.IF_STA)
nic.active(True)
nic.connect("your-ssid", "your-key")
while not nic.isconnected():
pass
print(nic.ipconfig("addr4"))
Constructors¶
- class network.WLAN(interface_id: int = WLAN.IF_STA) None¶
Create a
WLANinterface object.interface_idselects which interface to operate on:WLAN.IF_STA– station / client mode. Connect to an upstream access point withconnect(). This is the default.WLAN.IF_AP– access-point mode. Configure the AP withconfig()and accept client connections.
The same physical radio backs both interfaces; constructing one does not preclude the other.
Methods¶
- active(is_active: bool | None = None) bool¶
Bring the WiFi radio up or down.
With no argument, return the current state –
Truewhile the radio is up,Falseotherwise.active(True)powers the WiFi MCU, loads its firmware (CYW43 fetches the firmware blob from flash; NINA validates the currently flashed firmware version) and brings up the lwIP netif for this interface. All other methods –connect(),scan(),ipconfig()and friends – require the interface to be active.active(False)powers the radio back down. On the STA interface this also disassociates from the current AP and releases the netif.
- connect(ssid: str, key: str | None = None, *, security: int = -1, bssid: bytes | None = None, channel: int = -1) None¶
Associate the STA interface with the given access point.
ssid– the network SSID (string or bytes).key– password / pre-shared key. PassNonefor an open network.security(keyword-only) – one of theSEC_*constants.-1(the default) auto-selects:SEC_OPENwhenkeyis empty,SEC_WPA_WPA2otherwise.bssid(keyword-only, CYW43 only) – restrict the association to the AP with this 6-byte MAC address. Ignored by the NINA driver.channel(keyword-only) – preferred radio channel. Default is “let the driver choose”.
- disconnect() None¶
In STA mode, disassociate from the currently associated access point. The interface stays active; call
connect()again to re-associate, oractive()(False)to power the radio down completely. No-op when not currently associated.
- isconnected() bool¶
In STA mode return
Truewhen associated with an access point and an IPv4 address has been obtained from DHCP (or assigned statically throughipconfig()). ReturnsFalsewhile the link is still in the authenticating/associating/DHCP phase.In AP mode return
Truewhen at least one station has joined.
- scan(*, passive: bool = False, ssid: bytes | None = None, bssid: bytes | None = None) List[Tuple[bytes, bytes, int, int, int, int]]¶
Scan for nearby access points and return a list of 6-tuples:
[0]SSID (bytes; empty for hidden networks).[1]BSSID (6-byte MAC,bytes). Convert withbinascii.hexlify().[2]Channel number.[3]RSSI in dBm.[4]Security mode (one of theSEC_*constants).[5]Reserved (always1).
All keyword arguments are CYW43-only:
passive– ifTrue, use a passive scan instead of the default active probe-request scan.ssid– restrict the scan to one SSID.bssid– restrict the scan to one BSSID.
Scanning is only meaningful on a STA interface.
- status() int¶
- status(param: str) Any
Query connection status.
With no argument, return the link status as a small integer (driver-specific encoding – truthy means “associated”).
With a string argument:
"rssi"– in STA mode, return the current RSSI in dBm."stations"– in AP mode, return a list of connected stations. CYW43 returns[(mac_bytes,), ...]; NINA returns[ip_string, ...].
- ifconfig(config: Tuple[str, str, str, str] | None = None) Tuple[str, str, str, str] | None¶
Get or set IPv4 interface parameters as a 4-tuple of
(ip, subnet, gateway, dns)dotted-quad strings.Note
Prefer
ipconfig()for new code:nic.ipconfig(addr4="192.168.0.4/24", gw4="192.168.0.1") network.ipconfig(dns="8.8.8.8")
- ipconfig(param: str) Any¶
- ipconfig(**kwargs: Any) None
Get or set IPv4 / IPv6 interface parameters. The CYW43 driver delegates to the standard lwIP implementation and supports the full set of keys documented on
AbstractNIC.ipconfig(). The NINA driver implements a smaller per-interface subset –dhcp4andhas_dhcp4(read-only), plusaddr4andgw4for get / set.
- config(param: str) Any¶
- config(**kwargs: Any) None
Get or set WiFi-specific interface parameters.
With a single positional string argument, return the value of that parameter. With keyword arguments, set one or more parameters at once – changes that affect a running AP cause the AP to be cycled down and back up automatically.
Example:
# Set up the access-point name and channel. ap.config(ssid="My AP", channel=11) # Query params one at a time. print(ap.config("ssid")) print(ap.config("mac"))
CYW43 driver – gettable parameters:
"antenna"– antenna selector (int)."channel"– current channel."ssid"/"essid"– the current SSID (string)."security"– the AP’s auth mode (one ofSEC_*)."mac"– interface MAC address (6bytes)."pm"– power-management value."txpower"– transmit power in dBm."hostname"– DHCP/mDNS hostname. Deprecated; usenetwork.hostname()instead.
CYW43 driver – settable parameters:
antenna=<int>– antenna selector.channel=<int>– AP channel.ssid=<str>/essid=<str>– AP SSID.key=<str>/password=<str>– AP pre-shared key.security=<int>– AP auth mode (one ofSEC_*).pm=<int>– power management mode (one ofPM_NONE,PM_PERFORMANCE,PM_POWERSAVE).monitor=<int>– enable monitor / all-multicast mode.txpower=<int>– transmit power in dBm.trace=<int>– internal driver trace bitmask.hostname=<str>– DHCP/mDNS hostname. Deprecated; usenetwork.hostname()instead.
NINA driver – gettable parameters:
"ssid"– the current SSID (string)."security"– the AP’s auth mode."mac"/"bssid"– interface MAC address (6bytes)."fw_version"– a 3-tuple(major, minor, patch).
NINA driver – settable parameters: the call forwards to
connect()and accepts the same keyword arguments (ssid,key,security,channel). Only valid on the AP interface.
- deinit() None¶
Power-cycle the WiFi MCU and release every resource the driver holds (firmware buffers, lwIP netif, SPI/SDIO bus). After calling this the
WLANobject must be reconstructed before use. Use this rather thanactive()(False)when you need a full reset (for example, before re-flashing the radio’s firmware or to recover from a wedged driver state). CYW43 only.
- send_ethernet(buf: bytes) None¶
Inject the raw Ethernet frame
bufdirectly into the driver’s transmit path, bypassing the IP stack. Intended for L2-only consumers – bridging, custom EtherType protocols, and similar. The frame must include destination/source MAC and EtherType (no FCS – the hardware appends it). CYW43 only.
- ioctl(cmd: int, buf: bytearray) None¶
Issue a driver-specific control command.
cmdis the numeric ioctl code defined by the underlying radio firmware andbufis a mutable buffer used for both the command payload and the response. The set of validcmdvalues is driver-specific and not portable between CYW43 and NINA. Used mostly by low-level test scripts and chip-bring-up code.
Constants¶
- SEC_WPA_WPA2: int¶
Security value for WPA / WPA2 with a pre-shared key. The default when a key is supplied to
connect(). Available on both drivers.
- SEC_WEP: int¶
Security value for WEP (Wired Equivalent Privacy). Provided for compatibility with legacy access points – WEP is cryptographically broken and should not be used on new deployments. NINA-only.
- WPA_PSK: int¶
Back-compat alias for
SEC_WPA_WPA2. New code should useSEC_WPA_WPA2. NINA-only.