How to configure WiFi Credentials of your ESP module in runtime?

Deepak Radhakrishnan
()

ESP modules are a breakaway in the world of IoT. We could underline and say that ESP has helped to create smart devices effortless and cost-effective. The normal practice would be to hardcode WiFi credentials, MQTT credentials, etc. Today I am glad to guide you on how to configure wifi credentials in runtime.

Contents

Overview

The typical method, we practice, is to hardcode the WiFi credentials. This blog will be helpful for you to have an understanding of how to install the Wifi manager Library and How to use the Wifi Manager in our projects.

Why Runtime Configuration is so Important?

It is a tedious task to reprogram your ESP module each time as you relocate your device or when you have changed the WiFi password. And this exactly the reason as to why hardcoding these credentials is not really a good idea.

Well, truth be told, this is not the Industrial practice when you develop a commercial product as you hardcode the client’s credential in it and handover. Yes, it also helps in making your code less sharable.

WiFi-Manager

The WiFi-Manager is an Arduino library developed by tzapu, which assists in configuring wifi credentials in runtime. The WiFi-Manager does what a lot of commercial devices do. It starts off an access point if no previous configuration were to be found or if you are not able to join any wifi. You can configure your new wifi credentials by simply connecting to the access point created by the ESP module by making use of a wifi-enabled Phone or Tablet.

How does it work?

Once the power is ON, it will start searching for the previously connected wifi. If nothing is found esp module will create an access point on its own and spin up a DNS server with a default IP address 192.168.1.4.

You can connect to that AP through mobile or Tablet. Then open a browser to type the IP 192.168.1.4 or maybe try searching google and it will redirect you to the configuration page. You will be able to configure your WiFi credentials over there. Once you hit save, your esp module will restart and connect to the WiFi network you configured.

ESP Wifi Manager Steps

Adding Library to Arduino IDE

In the Arduino IDE, go to Tools > Manage Libraries, in the search bar type “wifimanager”. For mac users Window > Manage Libraries. Check out the following:

Choose the latest stable library, Click install, which will download and install the WiFi Manager library. Once it is installed, you can go to the Arduino Library Folder to see the example sketches to upload to your ESP8266 module.

Usage

You can simply include the following lines of code to your program to use wifi manager.

#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>   


void setup
{
......
.....
//replace your wifi connection code with this 
WiFiManager wifiManager;
wifiManager.autoConnect("TechroverAP");
....


}
 

Testing

I have added wifimanager code to my previous project. As you have noticed, I have replaced the wifi connection code with the above code for wifimanager. Tada!

Conclusion

I hope you got a clear understanding of How to install the Wifi manager Library and How to use the Wifi Manager in our projects. For the needs of a new connected world, ESP is one of the most popular WiFi module available in the market, allowing makers to develop IoT products easily.

You can find out further information regarding the WiFi Manager library from GitHub page.

Helpful? spread the word! #Dream_it#Code_it#Happy_Coding

How useful was this post?

Click on a starts to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow me on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

%d bloggers like this: