Configure ESP8266 Wifi With WiFiManager

There’s no doubt that the ESP8266 has made creating little WiFi widgets pretty easy. However, a lot of projects hard code the access point details into the device. There’s a better way to do it: use the WiFiManager library. [Witnessmenow] has a good tutorial and a two-minute video (which you can see below).

Hard coding is fine if you are just tinkering around. However, if you are going to send your device away (or even take it with you somewhere) you probably don’t want to reprogram it every time you change access points. This problem is even worse if you plan on a commercial product. WiFiManager does what a lot of commercial devices do. It initially looks like an access point. You can connect to it using a phone or other WiFi device. Then you can configure it to join your network by setting the network ID, password, etc.

It isn’t very hard to adapt a hard-coded program to use WiFiManager and [Witnessmehow] shows a normal program and a WiFiManager sample side-by-side. He then copies and pastes a few lines of code to get it working.

Essentially, you need to make sure you have the following headers:

#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

You also need some setup:

WiFiManager wifiManager;
//first parameter is name of access point, second is the password
wifiManager.autoConnect("AP-NAME", "AP-PASSWORD");

You can omit the password if you don’t want one. There are a few other options you can find on the GitHub page. You can also install from there or use the Arduino library manager.

We had recently mentioned this library in our Blynk tutorial. If you are looking for some good consumer-like project to apply this to, how about a learning remote control?

