WLAN Overview
WLAN (Wireless Local Area Network) is a network technology that enables interconnection between devices through wireless signals (such as Wi-Fi). It allows computers, smartphones, IoT devices and other terminals to access a local area network or the Internet without using physical cables.
Core Features of WLAN
• Wireless Transmission: Uses radio waves (2.4GHz/5GHz/6GHz frequency bands) instead of network cables, supporting device mobility.
• Standardized Protocols: Based on the IEEE 802.11 series of standards (such as 802.11ac, 802.11ax).
• Flexible Deployment: No wiring required, suitable for scenarios including homes, enterprises, and public places.
• Shared Bandwidth: All devices share the same wireless channel, and the available bandwidth is affected by the access point (AP) and environmental interference.
• Security Mechanisms: Supports WPA3 and WPA2 encryption to prevent unauthorized access.
Functional Overview
This article mainly describes how to use the QuecPython development board to connect to a Wi-Fi hotspot and create a Wi-Fi hotspot. The typical programming workflow is divided into the following parts:
Station Mode: Connect to a Wi-Fi hotspot
Create a Wi-Fi network interface object
Connect to the target hotspot
AP Mode: Create a Wi-Fi hotspot
Create a Wi-Fi network interface object
Set the hotspot name and password
Activate the network interface
Station Mode
Create a Wi-Fi Network Interface Object
Initialize the Wi-Fi network interface information and return the Wi-Fi network interface object.
class network.WLAN(mode)
For parameter details, please refer to the constructor.
Connect to a Hotspot
This method is used to connect to the specified wireless network. It only supports Station mode, and supports both blocking and non-blocking connection modes, with a default blocking connection and a 15s timeout period.
If the ssid and password are not specified, the device will automatically connect to the last successfully connected AP.
WLAN.connect([ssid, password, bssid, timeout])
For API details, please refer to WLAN.connect.
AP Mode
Create a Wi-Fi Network Interface Object
Initialize the Wi-Fi network interface information and return the Wi-Fi network interface object.
class network.WLAN(mode)
For parameter details, please refer to the constructor.
Set Configuration Parameters
This method is used to set the name and password of the hotspot.
WLAN.config(ap_ssid = "SSID", ap_password = "PASSWD")
For API details, please refer to WLAN.config.
Activate the Network Interface
This method is used to activate the network interface and trigger the startup of the hotspot.
WLAN.active(enable)
For API details, please refer to WLAN.active.
Application Example
This example uses the FCM360W QuecPython development board to connect to a hotspot, the sample code is as follows:
import network
Create a Wi-Fi network interface and set it to STATION modenic = network.WLAN(network.STA_MODE)
Define Wi-Fi event callback functiondef wifi_event_cb(event):
Print event informationprint("- Event:\r\n ", event)
When the IP address is obtained, print IP address related informationif event['id'] == 3305:print("- Got IP:\r\n ", nic.ifconfig())
Set the event callback
functionnic.config(event_callback = wifi_event_cb)
Connect to the hotspotnic.connect(ssid = "QuecPython", password = "12345678")
The code execution result is as follows:
Connecting to QuecPython
Event: {'msg': None, 'type': 3300, 'id': 3301}
Event: {'msg': {'password': '12345678', 'ssid': 'QuecPython', 'rssi': -62, 'channel': 1, 'bssid': 'a4:00:e2:ef:f7:80', 'auth': 4, 'cipher': 4}, 'type': 3300, 'id': 3302}
Event: {'msg': ('10.66.117.73', '255.255.252.0', '10.66.116.1', '0.0.0.0', '0.0.0.0'), 'type': 3300, 'id': 3305}
Got IP: ('10.66.117.73', '255.255.252.0', '10.66.116.1', '211.138.180.2', '114.114.114.114')
Top comments (0)