/*
//Ass3 Web Server for LED Control
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
// Replace with your network credentials
const char* ssid = "Wokwi-GUEST"; //your SSID
const char* password = ""; //pass
// GPIOs for the LEDs
const int ledPin1 = 26;
const int ledPin2 = 27;
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
// Set GPIOs as outputs
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
// Serve the HTML page
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
String html = "<html><head><title>ESP32 LED Control</title>";
html += "<style>";
html += "body {font-family: Arial, sans-serif; background-color: #f4f4f4; text-align: center; color: #333;}";
html += "h1 {color: #0275d8;}";
html += "button {display: inline-block; padding: 10px 20px; font-size: 16px; margin: 10px; cursor: pointer; background-color: #0275d8; color: white; border: none; border-radius: 5px;}";
html += "button:hover {background-color: #025aa5;}";
html += "a {text-decoration: none;}";
html += "</style></head><body>";
html += "<h1>ESP32 LED Control</h1>";
html += "<p><a href=\"/led1/on\"><button>Turn LED 1 ON</button></a></p>";
html += "<p><a href=\"/led1/off\"><button>Turn LED 1 OFF</button></a></p>";
html += "<p><a href=\"/led2/on\"><button>Turn LED 2 ON</button></a></p>";
html += "<p><a href=\"/led2/off\"><button>Turn LED 2 OFF</button></a></p>";
html += "</body></html>";
request->send(200, "text/html", html);
});
// Turn LED 1 on
server.on("/led1/on", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(ledPin1, HIGH);
request->send(200, "text/html", "<p>LED 1 is ON</p><a href=\"/\">Go Back</a>");
});
// Turn LED 1 off
server.on("/led1/off", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(ledPin1, LOW);
request->send(200, "text/html", "<p>LED 1 is OFF</p><a href=\"/\">Go Back</a>");
});
// Turn LED 2 on
server.on("/led2/on", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(ledPin2, HIGH);
request->send(200, "text/html", "<p>LED 2 is ON</p><a href=\"/\">Go Back</a>");
});
// Turn LED 2 off
server.on("/led2/off", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(ledPin2, LOW);
request->send(200, "text/html", "<p>LED 2 is OFF</p><a href=\"/\">Go Back</a>");
});
// Start server
server.begin();
}
void loop() {
// Nothing to do here, everything is handled by the server callbacks
}
*/
// #include <WiFi.h>
// #include <AsyncTCP.h> // Ensure this library is included
// #include <ESPAsyncWebServer.h>
// // Replace with your network credentials
// const char* ssid = "Wokwi-GUEST";
// const char* password = "";
// // GPIOs for the LEDs
// const int ledPin1 = 26;
// const int ledPin2 = 27;
// // Create AsyncWebServer object on port 80
// AsyncWebServer server(80);
// void setup() {
// // Initialize Serial Monitor
// Serial.begin(115200);
// // Set GPIOs as outputs
// pinMode(ledPin1, OUTPUT);
// pinMode(ledPin2, OUTPUT);
// digitalWrite(ledPin1, LOW);
// digitalWrite(ledPin2, LOW);
// // Connect to Wi-Fi
// WiFi.begin(ssid, password);
// while (WiFi.status() != WL_CONNECTED) {
// delay(1000);
// Serial.println("Connecting to WiFi...");
// }
// Serial.println("Connected to WiFi");
// Serial.print("IP Address: ");
// Serial.println(WiFi.localIP());
// // Serve the HTML page
// server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
// String html = "<html><head><title>ESP32 LED Control</title>";
// html += "<style>";
// html += "body {font-family: Arial, sans-serif; background-color: #f4f4f4; text-align: center; color: #333;}";
// html += "h1 {color: #0275d8;}";
// html += "button {display: inline-block; padding: 10px 20px; font-size: 16px; margin: 10px; cursor: pointer; background-color: #0275d8; color: white; border: none; border-radius: 5px;}";
// html += "button:hover {background-color: #025aa5;}";
// html += "a {text-decoration: none;}";
// html += "</style></head><body>";
// html += "<h1>ESP32 LED Control</h1>";
// html += "<p><a href=\"/led1/on\"><button>Turn LED 1 ON</button></a></p>";
// html += "<p><a href=\"/led1/off\"><button>Turn LED 1 OFF</button></a></p>";
// html += "<p><a href=\"/led2/on\"><button>Turn LED 2 ON</button></a></p>";
// html += "<p><a href=\"/led2/off\"><button>Turn LED 2 OFF</button></a></p>";
// html += "</body></html>";
// request->send(200, "text/html", html);
// });
// // Turn LED 1 on
// server.on("/led1/on", HTTP_GET, [](AsyncWebServerRequest *request){
// digitalWrite(ledPin1, HIGH);
// request->send(200, "text/html", "<p>LED 1 is ON</p><a href=\"/\">Go Back</a>");
// });
// // Turn LED 1 off
// server.on("/led1/off", HTTP_GET, [](AsyncWebServerRequest *request){
// digitalWrite(ledPin1, LOW);
// request->send(200, "text/html", "<p>LED 1 is OFF</p><a href=\"/\">Go Back</a>");
// });
// // Turn LED 2 on
// server.on("/led2/on", HTTP_GET, [](AsyncWebServerRequest *request){
// digitalWrite(ledPin2, HIGH);
// request->send(200, "text/html", "<p>LED 2 is ON</p><a href=\"/\">Go Back</a>");
// });
// // Turn LED 2 off
// server.on("/led2/off", HTTP_GET, [](AsyncWebServerRequest *request){
// digitalWrite(ledPin2, LOW);
// request->send(200, "text/html", "<p>LED 2 is OFF</p><a href=\"/\">Go Back</a>");
// });
// // Start server
// server.begin();
// }
// void loop() {
// // Nothing to do here, everything is handled by the server callbacks
// }