• Ankita Sharma

How to use WiFi Manager Library with NodeMCU?

The Internet of Things ( IoT) aims towards making life simpler by automating every small task around us. Many scientists are estimating that around 1.8 billion IoT devices will come up by the end of the year 2022. Hence, most of the engineers are interested in this domain, supporting to which there are numerous development boards to enable quick IoT prototyping. The most popular development boards used in IoT projects include Arduino, Raspberry Pi, and Esp8266. You can check out some latest IoT projects in this section.


In the case of IoT prototyping, devices can be connected to the internet by changing the WiFi SSID and password in the code. But when the device is handed over to the user, they should be able to connect to their Wi-Fi network without changing the hardcode. This is where a WiFi Manager helps. It allows you to connect your devices to different Access Points without changing the WiFi credentials. So, let us learn How to use WiFi Manager with NodeMCU.


Hardware Requirements:


The following hardware components are required to perform this task -


NodeMCU ESP8266 :

NodeMCU Esp8266

ESP8266 is a low-cost microcontroller chip that is used to interface various hardware components. It has inbuilt #WiFi and Bluetooth capabilities, making it a better candidate for IoT projects and Developments. Also, it is very cost-efficient as well as consumes less power. It allows us to use it as a micro-controller and manipulate input and output.


Buy Esp8266 from here.


USB Cable :

USB Cable

USB ( Universal Serial Bus ) Cable is used to connect the #development boards ( NodeMCU in this case ) to the system ( For eg: Laptops ).


Buy USB Cable from here.


Software Requirement:


Arduino IDE :

Arduino IDE

Arduino Integrated Development Environment ( #IDE ) is open-source software that facilitates the development and uploading of codes to the microcontroller. Program written in Arduino IDE is known as Sketch. These Sketch files are saved with the file extension ino.


Click on the link to download the software.


Installing WiFi Manager Library :


  1. Click here to download the WiFi Manager Library.

  2. Go to Code > Download ZIP.

  3. Open Arduino IDE > Sketch > Add .ZIP Library.

  4. Select the. ZIP file that you just downloaded.

  5. A message will get displayed on the screen saying " A library named WiFi manager successfully installed ".


Code Explanation :


The code explanations are as follows -


Firstly, we need to include the following libraries for the WiFi manager.

#include <ESP8266WiFi.h>               

The above library connects the ESP8266 board to the WiFi #network.

#include <DNSServer.h>

It enables the client to open a web server running on ESP8266 using a domain name.

#include <ESP8266WebServer.h>

The above library handles all HTTP #protocols.

#include <WiFiManager.h>  

This library is used to manage WiFi connections without changing the hardcode.

void setup() {

    Serial.begin(115200);
    // Creating WiFi Manager Object
    WiFiManager wifiManager;
    wifiManager.resetSettings();
    wifiManager.autoConnect();

    Serial.println("connected...yeey :)");
}

The above function resets the ESP board in the access point mode. If the connection is successfully established, a message will appear " Connected. . .yeey : )".


Complete Code :

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

void setup() {
  
    Serial.begin(115200);
    WiFiManager wifiManager;
    
    //wifiManager.resetSettings();
    
    wifiManager.autoConnect();

    //if the connection is successful, you will get here.
    Serial.println("connected...yeey :)");
}

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

Download the document given below, copy the code, and then paste it into the Arduino IDE code window.

AutoConnect
.txt
Download TXT • 1KB

NodeMCU WiFi Manager Working :


Once the code is written in the #ArduinoIDE, connect the ESP8266 board to the system via USB cable. Now, upload the code to the board and then run the program.


When the user uses a new #Wi-Fi connection on the system, he/she will be directed to a webpage as shown below.

WiFi Manager

Here, the user can configure a new #SSID and password. Then it tries to form a connection, and if the connection is established successfully, a message will be displayed in the serial monitor " connected...yeey :) ".


Do watch the video given below to get a better idea through practical implementation.


Video By - Harshit Gupta


Conclusion :


A WiFi #Manager manages wireless connections in your IoT devices by allowing users to connect to their own WiFi networks without changing the hardcode. Also, it allows you to manage multiple SSID connections. The WiFi Manager Library is a great library to add to your #IoT projects.

NodeMCU Projects :


  • Facebook
  • YouTube
  • Instagram
  • LinkedIn
LearnElectronics
Contact Us
© Copyright - LearnElectronics 2020.