AP模式的使用
ap = network.WLAN(network.AP_IF)
ap.config(essid='esp32',password='12345678',authmode=network.AUTH_WPA_WPA2_PSK)
ap.active(True)
其中,config可以配置的参数如下(谁能想到micropython官网的提供的参数是错的,害我找了好半天,xox):
mac | MAC address (bytes) |
essid | WiFi access point name (string) |
channel | WiFi channel (integer) |
hidden | Whether ESSID is hidden (boolean) |
authmode | Authentication mode supported (enumeration, see module constants) |
password | Access password (string) |
STA的使用:
wlan = network.WLAN(network.STA_IF) # create station interface
wlan.active(True) # activate the interface
wlan.scan() # scan for access points
wlan.isconnected() # check if the station is connected to an AP
wlan.connect('ssid', 'key') # connect to an AP
官方给了个推荐写法:
def do_connect():
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print('connecting to network...')
wlan.connect('ssid', 'key')
while not wlan.isconnected():
pass
print('network config:', wlan.ifconfig())
--ps顺便将记录下有网的情况下,可以使用upip进行安装相关库:
import upip
upip.install("micropython-ulogger")