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.")

Authors

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.

wifi_module.disconnect(wifi)[source]

Deactivates the specified Wi-Fi interface and checks if the device is not connected to any Wi-Fi network.

Parameters:

wifi – The Wi-Fi interface object to disconnect.

wifi_module.print_status(wifi)[source]

Retrieves the status of the specified Wi-Fi interface and prints a human-readable message corresponding to that status.

Parameters:

wifi – The Wi-Fi interface object whose status is to be printed.