WiFiManager library: easily manage the Wi-Fi connection of projects ESP8266

The WiFiManager library allows you to easily manage the Wi-Fi connection in your ESP8266 projects. The WiFi connection is very well supported by many libraries, for example Blynk, Cayenne, Homie, ESP Easy. For more simple projects or outside the framework of these libraries, you must manage the connection to the Wi-Fi network yourself. The WiFiManager library starts the ESP8266 in access point mode (AP mode) Configuration window to a WiFi network. It is also possible to enter other parameters (MQTT server, Token Blynk …) at the same time as the WiFi parameters.

Advantages of the WiFiManager library

It can also be very interesting not to have a username and password on a Wi-Fi network in the Arduino code of the project. For example, the object should connect to a network whose IDs you do not know at the time of development. IDs can change. For example, in a school, the identifiers and the password are changed at each school year. The access point has been replaced and the new password is different. In short, you have understood, by avoiding coding “hard” ID and password, you will not need to go back through the Arduino IDE in case of change of password, hardware or Access point.

Install the WiFiManager library in the Arduino IDE

The WiFiManager library is directly available from the Arduino IDE library manager.The official page of the project can be found on GitHub here. The project has been developed and is maintained by tzapu (its personal page). It is a very popular project (1500 stars) which is maintained very regularly.

Open the Library Manager (Sketch / Include Library / Manage Libraries)

wifimanager 0 add library ide arduino
Search for WiFiManager in the search box and then install.
wifimanager 00 librarie

That’s all.

How to use the library

The WiFiManager library runs when the ESP8266 is started. When the ESP starts, the library tries to connect to the last known network or to the network indicated in the code (yes it is also possible).

Here’s how. At the beginning of the program, the necessary libraries are declared

#include <ESP8266WiFi.h>          //ESP8266 Core WiFi Library (you most likely already have this in your sketch)
#include <DNSServer.h>            //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266WebServer.h>     //Local WebServer used to serve the configuration portal
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager WiFi Configuration Magic

In the setup loop, the library is initialized

WiFiManager wifiManager;

Then connect to the Wi-Fi network with the autoConnect () function. Several configurations are possible:

  • AutoConnect(): the library is left to define an identifier composed of the prefix ESP associated with the serial number of the ESP8266. It is not very wise if you have several devices
  • AutoConnect(“AP-NAME”): indicates the name that the access point will carry.
  • AutoConnect(“AP-NAME”, “AP-PASSWORD): and a password is defined to protect the WiFi network connection page.

Therefore, if no WiFi network has been configured or if the WiFi network is inaccessible, an access point is created. Here is a basic program that you can use to test the library.

#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino

//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager

void setup() {
    // put your setup code here, to run once:

    //Local intialization. Once its business is done, there is no need to keep it around
    WiFiManager wifiManager;
    //reset saved settings
    //set custom ip for portal
    //wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));

    //fetches ssid and pass from eeprom and tries to connect
    //if it does not connect it starts an access point with the specified name
    //here  "AutoConnectAP"
    //and goes into a blocking loop awaiting configuration
    //or use this for auto generated name ESP + ChipID

    //if you get here you have connected to the WiFi
    Serial.println("connected...yeey :)");

void loop() {
    // put your main code here, to run repeatedly:

As you can see, there are several complementary methods:

  • ResetSettings: allows you to re-initialize the connection parameters. This is useful for debugging or forcing the ESP to start in AP mode. Useful for testing different networks
  • SetAPStaticIPConfig: Specifies the IP address of the access point.

After uploading the program to the ESP8266, use a computer, tablet, or smartphone to connect to the access point created by the computer.

wifimanager 1 apmode connexion point acces

Choose the network created by the ESP8266. A login window opens automatically. For example, choose the Configure WiFi method that will list wi-Fi networks within range.

wifimanager 2 fonctions connexion

Choose the desired network and enter the password. Finish with Save. The connection parameters are saved for the next reboot. The ESP is restarted immediately with these new settings and your program starts immediately.

wifimanager 3 connection reseau wifi

You can easily track the progress of the connection process (and identify problems) by opening the serial monitor. The paper is very detailed.

*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 0
*WM: Configuring access point... 
*WM: AutoConnectAP
*WM: AP IP address: 
*WM: HTTP server started
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Sent config page
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Sent config page
*WM: Request redirected to captive portal
*WM: Scan done
*WM: -70
*WM: -87
*WM: -90
*WM: Sent config page
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: WiFi save
*WM: Sent wifi save page
*WM: Connecting to new AP
*WM: Connecting as wifi client...
*WM: Connection result: 
*WM: 3
connected...yeey 🙂

Other connection strategies are available in the example folder here

  • AutoConnect: the basic connection
  • AutoConnectWithFSParameters: parameters are stored in the SPIFFS memory area of ​​the ESP8266 and reloaded at startup
  • AutoConnectWithFSParametersAndCustomIP: idem but with a fixed IP and connection parameters to u MQTT server. The parameters are stored in JSON format using the ArduinoJson library presented in this tutorial
  • AutoConnectWithFeedback:
  • AutoConnectWithFeedbackLED
  • AutoConnectWithReset
  • AutoConnectWithStaticIP: configuration with static IP saved in the SPIFFS memory area
  • AutoConnectWithTimeout
  • OnDemandConfigPortal: Allows you to call the AP mode to configure a new connection using a physical control button connected to a pin on the ESP8266

Can we combine with other bookstores: pubsubclient, ArduinoOTA …?

Yes, the WiFiManager library is designed to be compatible with other libraries. Indeed, it is an abstraction layer at the ESP8266WiFi library. It only intervenes when the ESP8266 is started. However, as there is always a BUT, I have encountered some difficulties in connecting to an MQTT server. This is probably more of a bad implementation on my part than a real problem in the library. If you have more experience feel free to share in the comments.

To manage the connection to an MQTT server (broker) you can use this example available on GitHub. WiFiManager is able to integrate the input of additional connection parameters. On the other hand, it is necessary to manage either the registration and the loading of the parameters at the launch of the ESP8266 using the method setSaveConfigCallback.

It is also possible to upgrade wirelessly to Wi-Fi using the ArduinoOTA library. However, you must save and reload the connection parameters. After an update, the WiFiManager library tends to forget the previous connection parameters.


Subscribe to the weekly newsletter

No spam and no other use will be made of your email. You can unsubscribe anytime.

1 Comment

    Leave a Reply

    DIY Projects
    %d bloggers like this: