0% found this document useful (0 votes)
5 views

Code

This document contains an Arduino sketch for controlling an LED via a web interface using an ESP8266 WiFi module. It sets up a WiFi access point and a web server that responds to requests to turn the LED on or off. The HTML interface includes buttons for the user to control the LED state.

Uploaded by

Varsha Ji
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Code

This document contains an Arduino sketch for controlling an LED via a web interface using an ESP8266 WiFi module. It sets up a WiFi access point and a web server that responds to requests to turn the LED on or off. The HTML interface includes buttons for the user to control the LED state.

Uploaded by

Varsha Ji
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <ESP8266WiFi.

h>
const char WiFiPassword[] = "9004652173";
const char AP_NameChar[] = "EmbeddedGate" ;

WiFiServer server(80);

String header = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";


String html_1 = "<!DOCTYPE html><html><head><title>LED
Control</title></head><body><div id='main'><h2>LED Control</h2>";
String html_2 = "<form id='F1' action='LEDON'><input class='button' type='submit'
value='LED ON' ></form><br>";
String html_3 = "<form id='F2' action='LEDOFF'><input class='button' type='submit'
value='LED OFF' ></form><br>";
String html_4 = "</div></body></html>";

String request = "";


int LED_Pin = D0;

void setup()
{
pinMode(LED_Pin, OUTPUT);

boolean conn = WiFi.softAP(AP_NameChar, WiFiPassword);


server.begin();

} // void setup()

void loop()
{

// Check if a client has connected


WiFiClient client = server.available();
if (!client) { return; }

// Read the first line of the request


request = client.readStringUntil('\r');

if ( request.indexOf("LEDON") > 0 ) { digitalWrite(LED_Pin, LOW); }


else if ( request.indexOf("LEDOFF") > 0 ) { digitalWrite(LED_Pin, HIGH); }

client.flush();

client.print( header );
client.print( html_1 );
client.print( html_2 );
client.print( html_3 );
client.print( html_4);

delay(5);
// The client will actually be disconnected when the function returns and
'client' object is detroyed

} // void loop()

You might also like