Practical 3 (IOT)
Practical 3 (IOT)
Practical – 3
Aim: To create a standalone web server that controls outputs (two LEDs).
Theory:
Web server is a place which stores, processes and delivers web pages to Web
clients. Web client is
nothing but a web browser on our laptops and smartphones. The communication
between client and
server takes place using a special protocol called Hypertext Transfer Protocol
(HTTP)
Procedure:
How to create a web server to control two outputs using Arduino IDE.
When a URL is typed in a web browser and hit ENTER, then the browser sends a HTTP
request (a.k.a. GET request) to a web server. It’s a job of web server to handle this request by
doing something.
we are going to control things by accessing a specific URL. For example, suppose we
entered a URL like http://192.168.1.1/ledon in a browser. The browser then sends a HTTP
request to ESP8266 to handle this request. When ESP8266 reads this request, it knows that
user wants to turn the LED ON. So, it turns the LED ON and sends a dynamic webpage to a
Code:
// Load Wi-Fi library
#include <WiFi.h>
// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0;
// Define timeout time in milliseconds
const long timeoutTime = 2000;
void setup() {
Serial.begin(115200);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
void loop() {
WiFiClient client = server.available(); // Listen for incoming clients
client.println("Connection: close");
client.println();
} else {
client.println("<p><a href=\"/5/off\"><button class=\"button
button2\">OFF</button></a></p>");
}
client.println("</body></html>");
Copy that IP address, because you need it to access the web server.
Accessing the Web Server. Open the browser and type the Node MCU IP address, and the
following page will be displayed as shown in below figure. This page is sent by the NodeMCU
when a request on the NodeMCU IP address is made.
Other information about the HTTP request such as HTTP header fields can be
also seen. They define the operating parameters of an HTTP transaction.
Output:
Conclusion:
The standalone web server was successfully created using NodeMCU, enabling the
control of two LEDs via a web interface. This project demonstrates the integration
of IoT technology with web development, providing a user-friendly platform to
manage hardware outputs remotely. It highlights the potential for scalable solutions
in smart home automation and similar applications, ensuring reliable and efficient
operation with minimal hardware requirements.