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

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

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

Station Mode

../../../../../_images/wifi.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/ap.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 API

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

  • wifi.disconnectWiFi() - Disconnect

  • wifi.sta.isconnected() - Check if connection is successful

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

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

  • wifi.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