class documentation

class WiFiUART:

Constructor: WiFiUART(uart, timeout_ms)

View In Hierarchy

Class to manage WiFi functionality on a MicroPython device.

Method __init__ Initialize the WiFiUART instance.
Method connect Connect to a Wi-Fi network.
Method connect_async Initiate an asynchronous connection to a Wi-Fi network.
Method disconnect Disconnect from the current Wi-Fi network.
Method is_connected Check if the device is currently connected to a Wi-Fi network.
Method ping Check for pong response
Method reset Reset the Wi-Fi module.
Method scan Scan for available Wi-Fi networks.
Method status Get the current Wi-Fi status.
Instance Variable error The last error message encountered during WiFi operations.
Instance Variable timeout_ms The timeout for UART receiving
Instance Variable uart The UART object for communication with the WiFi module.
Property device_ip Get the current device IP address.
Property last_error Get the last error message encountered during WiFi operations.
Property mac_address Get the current device MAC address.
Property state Get the current WiFi state.
Method __send_and_wait Send a command to the UART and wait for a response.
def __init__(self, uart=None, timeout_ms: int = 5000):

Initialize the WiFiUART instance.

Parameters
uartThe UART object for communication with the WiFi module.
timeout_ms:intThe timeout for UART receiving in milliseconds. Defaults to 5000.
def connect(self, ssid: str, password: str = '', sta_mode: bool = True) -> bool:

Connect to a Wi-Fi network.

Parameters
ssid:strSSID of the Wi-Fi network.
password:strPassword for the Wi-Fi network. Defaults to "".
sta_mode:boolTrue for station mode (STA_IF), False for access point mode (AP_IF). Defaults to True.
Returns
boolTrue if the connection succeeded, False otherwise.
def connect_async(self, ssid: str, password: str = '', sta_mode: bool = True) -> bool:

Initiate an asynchronous connection to a Wi-Fi network.

Parameters
ssid:strSSID of the Wi-Fi network.
password:strPassword for the Wi-Fi network. Defaults to "".
sta_mode:boolTrue for station mode (STA_IF), False for access point mode (AP_IF). Defaults to True.
Returns
boolTrue if the command to initiate the connection was sent successfully, False otherwise.
def disconnect(self):

Disconnect from the current Wi-Fi network.

Returns
None
def is_connected(self) -> bool:

Check if the device is currently connected to a Wi-Fi network.

Returns
boolTrue if connected, False otherwise.
def ping(self) -> bool:

Check for pong response

def reset(self):

Reset the Wi-Fi module.

Returns
None
def scan(self) -> list:

Scan for available Wi-Fi networks.

def status(self) -> int:

Get the current Wi-Fi status.

Returns
intThe current Wi-Fi status as one of the WIFI_STATE_* constants.
error: str =

The last error message encountered during WiFi operations.

timeout_ms: int =

The timeout for UART receiving

uart =

The UART object for communication with the WiFi module.

@property
device_ip =

Get the current device IP address.

@property
last_error =

Get the last error message encountered during WiFi operations.

@property
mac_address =

Get the current device MAC address.

@property
state =

Get the current WiFi state.

def __send_and_wait(self, command: str) -> str:

Send a command to the UART and wait for a response.

Parameters
command:strThe command to send.
Returns
strThe response from the UART.