class documentation

Class to manage WiFi functionality on a MicroPython device.

Method __del__ Destructor to clean up resources.
Method __init__ Initialize the WiFi class.
Method callback_connect.setter Set the connection callback function.
Method connect Connect to a Wi-Fi network.
Method connect_async Connect to a Wi-Fi network asynchronously.
Method disconnect Disconnect from the Wi-Fi network.
Method is_connected Check if the device is connected to a Wi-Fi network.
Method reset Reset the Wi-Fi configuration.
Method scan Scan for available Wi-Fi networks.
Method status Get the current Wi-Fi connection status.
Method timeout.setter Set the connection timeout in seconds.
Instance Variable connection_start_time The timestamp when the connection attempt started.
Instance Variable connection_timeout The timeout duration for WiFi connections in seconds.
Instance Variable error The last error message encountered during WiFi operations.
Instance Variable mode The WiFi mode (STA_IF or AP_IF).
Instance Variable password The password for the WiFi network.
Instance Variable ssid The SSID of the WiFi network.
Instance Variable wlan The WLAN object for managing WiFi connections.
Property callback_connect Get the connection callback function.
Property device_ip Get the current device IP address.
Property last_error Get the last connection error message.
Property mac_address Get the MAC address of the Wi-Fi interface.
Property state Get the current Wi-Fi state.
Property timeout Get the connection timeout in seconds.
Method __close_thread Internal method to close the background thread.
Method _should_continue Check if the operation should continue running.
Instance Variable _callback_connect Undocumented
Instance Variable _current_task Undocumented
Instance Variable _state Undocumented
Instance Variable _thread Undocumented
Instance Variable _thread_lock Undocumented
Instance Variable _thread_manager Undocumented
Instance Variable _thread_running Undocumented
def __del__(self):

Destructor to clean up resources.

def __init__(self, thread_manager=None, timeout: int = 10):

Initialize the WiFi class.

Parameters
thread_manager:ThreadManagerOptional ThreadManager instance for managed threading. Defaults to None.
timeout:intConnection timeout in seconds. Defaults to 10.
def callback_connect(self, func: callable):

Set the connection callback function.

The callback receives the Wi-Fi state and an error message (if any).

Parameters
func:callableThe callback function to set.
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:

Connect to a Wi-Fi network asynchronously.

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 was started.
def disconnect(self):

Disconnect from the Wi-Fi network.

def is_connected(self):

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

def reset(self):

Reset the Wi-Fi configuration.

def scan(self) -> list:

Scan for available Wi-Fi networks.

def status(self) -> int:

Get the current Wi-Fi connection status.

def timeout(self, seconds: int):

Set the connection timeout in seconds.

Parameters
seconds:intThe timeout in seconds.
connection_start_time: int =

The timestamp when the connection attempt started.

connection_timeout: int =

The timeout duration for WiFi connections in seconds.

error: str =

The last error message encountered during WiFi operations.

mode: int =

The WiFi mode (STA_IF or AP_IF).

password: str =

The password for the WiFi network.

ssid: str =

The SSID of the WiFi network.

wlan: network.WLAN =

The WLAN object for managing WiFi connections.

@property
callback_connect: callable =

Get the connection callback function.

@property
device_ip =

Get the current device IP address.

@property
last_error: str =

Get the last connection error message.

@property
mac_address: str =

Get the MAC address of the Wi-Fi interface.

@property
state: int =

Get the current Wi-Fi state.

@property
timeout: int =

Get the connection timeout in seconds.

def __close_thread(self):

Internal method to close the background thread.

def _should_continue(self) -> bool:

Check if the operation should continue running.

_callback_connect: callable =

Undocumented

_current_task =

Undocumented

_state =

Undocumented

_thread =

Undocumented

_thread_lock =

Undocumented

_thread_manager =

Undocumented

_thread_running: bool =

Undocumented