Wi-Fi

Overview

Introduces the basic usage of its Wi-Fi features.

Wi-Fi Working Modes

The mPython Board 3.0 supports 2.4 GHz Wi-Fi

  1. Station mode (STA) - Connects to a wireless access point (AP)

  2. SoftAP mode - Acts as an access point for other devices to connect to

Station Mode

../../../../../_images/wifi1.png
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

../../../../../_images/ap1.png
SoftAP hotspot mode
from mpython import *

import network

my_wifi = wifi()
my_wifi.enable_APWiFi('ap', 'mpython', channel=8)

API Reference

Main Wi-Fi APIs

  • wifi.connectWiFi("ssid, "psd") - Connect to Wi-Fi

  • wifi.disconnectWiFi() - Disconnect

  • wifi.sta.isconnected() - Check whether the connection succeeded

  • wifi.sta.ifconfig() - Get the Wi-Fi configuration

  • wifi.enable_APWiFi('ssid', 'psd', channel=) - Enable SoftAP mode

  • wifi.disable_APWiFi() - Disable SoftAP mode

FAQ

Q: Unable to connect to the AP
  • Check whether the SSID and password are correct

  • Check whether the Wi-Fi network is on the 2.4 GHz band

  • Check the router settings

  • Check the signal strength

Q: The SoftAP cannot be found in scans
  • Check whether the correct channel is set

  • Check whether the maximum number of connections is set reasonably