Wi-Fi
Overview
Introduction to the basic usage of Wi-Fi functionality.
Wi-Fi Operating Modes
mPython Core 2.0 supports 2.4 GHz Wi-Fi
Station mode (STA) - Connect to a wireless access point (AP)
SoftAP mode - Act as an access point for other devices to connect
Station Mode
Station mode
from mpython import *
import network
my_wifi = wifi()
my_wifi.connectWiFi("my_wifi", "12345678")
if my_wifi.sta.isconnected():
print(my_wifi.sta.ifconfig())
SoftAP Hotspot Mode
SoftAP hotspot mode
from mpython import *
import network
my_wifi = wifi()
my_wifi.enable_APWiFi('ap', 'mpython', channel=8)
API Reference
Main Wi-Fi API
wifi.connectWiFi("ssid, "psd")- Connect to Wi-Fiwifi.disconnectWiFi()- Disconnectwifi.sta.isconnected()- Check if connection is successfulwifi.sta.ifconfig()- Get Wi-Fi configurationwifi.enable_APWiFi('ssid', 'psd', channel=)- Enable SoftAP modewifi.disable_APWiFi()- Disable SoftAP mode
FAQ
- Q: Unable to connect to AP
Check if SSID and password are correct
Check if Wi-Fi is on the 2.4 GHz band
Check router settings
Check signal strength
- Q: SoftAP cannot be discovered
Check if the correct channel is set
Check if the maximum connection count is set reasonably