#include <WiFi.h>
#include <WebServer.h>
const char* ap_ssid = "jorgenerico";
const char* ap_password = "12345678";
WebServer server(80);
void setup_wifi() {
// Configurar ponto de acesso
WiFi.softAP(ap_ssid, ap_password);
Serial.print("Ponto de acesso IP: ");
Serial.println(WiFi.softAPIP());
}
void handleRoot() {
server.send(200, "text/html", getHtml());
}
void handleOn() {
digitalWrite(2, HIGH); // Liga o LED no pino 2
server.send(200, "text/html", getHtml());
}
void handleOff() {
digitalWrite(2, LOW); // Desliga o LED no pino 2
server.send(200, "text/html", getHtml());
}
String getHtml() {
String html = "<html><head><title>Controle do LED</title> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"></head><body>";
html += "<h1>Controle o LED</h1>";
html += "<p><a href=\"/on\">Ligar LED</a></p>"; // Link para ligar o LED
html += "<p><a href=\"/off\">Desligar LED</a></p>"; // Link para desligar o LED
html += "</body></html>";
return html;
}
void setup() {
pinMode(2, OUTPUT); // Define o pino 2 como saída
Serial.begin(115200);
setup_wifi(); // Configura o ponto de acesso Wi-Fi
// Define as rotas para o servidor web
server.on("/", handleRoot);
server.on("/on", handleOn);
server.on("/off", handleOff);
// Inicia o servidor
server.begin();
}
void loop() {
server.handleClient(); // Mantém o servidor ativo
}