wifi

The wifi module provides necessary low-level functionality for managing wifi connections. Use socketpool for communicating over the network.

Available on these boards
  • ATMegaZero ESP32-S2
  • Adafruit FunHouse
  • Adafruit MagTag
  • Adafruit Metro ESP32S2
  • Artisense Reference Design RD00
  • BastWiFi
  • Feather ESP32S2 without PSRAM
  • FeatherS2
  • FeatherS2 PreRelease
  • Franzininho WIFI w/Wroom
  • Franzininho WIFI w/Wrover
  • Kaluga 1
  • LILYGO TTGO T8 ESP32-S2 w/Display
  • Saola 1 w/Wroom
  • Saola 1 w/Wrover
  • Targett Module Clip w/Wroom
  • Targett Module Clip w/Wrover
  • TinyS2
  • microS2
  • nanoESP32-S2 w/Wrover
  • nanoESP32-S2 w/Wroom

wifi.radio :Radio

Wifi radio used to manage both station and AP modes. This object is the sole instance of wifi.Radio.

class wifi.AuthMode

The authentication protocols used by WiFi.

OPEN :object

Open network. No authentication required.

WEP :object

Wired Equivalent Privacy.

WPA :object

Wireless Protected Access.

WPA2 :object

Wireless Protected Access 2.

WPA3 :object

Wireless Protected Access 3.

PSK :object

Pre-shared Key. (password)

ENTERPRISE :object

Each user has a unique credential.

class wifi.Network

A wifi network provided by a nearby access point.

You cannot create an instance of wifi.Network. They are returned by wifi.Radio.start_scanning_networks.

ssid :str

String id of the network

bssid :bytes

BSSID of the network (usually the AP’s MAC address)

rssi :int

Signal strength of the network

channel :int

Channel number the network is operating on

country :str

String id of the country code

authmode :str

String id of the authmode

class wifi.Radio

Native wifi radio.

This class manages the station and access point functionality of the native Wifi radio.

You cannot create an instance of wifi.Radio. Use wifi.radio to access the sole instance available.

enabled :bool

True when the wifi radio is enabled. If you set the value to False, any open sockets will be closed.

mac_address :bytes

MAC address of the wifi radio station. (read-only)

mac_address_ap :bytes

MAC address of the wifi radio access point. (read-only)

hostname :_typing.ReadableBuffer

Hostname for wifi interface. When the hostname is altered after interface started/connected the changes would only be reflected once the interface restarts/reconnects.

ipv4_gateway :Optional[ipaddress.IPv4Address]

IP v4 Address of the station gateway when connected to an access point. None otherwise.

ipv4_gateway_ap :Optional[ipaddress.IPv4Address]

IP v4 Address of the access point gateway, when enabled. None otherwise.

ipv4_subnet :Optional[ipaddress.IPv4Address]

IP v4 Address of the station subnet when connected to an access point. None otherwise.

ipv4_subnet_ap :Optional[ipaddress.IPv4Address]

IP v4 Address of the access point subnet, when enabled. None otherwise.

ipv4_address :Optional[ipaddress.IPv4Address]

IP v4 Address of the station when connected to an access point. None otherwise.

ipv4_address_ap :Optional[ipaddress.IPv4Address]

IP v4 Address of the access point, when enabled. None otherwise.

ipv4_dns :Optional[ipaddress.IPv4Address]

IP v4 Address of the DNS server in use when connected to an access point. None otherwise.

ap_info :Optional[Network]

Network object containing BSSID, SSID, authmode, channel, country and RSSI when connected to an access point. None otherwise.

start_scanning_networks(self, *, start_channel: int = 1, stop_channel: int = 11)Iterable[Network]

Scans for available wifi networks over the given channel range. Make sure the channels are allowed in your country.

stop_scanning_networks(self)None

Stop scanning for Wifi networks and free any resources used to do it.

start_station(self)None

Starts a Station.

stop_station(self)None

Stops the Station.

start_ap(self, ssid: _typing.ReadableBuffer, password: _typing.ReadableBuffer = b'', *, channel: Optional[int] = 1, authmode: Optional[AuthMode])None

Starts an Access Point with the specified ssid and password.

If channel is given, the access point will use that channel unless a station is already operating on a different channel.

If authmode is given, the access point will use that Authentication mode. If a password is given, authmode must not be OPEN. If authmode isn’t given, OPEN will be used when password isn’t provided, otherwise WPA_WPA2_PSK.

stop_ap(self)None

Stops the Access Point.

connect(self, ssid: _typing.ReadableBuffer, password: _typing.ReadableBuffer = b'', *, channel: Optional[int] = 0, bssid: Optional[_typing.ReadableBuffer] = b'', timeout: Optional[float] = None)bool

Connects to the given ssid and waits for an ip address. Reconnections are handled automatically once one connection succeeds.

By default, this will scan all channels and connect to the access point (AP) with the given ssid and greatest signal strength (rssi).

If channel is given, the scan will begin with the given channel and connect to the first AP with the given ssid. This can speed up the connection time significantly because a full scan doesn’t occur.

If bssid is given, the scan will start at the first channel or the one given and connect to the AP with the given bssid and ssid.

ping(self, ip: ipaddress.IPv4Address, *, timeout: Optional[float] = 0.5)float

Ping an IP to test connectivity. Returns echo time in seconds. Returns None when it times out.

class wifi.ScannedNetworks

Iterates over all wifi.Network objects found while scanning. This object is always created by a wifi.Radio: it has no user-visible constructor.

Cannot be instantiated directly. Use wifi.Radio.start_scanning_networks.

__iter__(self)Iterator[Network]

Returns itself since it is the iterator.

__next__(self)Network

Returns the next wifi.Network. Raises StopIteration if scanning is finished and no other results are available.