0% found this document useful (0 votes)
13 views2 pages

Led Control Wifi

Programming

Uploaded by

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

Led Control Wifi

Programming

Uploaded by

mail.extra.ac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <WiFi.

h>

// Define LED pin


const int ledPin = 32;

// WiFi credentials
const char* wifiName = "ESP-WIFI";
const char* password = "";

// Create a server on port 80


WiFiServer server(80);

void setup() {
Serial.begin(115200); // Match this baud rate with
the Serial Monitor settings

pinMode(ledPin, OUTPUT); // Set LED pin as


output
digitalWrite(ledPin, LOW); // Start with LED
off

// Start Wi-Fi access point


WiFi.softAP(wifiName, password);

// Start the server


server.begin();
}

void loop() {
// Check for incoming client connections
WiFiClient client = server.available();
if (client) {
Serial.println("New Client Connected");
// Read the client's request
String request = client.readStringUntil('\r');
Serial.println(request);

// Process ON/OFF requests


if (request.indexOf("GET /ON") != -1) {
digitalWrite(ledPin, HIGH); // Turn LED on
} else if (request.indexOf("GET /OFF") != -1) {
digitalWrite(ledPin, LOW); // Turn LED off
}

// Send the HTML page


client.println("HTTP/1.1 200 OK\nContent-
type:text/html\n");
client.println();
client.println("<!DOCTYPE html>"
"<html>"
"<head><title>ESP32 LED
Control</title></head>"
"<body>"
"<h1>LED Control</h1>"
"<button
onclick=\"location.href='/ON'\">ON</button>"
"<button
onclick=\"location.href='/OFF'\">OFF</button>"
"</body>"
"</html>");

// Stop the client connection


client.stop();
}
}

You might also like