39 thoughts on “Configure ESP8266 Wifi With WiFiManager

  1. That’s a brilliant idea. I just implemented it in about 3 minutes on my ESP and it does exactly what it says on the tin! So bloody simple to use… 3 includes and 2 lines that replace your wifi connect command… that’s it!

    1. Yeah the Hackaday hackers ought to start checking with you to find out what you know about before they post. After all nobody else matters right?

      Oh. Check with tv station about why they keep showing shows you don’t watch too.

    2. @Martin I assume you submitted this to Hackaday back in 2014?

      Can you include a link to your tutorial and video that you created to enlighten the rest of us? Maybe you can share all the other things you’ve done to show how much wiser you are than the rest of us?

      It took me a few weeks of searching and playing around with the ESP8266 before I stumbled on WifiManager last year. I had already started writing something similar and was glad to find something already done.

      I personally really appreciate that people take the time to write articles, summarize and share information that may save others time even when it is “old” news to those who have been doing this for a while.

    1. As far as user data it only sends/receives when you tell it to… I believe the WiFi standard has some sort of keep alive to tell the base station it’s still there, you could check 802.11 the RFC for that info…

  2. I’ve used this library as well. It is handy. I ended up assigning a pin to a button so that I could request to enter new wifi creds. Otherwise the esp would get confused due to a power blip and get stuck waiting for creds -or- I’d have to reprogram it to enter new creds.

  3. It looks very convenient, but can a hacker insert a man in the middle attack by jamming the local WiFi, connecting to the ESP then telling it to use a WiFi bridge device which then facilitates attacks against whatever the ESP’s function is?

    1. The hacker would have to know the password used in the WAP’s autoConnect setup.

      wifiManager.autoConnect(“AP-NAME”, “AP-PASSWORD”);

      But you can optionally omit that password if you want to be part-of-the-problem.

  4. This has me thinking since I have had that headache of setting an ESP device to a specific hot spot and then moving it and it breaks.
    I am using EspEasy firmware on ESP devices and controlling them using Node Red.
    I am using a Mosquitto MQTT broker in between to allow them to talk to each other.
    So I am thinking I may be able to publish a particular topic to the mqtt something like:
    /DeviceName/ChangeIP/123.456.789
    On the ESPEasy device you can set rules so you could (I think) subscribe to that topic and when it comes in, it would set the property for IP Address (EspEasy has many settable properties) then force it to reboot
    Gonna give it a try
    Damn… Just talked myself out of it- I realized if I move the device to a new location the ip address will be different so it will never get the mqtt message.

  5. Very nice. It works perfect.

    But once i ve configured the SSID, and passw of the new network, how do i reset the values ? so ESP8266 has to start the server again=

  6. Just got a new nodemcu delivered today…. Do I need to put in a particular firmware to use this wifi manager? Sorry for the dumb question but till nnow I have been working/learning arduino and esp is new to me.

  7. Been working on ESP8266 and finally I have put together an app that will autoconfigure your network settings. It first turn on your phone’s WIFI (if off), locates ESP automatically and connects to it, then allows you to select your network SSID and password and the same are pushed to ESP and saved !!!!!

    No need to hard code anything. “kapiloberoi@gmail” if any one needs the code and app !!!!!!

  8. Did someone get the following error related to ESP8266WebServer.h file when comipling arduino scketch?
    In file included from C:\directory/Arduino\arduino_esp8266_v2_wifimanager\arduino_esp8266_v2_wifimanager.ino:5:0:

    C:\directory\Arduino\libraries\ESP8266WebServer/ESP8266WebServer.h:27:22: fatal error: functional: No such file or directory

    #include

    ^

    compilation terminated.

    exit status 1
    Error compiling for board Arduino/Genuino Uno.

    To create the file I got code from GitHub, using notepad to save as .h (header). Same to ESP8266WebServer.cpp.
    Library is created without errors but arduino does not compile sketch.
    I did the same to DNSServer.h and .cpp and worked fine.
    Arduino Uno version 1.6.4.
    Googling error message was not so helpful.

    Any info is more than welcome.

    Tks

  9. I’m new to ESP8266. I tried the examples of wifimanager. I need a clarification: if I have programmed ESP, for example, with ssid = “net1”, can I change, with captive portal, the ssid, for example “net2”, for ever?
    Thank you

  10. A great sketch, good work.
    i’m new to this.
    How can this:
    configTime(0 * 3600, 0, “pool.ntp.org”, “time.nist.gov”);//
    setenv(“TZ”, “GMT-1BST,M3.5.0/01,M10.5.0/02”, 1);
    // Central European Time (Frankfurt, Paris)
    Be replaced with this and work, whats missing:
    TimeChangeRule CEST = {“CEST”, Last, Sun, Mar, 2, 120}; //Central European Time (Frankfurt, Paris)
    TimeChangeRule CET = {“CET “, Last, Sun, Oct, 3, 60}; //Central European Time (Frankfurt, Paris)
    Timezone CE(CEST, CET);
    using Arduino ide 1.8.5
    ESP8266 E12 nodemcu

  11. wifiManager generally works pretty well but one thing I don’t like is that after you have saved the WiFi credentials from the AP web page. the browser address of the new page includes both the SSID and the password in plain. This, I think, is a security hole as it stays in the browser history of the device you use to connect to the AP unless, of course, you clear the history or use the private browsing option. Not very idiot proof! Can anyone reassure me or come up with a fix I can use?

    1. Hey. You could access the wifimanager server programmatically from inside an app, and optionally disable most of the endpoints in the wifimanager code. That way you can control the http requests without any need for a browser. That is what I did. Unfortunately, it doesn’t do a whole lot to address the larger security hole that the whole thing is completely unsecured! Maybe someone can correct me but it seems that the option to “password protect” your session is completely pointless, as the data can be sniffed over the air. Shouldn’t the server be replaced with a secure bearssl server or something like that?

  12. Ok, thanks to tablatronix on the wifimanager github page, I now know that the fix is simple – just change any form actions in wifimanager from ‘get’ to ‘post’

  13. Hello,
    Just wondering if anyone have looked to add IFTTT AppKey to be configured via same WiFi manager configuration menu?
    Basically custom parameter to be stored, would be very useful for the devices triggering EFTTT events…
    May be it exists, would appreciate the data point.
    Thanks

  14. Sorry I’m new to this but I have built a water level sensor and post the results on line to thingspeak. I am using a basic ESP8266 module with an Arduino Uno 3. I have connected the ESP8266 up TX to 2, RX to 3, Power to power and CH-, and Ground to ground. I have tried to include DNSserver.h, WiFiManager.h,ESP8266WebServer.h,and ESP8266Wifi.h to my project which already uses softwareserial.h. When I try to copy it to my arduino I get an error that the queue.h is missing , as well as foundation and other files. Someplace else I saw that all I needed was the WiFiManager.h file but still get errors of missing files. what am I doing wrong? Can someone point me to a very clear detailed tutorial about this.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.