Explanation of Wireless Network Examples#
Example Locations#
Wi-Fi STA example:
Development board firmware path:
/sdcard/examples/14-Socket/network_wlan_sta.pySDK source code path:
src/canmv/resources/examples/14-Socket/network_wlan_sta.py
Wi-Fi AP example:
Development board firmware path:
/sdcard/examples/14-Socket/network_wlan_ap.pySDK source code path:
src/canmv/resources/examples/14-Socket/network_wlan_ap.py
WLAN Device Selection#
Both examples use:
WLAN_DEVICE = "auto"
Valid values are "auto", "usb", "sdio", and "spi". Typically keep "auto"
to let the system choose from registered devices. Only fix this parameter when
multiple Wi-Fi modules are installed simultaneously and the application must
use a specific transport type.
The current SDK supports RTL8189FTV/RTL8733BS and Broadcom brcmfmac SDIO, RW007
SPI, AIC8800 USB/SDIO, as well as ESP-Hosted SPI/SDIO solutions enabled per
firmware configuration. For details on specific drivers, default board
configuration, and security mode restrictions, see
Wi-Fi Drivers and Device Selection. WLAN_DEVICE
only selects the transport type and cannot select between devices from
different vendors or models on the same bus.
Wi-Fi STA Example#
STA mode is used to connect to an existing wireless router or hotspot.
Configure Credentials#
SSID = "TEST"
PASSWORD = "12345678"
WLAN_DEVICE = "auto"
Modify the SSID and password to match the on-site hotspot information. SSID is case-sensitive.
Connect and Wait for Address#
from libs.Network import connect_network
sta, ip = connect_network(
"wifi_sta",
ssid=SSID,
password=PASSWORD,
wlan_device=WLAN_DEVICE,
timeout=10,
)
This step sequentially completes physical WLAN selection, device registration waiting, hotspot connection, DHCP address waiting, and default uplink configuration. An exception is thrown on failure or if no address is obtained within 10 seconds, so the application does not need to poll indefinitely on its own.
Check Status#
print(sta.ifconfig())
print(sta.status())
ifconfig() returns IP parameters, and status() returns the connection
status. To view the dynamic device name corresponding to the current Wi-Fi
STA, you can additionally call sta.netdev_name().
Disconnection Test#
sta.disconnect()
print("Disconnect")
print(sta.status())
The active disconnection at the end of the example is only for demonstration. Programs that need continuous network access should remove these lines. After disconnection, the default route management will attempt to select another ready LAN or Wi-Fi STA.
