Esp32 WiFiManager with PlatformIO
The PlatformIO ESP32 WiFiManager library simplifies the process of managing Wi-Fi connections on ESP32 boards, enabling device manufacturers and developers to create robust and user-friendly network configurations without exposing sensitive credentials.
The ESP32 is a powerful low-cost microcontroller with integrated Wi-Fi and dual-mode Bluetooth. However, configuring Wi-Fi connections can be complex and error-prone. The PlatformIO ESP32 WiFiManager library provides an elegant solution, offering an easy-to-use interface for managing Wi-Fi networks and storing credentials securely.
Configuring Wi-Fi with ESP32 and PlatformIO WiFiManager
The first step in using the PlatformIO ESP32 WiFiManager library is to include it in your project. Add the following line to your `platformio.ini` file:
`lib_deps = karlp/Espressif-WiFi-Manager@^2.0.0`
Initializing WiFiManager
Afterincluding the library, initialize the WiFiManager instance in your sketch:
`WiFiManager wifiManager;`
Managing Wi-Fi Modes
The ESP32 supports multiple Wi-Fi modes, including Station, Access Point, and Station+Access Point. The PlatformIO ESP32 WiFiManager library simplifies mode management:
wifiManager.setMode(WIFI_STA)sets the Wi-Fi mode to Station mode.wifiManager.setMode(WIFI_AP)sets the Wi-Fi mode to Access Point mode.wifiManager.setMode(WIFI_AP_STA)sets the Wi-Fi mode to Station+Access Point mode.
Working with Wi-Fi Credentials and the Soft Access Point
The PlatformIO ESP32 WiFiManager library enables you to create a temporary soft Access Point (AP) for configuring Wi-Fi credentials. This feature is particularly useful when initial network credentials are not available.
Enabling the Soft Access Point
To enable the soft AP, call the following function in your sketch:
`bool softAP(bool open = false);`
Configuring Wi-Fi Credentials
Once the soft AP is active, connect to it using a Wi-Fi-enabled device. Navigate to the captive portal (usually at IP address 192.168.4.1) and configure your network credentials.
Persisting Wi-Fi Credentials
The PlatformIO ESP32 WiFiManager library stores Wi-Fi credentials securely in non-volatile memory, ensuring that they persist across power cycles and resets.
Automatic Credential Storage
The library automatically stores and retrieves credentials from the ESP32's non-volatile memory using the following functions:
- `wifiManager.startNonBlocking()` starts the non-blocking function to connect to the configured network.
- `wifiManager.getConfig()` retrieves the current Wi-Fi configuration.
Manually Saving Credentials
If needed, you can manually save Wi-Fi credentials using the following function:
`bool saveConfig()`
Isn't it time you streamlined your ESP32 Wi-Fi management? Give the PlatformIO ESP32 WiFiManager library a try today, and watch your network configurations become a breeze. Happy coding!