Webserver Home IOT Static IP
Home IOT (internet of things) plays big role in our society, the know-how increases our understanding as well as controlling such technology, this topic discusses the use of home IOT through web server with local IP address. Moreover the local IP address gives more quick accessibility and batter network organization.
The project is to make a web server that can control two LED and can switch them ON / OFF through local web page, the project will use local IP address which can be accessed through home WiFi, the LED can be changed to any relay or device. This project is not limited to this project and it can host any future expansion, please note that this project was build on the referenced project.
Supplies
- NODE MCU ESP8266
- Two 1K Ohm resistors
- Bread board
- Two jumper M/F
- Two LED
- Micro USB cable
Block Diagram
The first step is to construct the circuit diagram, its easy to fabricate it as in the block diagram.The Node MCU is in the center of all the units as it interconnects all components to together . Note that both LEDs are connected via a resistor of 1 K ohm to protect the led, hence the cathode terminal of the led is connected to the positive terminal, the anode in the other hand is connected to the ground (0v). All negative terminals are common for all and connected to the Node MCU GRD terminal. The definition of the pin terminals at the node MCU is in term of GPIO but in the ESP8266 PCB it is printed in term of D1 and so on. D1 is corresponds to GPIO 5 and D2 corresponds to GPIO 4.
Setup the Node MCU in Arduino IDE
The node mcu esp8266 needs further setting up in order to communicate with the Arduino IDE especially if its the first time, the following steps are the configration:
- Load the following URL in the file / preference additional board management , http://arduino.esp8266.com/stable/package_esp8266com_index.json
- Go to tools the board managements then type in ESP8266 and select esp8266 community and install
Now you can select the ESP8266 board form the tools boards / ESP8266 / Node MCU 1.0 12E. Prior this selection make sure that the esp8266 board weather its 1.0 or 0.9. Finally connect the node mcu and define the communication port.
Coding the ESP8266
The coding of the node mcu starts by including the library (esp8266Wifi.h) in the first line. Then define the username and password of the local wifi. After that because the webserver will have a local IP address the following steps are to define the the network IP address. The local IP is what you want the webserver to be its important to keep all values similier to the gateway except the last value, if you can find the gateway and ip address of the connected devices at home you can install app called iNet which can shows all devices within your network. second step is to define the gpio pins states and the GPIO pins along with the time line current and previous. For more infomation about his code there is a great explination in this link.
In the third photo the code is in the step up stage, the esp8266 will connect to the locate network finding the IP address of the gateway and localize the IP for the web server and then connect to the network through the username and password, finally the web server begins interacting with the user.
In the loop funcaiton the web server when its avilable it starts listing to the incoming messages and makes the comparreson between the preiouis and current values whenever there is a change the byte will be read .However when the massage header corrsponds to the line HTTP the the clint will read the messga util connection is close. after that through the index the analyisis of the message will be so if its to GET 5 on ( it means turn on GPIO 5 ) so it will be digitalWrite (ouput5, HIGH); then smilier process happens to the off state and GPIO 4.
Last stage of the code is the web server page, this page is in term od HTML fomate and in order to understand the full picture the HTML constrution there are number of websites that explains them in deatils however the mainplation of the HTML is not. I would like to thank Random Nerd tutorails for thier brife explaination and please visit this link to have batter knowalge about the code https://randomnerdtutorials.com/esp8266-web-server/.
Downloads
Fabrication
In this stage connect all the components together and load the code in the Node mcu, remember that the web server esp8266 and the access device to (labtop, smart phone and so on) shall be in the same wifi host. Then in the browser address type in the IP address. The web page appers will monitir the two LEDS and thier state , once you push one of the leds the light will go on and if you push it again it will turn off, similierly appens to the second led.
Reference
randomnerdtutorials.2019.Build an ESP8266 Web Server – Code and Schematics (NodeMCU)[ONLINE] Available at:https://randomnerdtutorials.com/esp8266-web-server/[Accessed SEP2022].