WLAN AP – control built-in WiFi interfaces

This class provides a driver for WiFi AP network processors.

Micropython Example:

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8import network
 9
10
11title0 = None
12label0 = None
13label1 = None
14label2 = None
15wlan = None
16
17
18ap_client = None
19
20
21def setup():
22    global title0, label0, label1, label2, wlan
23
24    M5.begin()
25    Widgets.fillScreen(0x222222)
26    title0 = Widgets.Title("WLAN AP CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
27    label0 = Widgets.Label("label0", 2, 77, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
28    label1 = Widgets.Label("label1", 2, 111, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
29    label2 = Widgets.Label("label2", 2, 145, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
30
31    wlan = network.WLAN(network.AP_IF)
32    wlan.config(max_clients=4)
33    wlan.config(essid="M5CoreS3AP")
34    wlan.active(True)
35
36
37# Please connect to the AP named M5CoreS3.
38def loop():
39    global title0, label0, label1, label2, wlan
40    M5.update()
41    label0.setText(str((str("AP is connected?:") + str((wlan.isconnected())))))
42    label1.setText(str((str("SSID:") + str((wlan.config("essid"))))))
43    for ap_client in wlan.status("stations"):
44        label2.setText(str(ap_client[0]))
45
46
47if __name__ == "__main__":
48    try:
49        setup()
50        while True:
51            loop()
52    except (Exception, KeyboardInterrupt) as e:
53        try:
54            from utility import print_error_msg
55
56            print_error_msg(e)
57        except ImportError:
58            print("please update to latest firmware")

UIFLOW2 Example:

example.png

wlan_ap_cores3_example.m5f2

Constructors

class network.WLAN(interface_id)

Create a WLAN network interface object. Supported interfaces are network.AP_IF (access point, allows other WiFi clients to connect)

UIFLOW2:

init.png

Methods

WLAN.status([param])

Return the current status of the wireless connection.

When called with no argument the return value describes the network link status.

UIFLOW2:

scan.png

scan_get_mac.png

WLAN.isconnected()

In AP mode returns True when a station is connected. Returns False otherwise.

isconnected.png

WLAN.active([is_active])

Activate (“up”) or deactivate (“down”) network interface, if boolean argument is passed. Otherwise, query current state if no argument is provided. Most other methods require active interface.

active.png

WLAN.ifconfig([(ip, subnet, gateway, dns)])

Get/set IP-level network interface parameters: IP address, subnet mask, gateway and DNS server. When called with no arguments, this method returns a 4-tuple with the above information. To set the above values, pass a 4-tuple with the required information.

get_local_ip.png

get_subnet.png

get_gateway.png

get_dns.png

WLAN.config('param')
WLAN.config(param=value, ...)

Get or set general network interface parameters. These methods allow to work with additional parameters beyond standard IP configuration (as dealt with by AbstractNIC.ipconfig()). These include network-specific and hardware-specific parameters. For setting parameters, keyword argument syntax should be used, multiple parameters can be set at once. For querying, parameters name should be quoted as a string, and only one parameter can be queried at a time:

Following are commonly supported parameters (availability of a specific parameter depends on network technology type, driver, and MicroPython port).

Parameter

Description

mac

MAC address (bytes)

ssid

WiFi access point name (string)

channel

WiFi channel (integer)

hidden

Whether SSID is hidden (boolean)

security

Security protocol supported (enumeration, see module constants)

key

Access key (string)

hostname

The hostname that will be sent to DHCP (STA interfaces) and mDNS (if supported, both STA and AP). (Deprecated, use network.hostname() instead)

reconnects

Number of reconnect attempts to make (integer, 0=none, -1=unlimited)

txpower

Maximum transmit power in dBm (integer or float)

pm

WiFi Power Management setting (see below for allowed values)

set_ssid.png

set_password.png

set_hidden_status.png

set_auth_mode.png

set_channel.png

set_dhcp_hostname.png

set_max_clients.png

set_txpower.png

get_ssid.png

get_password.png

get_mac.png

get_hidden_status.png

get_auth_mode.png

get_channel.png

get_dhcp_hostname.png

get_max_clients.png

get_txpower.png

Constants

WLAN.AUTH_OPEN
WLAN.AUTH_WEP
WLAN.AUTH_WPA_PSK
WLAN.AUTH_WPA2_PSK
WLAN.AUTH_WPA_WPA2_PSK
WLAN.AUTH_WPA2_ENTERPRISE
WLAN.AUTH_WPA3_PSK
WLAN.AUTH_WPA2_WPA3_PSK
WLAN.AUTH_WAPI_PSK

Allowed values for the WLAN.config(authmode=...) network interface parameter:

  • AUTH_OPEN: 0 – open

  • AUTH_WEP: 1 – WEP

  • AUTH_WPA_PSK: 2 – WPA-PSK

  • AUTH_WPA2_PSK: 3 – WPA2-PSK

  • AUTH_WPA_WPA2_PSK: 4 – WPA/WPA2-PSK

  • AUTH_WPA2_ENTERPRISE: 5 – WPA2-Enterprise

  • AUTH_WPA3_PSK: 6 – WPA3-PSK

  • AUTH_WPA2_WPA3_PSK: 7 – WPA2/WPA3-PSK

  • AUTH_WAPI_PSK: 8 – WAPI-PSK