platformio esp32 wifimanager

Esp32 WiFiManager with PlatformIO

By Nicole Moore
AD

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:

AD
10 ESP32 Skills Every Maker Should Learn
10 ESP32 Skills Every Maker Should Learn
WiFiManager with ESP8266 – Autoconnect without hard-code
WiFiManager with ESP8266 – Autoconnect without hard-code
🌐 How to Set Static IP on ESP32 – Reliable Networking Made Easy!
🌐 How to Set Static IP on ESP32 – Reliable Networking Made Easy!

`lib_deps = karlp/Espressif-WiFi-Manager@^2.0.0`

Initializing WiFiManager

Afterincluding the library, initialize the WiFiManager instance in your sketch:

How to Power the ESP32 Correctly ⚑
How to Power the ESP32 Correctly ⚑
ESP32 MQTT: Publish & Subscribe πŸ“‘βš‘
ESP32 MQTT: Publish & Subscribe πŸ“‘βš‘
Develop ESP32 With PlatformIO IDE
Develop ESP32 With PlatformIO IDE

`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:

AD
  • 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.

Simulate ESP32 Projects in VS Code with Wokwi (Beginner Guide!)
Simulate ESP32 Projects in VS Code with Wokwi (Beginner Guide!)
an esp wi - fi manager is shown on the screen next to a cell phone
an esp wi - fi manager is shown on the screen next to a cell phone
ESP32 Over-the-Air (OTA) Updates – Wireless Firmware Upload
ESP32 Over-the-Air (OTA) Updates – Wireless Firmware Upload
🌐 ESP32 + IFTTT = Smart Home Magic! ✨
🌐 ESP32 + IFTTT = Smart Home Magic! ✨
Anatomy esp32
Anatomy esp32
an electronic device is shown in this poster, with instructions on how to use it
an electronic device is shown in this poster, with instructions on how to use it

Enabling the Soft Access Point

To enable the soft AP, call the following function in your sketch:

`bool softAP(bool open = false);`

AD

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.

🌐 Build an ESP32 Web Server to Control LEDs (Step-by-Step Guide!)
🌐 Build an ESP32 Web Server to Control LEDs (Step-by-Step Guide!)
250+ ESP32 Projects, Tutorials and Guides with Arduino IDE​ | Random Nerd Tutorials
250+ ESP32 Projects, Tutorials and Guides with Arduino IDE​ | Random Nerd Tutorials
ESP32/ESP8266 WIFI Display Using MQTT Protocol
ESP32/ESP8266 WIFI Display Using MQTT Protocol
esp 32 is a machine that can make you an engineer
esp 32 is a machine that can make you an engineer
ESP32 Tutorials for Beginners
ESP32 Tutorials for Beginners
ESP32 Explained: The Powerful IoT Board
ESP32 Explained: The Powerful IoT Board
Getting Started with VS Code and PlatformIO IDE for ESP32 and ESP8266 | Random Nerd Tutorials
Getting Started with VS Code and PlatformIO IDE for ESP32 and ESP8266 | Random Nerd Tutorials

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:

AD
  • `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!

AD