wifi - wolfen351/public-micropython-iot-platform GitHub Wiki
The [WifiHandler] module is responsible for managing Wi-Fi connectivity on a MicroPython-based device. It handles both Station (STA) and Access Point (AP) modes, provides telemetry data, and supports Over-The-Air (OTA) updates. The module ensures robust Wi-Fi connectivity and facilitates configuration through a web interface.
Features
- Station Mode: Connects to a configured Wi-Fi network.
- Access Point Mode: Starts an AP for configuration when no Wi-Fi is available.
- Automatic Reconnection: Attempts to reconnect to Wi-Fi if the connection is lost.
- OTA Updates: Checks for and installs firmware updates.
- Telemetry: Provides system and network telemetry data.
- Web Interface: Allows configuration and file uploads via HTTP endpoints.
- Power Cycling: Automatically resets Wi-Fi interfaces if connectivity issues persist.
- Static IP Support: Configures static IP settings if required.
UI
The module provides a web-based interface for configuration and monitoring:
The configuration screen looks like this:
- Network Settings Page (/network): Configure Wi-Fi SSID, password, and IP settings.
- Log Page (/log): View Wi-Fi connection logs.
- Firmware Update Page (/firmware): Upload and manage firmware updates.
- File Upload Endpoint (/upload): Upload files to the device.
Hardware / Pinout
The module leverages the built-in Wi-Fi capabilities found on most ESP-based boards.
Configuration
The module can be configured through the Web UI. These configuration parameters are stored in the prefs.json
file under the wifi
section. Below is the list of configurable parameters along with their default values:
"wifi": {
"ssid": "yourssid", // Wi-Fi SSID (default: self.defaultSSID)
"password": "yourpassword", // Wi-Fi password (default: self.defaultPassword)
"type": "DHCP", // Connection type ("DHCP" or "Static", default: "DHCP")
"ip": "", // Static IP address (default: empty)
"netmask": "", // Netmask for static IP (default: empty)
"gateway": "" // Gateway address for static IP (default: empty)
}
The module retrieves its configuration from persistent storage using the [getPref] method.
This module is configured by the web ui.
To configure the module:
- Access the /network endpoint.
- Provide the SSID, password, and other settings.
- Save the settings, and the module will attempt to connect to the specified network.
Telemetry provided
The module provides telemetry data through the getTelemetry method:
- SSID: The connected Wi-Fi network name.
- IP Address: The device's IP address.
- RSSI: Signal strength of the Wi-Fi connection.
- Free RAM: Available memory on the device.
- Free Disk Space: Available storage space.
- OS Name: The operating system name.
- Wi-Fi Mode: Current mode (Station or Access Point).
- Wi-Fi Uptime: Duration of the Wi-Fi connection.
Telemetry consumed
The module does not consume telemetry data from external sources.
Commands provided
This module does not provide any commands to other modules. It only provides telemetry about the button state.
The module exposes the following commands via HTTP endpoints:
/netloadsettings
: Load current network settings./netsavesettings
: Save new network settings./getlog
: Retrieve Wi-Fi connection logs./forceUpdate
: Force an OTA update./upload
: Upload files to the device.
Commands consumed
The module processes commands received via HTTP endpoints:
- Network Configuration Commands: Updates SSID, password, and IP settings.
- OTA Commands: Initiates firmware updates.
- File Upload Commands: Saves uploaded files to the device.
Additional Notes
- Error Handling: The module logs errors and exceptions to SerialLog for debugging.
- Reboot on Failure: If the device fails to connect to Wi-Fi for 90 minutes, it automatically reboots.
- AP Timeout: The AP mode shuts down after 3 minutes of inactivity to conserve resources.