WiFiManager
WiFi connection lifecycle management#include <WiFiManager.h>
Public Types | |
| enum class | WiFiState { DISCONNECTED , CONNECTING , CONNECTED , TIMEOUT , AP_MODE_INIT , AP_MODE , WPS_LISTENING , WPS_SUCCESS , WPS_FAILED , ERROR , CREDENTIAL_NOT_FOUND } |
Public Member Functions | |
| WiFiManager () | |
| ~WiFiManager ()=default | |
| void | init () |
| void | update () |
| bool | connectWithSavedCredentials () |
| bool | connect (const char *ssid, const char *password, uint32_t timeout=10000) |
| void | disconnect () |
| void | reconnect () |
| void | setupAP () |
| void | stopAP () |
| bool | hasConnectedDevices () |
| String | getAPSSID () const |
| String | getAPPassword () const |
| String | getAPIP () const |
| void | startWPS () |
| void | stopWPS () |
| bool | isWPSListening () const |
| WiFiState | getState () const |
| bool | isConnected () const |
| bool | isConnecting () const |
| bool | isTimedOut () const |
| bool | isAPMode () const |
| String | getLocalIP () const |
| String | getSSID () const |
| int | getRSSI () const |
| uint32_t | getConnectionTime () const |
| wifi_mode_t | getMode () const |
| void | saveCredentials (const String &ssid, const String &password) |
| bool | hasAPClient () const |
Member Enumeration Documentation
◆ WiFiState
|
strong |
Constructor & Destructor Documentation
◆ WiFiManager()
| CloudMouse::Network::WiFiManager::WiFiManager | ( | ) |
Constructor - prepares WiFi manager instance Sets up static instance pointer for event callback system
◆ ~WiFiManager()
|
default |
Member Function Documentation
◆ connect()
| bool CloudMouse::Network::WiFiManager::connect | ( | const char * | ssid, |
| const char * | password, | ||
| uint32_t | timeout = 10000 |
||
| ) |
Connect to specified WiFi network with timeout Saves successful credentials automatically for future use
- Parameters
- Returns
- true if connection attempt started successfully
◆ connectWithSavedCredentials()
| bool CloudMouse::Network::WiFiManager::connectWithSavedCredentials | ( | ) |
Attempt connection using saved credentials from NVS Automatically retrieves SSID and password from preferences
- Returns
- true if credentials found and connection attempt started
◆ disconnect()
| void CloudMouse::Network::WiFiManager::disconnect | ( | ) |
Disconnect from current WiFi network Transitions to DISCONNECTED state immediately
◆ getAPIP()
|
inline |
Get Access Point IP address Standard gateway address for device configuration
- Returns
- AP IP address string (typically "192.168.4.1")
◆ getAPPassword()
|
inline |
Get Access Point password (device-specific) Generated from device MAC address for security
- Returns
- AP password for user authentication
◆ getAPSSID()
|
inline |
Get Access Point SSID (device-specific) Format: "CloudMouse-{device_id}" based on MAC address
- Returns
- AP network name for user connection
◆ getConnectionTime()
| uint32_t CloudMouse::Network::WiFiManager::getConnectionTime | ( | ) | const |
Get current connection attempt duration Returns elapsed time since connection started
- Returns
- Connection time in milliseconds, 0 if not connecting
◆ getLocalIP()
| String CloudMouse::Network::WiFiManager::getLocalIP | ( | ) | const |
Get local IP address (station or AP mode)
- Returns
- IP address string, empty if not connected
◆ getMode()
|
inline |
Get current WiFi mode (station, AP, or mixed)
- Returns
- ESP32 WiFi mode enumeration
◆ getRSSI()
| int CloudMouse::Network::WiFiManager::getRSSI | ( | ) | const |
Get WiFi signal strength (RSSI) Only valid when connected to a network
- Returns
- Signal strength in dBm (negative values, closer to 0 = stronger)
◆ getSSID()
| String CloudMouse::Network::WiFiManager::getSSID | ( | ) | const |
Get connected network SSID or AP SSID
- Returns
- Network name, empty if not connected
◆ getState()
|
inline |
Get current WiFi connection state
- Returns
- Current state from WiFiState enumeration
◆ hasAPClient()
|
inline |
Check if clients are connected to Access Point Alias for hasConnectedDevices() for API consistency
- Returns
- true if AP has connected clients
◆ hasConnectedDevices()
| bool CloudMouse::Network::WiFiManager::hasConnectedDevices | ( | ) |
Check if devices are connected to our Access Point Useful for determining if setup is in progress
- Returns
- true if one or more clients connected to AP
◆ init()
| void CloudMouse::Network::WiFiManager::init | ( | ) |
Initialize WiFi manager and begin connection process Registers event handlers and attempts automatic connection Call once during system initialization
◆ isAPMode()
|
inline |
Check if device is in Access Point mode
- Returns
- true if AP mode is active
◆ isConnected()
|
inline |
Check if connected to WiFi network with IP address
- Returns
- true if fully connected and operational
◆ isConnecting()
|
inline |
Check if connection attempt is in progress
- Returns
- true if currently attempting to connect
◆ isTimedOut()
|
inline |
Check if last connection attempt timed out
- Returns
- true if connection timeout occurred
◆ isWPSListening()
|
inline |
Check if WPS mode is currently active
- Returns
- true if listening for WPS button press
◆ reconnect()
| void CloudMouse::Network::WiFiManager::reconnect | ( | ) |
Attempt reconnection using saved credentials Convenience method for retry logic after failures
◆ saveCredentials()
| void CloudMouse::Network::WiFiManager::saveCredentials | ( | const String & | ssid, |
| const String & | password | ||
| ) |
◆ setupAP()
| void CloudMouse::Network::WiFiManager::setupAP | ( | ) |
Setup device as WiFi Access Point for configuration Creates network with device-specific SSID and password IP address: 192.168.4.1 (standard AP gateway) Use with WebServerManager for captive portal setup
◆ startWPS()
| void CloudMouse::Network::WiFiManager::startWPS | ( | ) |
Start WPS push-button configuration mode Listens for WPS button press on router for 2 minutes Alternative to manual credential entry
◆ stopAP()
| void CloudMouse::Network::WiFiManager::stopAP | ( | ) |
Stop Access Point mode and return to station mode Disconnects all connected clients gracefully
◆ stopWPS()
| void CloudMouse::Network::WiFiManager::stopWPS | ( | ) |
Stop WPS mode and return to normal operation Call after successful WPS connection or timeout
◆ update()
| void CloudMouse::Network::WiFiManager::update | ( | ) |
Update WiFi manager state and handle timeouts Processes connection timeouts and state transitions Must be called regularly in main loop (every 100ms recommended)