Controlling Things using WebServer(MicroPython) | Codegnan | MicroPython

Опубликовано: 02 Октябрь 2024
на канале: Codegnan
77
7

The Hypertext Transfer Protocol (HTTP) is a standard application layer protocol that functions as a request-response protocol between server and client.
It is widely used in IoT (Internet of Things) embedded applications, where every sensor is connected to a server and we have access to control them over the internet.

NodeMCU has Wi-Fi functionality available on board. With this Wi-Fi functionality, NodeMCU can connect to any wi-fi network as a client or it can create a network to which other wi-fi enabled devices can connect.

NodeMCU as HTTP Server using Wi-Fi AP mode
NodeMCU wi-fi has Access Point (AP) mode through which it can create Wireless LAN to which any wi-fi enabled device can connect as shown in the below figure.

NodeMCU as HTTP Server using Wi-Fi AP mode
We can set SSID and Password for AP mode which will be used to authenticate other devices while connecting to it.

NodeMCU as HTTP Server using Wi-Fi STA mode
NodeMCU has Station (STA) mode using which can connect to the existing wi-fi network and can act as an HTTP server with an IP address assigned by that network.

NodeMCU as HTTP Server using Wi-Fi STA mode
NodeMCU gets IP from the Wi-Fi router to which it is connected. With this IP address, it can act as an HTTP server to which any wi-fi device can connect.

Let’s write Arduino Sketch to enable NodeMCU as an HTTP server with Wi-Fi STA/AP mode and control an LED connected at the server-side from the client-side.
HTML page for client
As we are making an HTTP server for LED on/off functionality, we are going to make a simple HTML page that will be visible at the client-side and able to take user input for LED on/off. It is a user-friendly representation of button input that takes input from the user on click.
We need to write two HTML pages for LED ON and LED OFF state i.e. when a client clicks the LED ON button, then in the next action, we need to provide options for LED OFF. Below are the two HTML code snippets for LED ON and LED OFF state presentation

Learn Machine Learning from our Tutorials: http://bit.ly/CodegnanMLPlaylist
Learn Python from our Tutorials: http://bit.ly/CodegnanPythonTuts

Subscribe to our channel and hit the bell icon and never miss the update: https://bit.ly/SubscribeCodegnan

++++++++++++++Follow us ++++++++++++++++
Facebook: https//facebook.com/codegnan
Instagram: https://instagram/codegnan
Telegram: https://t.me/codegnan
Linkedin:   / codegnan  

Visit our website: https://codegnan.com

About us:
CodeGnan offers courses in new technologies and niches that are gaining cult reach. This is to ensure that students understand the workflow from each and every perspective in a Real-Time environment. Students can train themselves and enrich their skillset in the best way possible.
We always used to believe in student-centric methods. Every student, if trained in a Real-Time environment can achieve more in their careers. Hence, CodeGnan offers courses where students can access live environments and nourish themselves in the best way possible in order to increase their “CodeGnan”.

With Codegnan, you get an industry-recognized certificate with worldwide validity. You get to reach the heights of your career in a shorter period of time. With your skill set, you can find a place at any top companies in India and worldwide. This will help you to improve your skill set like never before and get access to the top level placement opportunities that are currently available.

CodeGnan offers courses in new technologies and makes sure students understand the flow of work from each and every perspective in a Real-Time environment.

#ControllingThingsusingWebServer #MicroPython #WebServer