Tutorials

Change WiFi Credentials of ESP8266 without uploading code again

Learn how to change the wifi credientials of ESP8266 over the air without touching and uploading the edited code through Arduino IDE.

If you are working with the ESP8266 in your project, surely you had the same problem as us: what to do when you change the WiFi network to which your ESP8266  is to be connected. This is the main issue faced by many IOT device creators.

Normally we enter the SSID and the password of the  WiFi network directly in the programming code, but it can be inconvenient if we transfer the project we are dealing with, or if the end user who is going to use it does not know anything about programming it.

esp8266 connected to pc to change wifi credentials

In these cases, its very hard to open the box of the esp board or if it is fixed inside any box in home automation systems and connect it to laptop or PC and need to have an access to the previous code and upload it again into the ESP8266 board which is very stubborn task.

So, in this situation we have 2 solutions which we gonna explain below in detail with code and how to implement it in your previous programs. The first method is by using the code which we provided below and the other is by using an Arduino library named ‘WiFi Manager’. So lets get started.

Method 1: Code inside sketch. Storing the WiFi credentials inside EEPROM

In this method, we are going to use EEPROM to store the wife credentials inside it, and retrieving the stored data and connecting to that network if available. If the WiFi network is not available it ill create a WiFi hotspot to which we need to connect any device like laptop or mobile to change the WiFi credentials over web server.

To do so we need to get into setting by typing 192.168.4.1 on your device browser to access the setting page, where we can see the available networks and there signal strengths. So enter the SSID and PASSWORD of the network which you wanted to connect and click save.

change wifi credentials esp8266]

That it the network credentials are written into the EEPROM of the board and it will restart and search for the network which was stored in the EEPROM and connect to the network and continue executing our program.

Required Libraries:

  • ESP8266WiFi.h
  • ESP8266HTTPClient.h
  • ESP8266WebServer.h
  • EEPROM.h

Method1 Code:

In the above code you need to add the main work code which the esp8266 has to perform after connecting to network  If you want to test the above code insert the below code for blinking the LED on board by adding blow code inside the above code by replacing “// Add your program code here which the esp8266 has to perform when it connects to network”.

Method2: Using the WiFi manager library from Arduino IDE

This method is very simple than the previous one, in this you just need to download a library from arduino IDE by following the steps below. To download directly and install manually click here.

Step1: In Arduino IDE got to Sketch/Include Library/Manage Libraries

how to install a library in arduino ide
In Arduino IDE got to Sketch/Include Library/Manage Libraries

Step2: search for WiFiManager and install it.

search for WiFiManager

include the library in the sketch or code. by adding

  • To Initialize WiFi manger library, in your setup function add

  • Also in the setup function add

First parameter is name of access point or hotspot to be created, second is the password you can leave it empty if you want it as an open network.

After uploading the code you will find and WiFi network same as the previous method and connect to it, it will redirect you to the webserver homepage with option to connect to the WiFi networks which are available with in. The page looks like below image.

wifi manager dashboard arduino ide esp 8266That’s it, you are now connected to the new WiFi network and your esp8266 is ready to use with new WiFi network and this method works same as the previous method by storing the WiFi credentials in the EEPROM.

You you have any doubts regarding the the above methods and found any errors in the above code please comment below. if you like this tutorial please share it to you friends.

CircuitSchools Staff

We at CircuitSchools publish on basics of electronics and electric components and everything related to evolution of electrical technology with complete analysis of development boards and modules along with latest projects with innovative ideas.

Related Articles

Back to top button