0% found this document useful (0 votes)
33 views3 pages

Iot

This document is an Arduino sketch for controlling an LED using an ESP8266 microcontroller via a web server. It connects to a specified WiFi network and provides a simple HTML interface to turn the LED on or off. The server handles requests for the LED status and updates the HTML page accordingly.

Uploaded by

Alfred Baraka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Iot

This document is an Arduino sketch for controlling an LED using an ESP8266 microcontroller via a web server. It connects to a specified WiFi network and provides a simple HTML interface to turn the LED on or off. The server handles requests for the LED status and updates the HTML page accordingly.

Uploaded by

Alfred Baraka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include<ESP8266WiFi.

h>

#include<ESP8266WebServer.h>

#include<ESP8266mDNS.h>

ESP8266WebServer server(80);

String getHTML();

void haipatikani();

void watupori();

void LEDON();

void LEDOFF();

int led=4;

const char* ssid="nkwera";

const char* password="nkwera@newPC.2025";

int LED_status=LOW;

void setup(){

pinMode(led,OUTPUT);

Serial.begin(115200);

delay(100);

WiFi.begin(ssid,password);

delay(1000);

int n=0;

while(WiFi.status()!=WL_CONNECTED){

delay(1000);

Serial.print("Try to connect ");

Serial.print(++n);

Serial.print(" ");

Serial.print("\n");

Serial.print("WiFi established IP address is ");

Serial.print(WiFi.localIP());

Serial.print("\n");

server.on("/", watupori);
server.on("/ledON",LEDON);

server.on("/ledOFF",LEDOFF);

server.onNotFound(haipatikani);

server.begin();

delay(100);

void loop(){

server.handleClient();

void watupori(){

server.send(200,"text/html", getHTML());

void LEDON(){

LED_status=HIGH;

digitalWrite(led,LED_status);

server.send(200,"text/html",getHTML());

void LEDOFF(){

LED_status=LOW;

digitalWrite(led,LED_status);

server.send(200,"text/html",getHTML());

void haipatikani(){

server.send(404,"text/plain" "SERVER NOT FOOUND");

String getHTML(){

String html="<!DOCTYPE html>";

html+="<html><head><title>IOT page</title></head>";

html+="<body><h1><u>LED CONTROL</u></h1><br><br>";

html+="<p>LED status: ";

if(LED_status==LOW)
html+="OFF </p>";

else

html+="ON </p>";

html+="<a href='/ledON'>TURN ON</a><br><br>";

html+="<a href='/ledOFF'>TURN OFF</a></body></html>";

return html;

You might also like