Wi-Fi
This module provides functions for connecting to and disconnecting from a Wi-Fi network using MicroPython on ESP8266 or ESP32 devices.
Example
from wifi_module import connect, disconnect
# Initialize the Wi-Fi interface in Station mode
wifi = network.WLAN(network.STA_IF)
# Connect to Wi-Fi
if connect(wifi, "Your_SSID", "Your_Password"):
print("Connected to Wi-Fi!")
else:
print("Failed to connect.")
# Disconnect from Wi-Fi
disconnect(wifi)
print("Disconnected from Wi-Fi.")
Modification history
2024-12-14 : Prefixes added to print statements.
2024-11-11 : Added Sphinx comments.
2024-11-02 : Added print_status method.
2023-06-17 : Created connect and disconnect methods.
- wifi_module.connect(wifi, ssid, password)[source]
Connect to a specified Wi-Fi network using the provided SSID and password. If the connection attempt exceeds the specified timeout, it will terminate and return False.
- Parameters:
wifi – The Wi-Fi interface object to use for the connection.
ssid (str) – The SSID of the Wi-Fi network to connect to.
password (str) – The password for the Wi-Fi network.
- Returns:
True if connected successfully, False if the connection attempt timed out.