-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSERVIDOR_ESP32_FOQUITO_LED.ino
54 lines (44 loc) · 1.37 KB
/
SERVIDOR_ESP32_FOQUITO_LED.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <WiFi.h>
#include <WebServer.h>
const char* ssid = "";
const char* password = "";
const int ledPin = 2;
WebServer server(80);
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
// Conectar a la red WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Conectando a la red WiFi...");
}
Serial.println("Conexión WiFi establecida.");
Serial.print("Dirección IP: ");
Serial.println(WiFi.localIP());
// Rutas para manejar las solicitudes HTTP
server.on("/", HTTP_GET, []() {
String content = "<h1>Bienvenido al ESP32 Web Server</h1>";
content += "<p>Dirección IP del servidor: ";
content += "<p>Control del LED:</p>";
content += "<a href=\"/encender\"><button>Encender LED</button></a> ";
content += "<a href=\"/apagar\"><button>Apagar LED</button></a>";
server.send(200, "text/html", content);
});
server.on("/encender", HTTP_GET, []() {
digitalWrite(ledPin, HIGH);
server.sendHeader("Location", "/");
server.send(303);
});
server.on("/apagar", HTTP_GET, []() {
digitalWrite(ledPin, LOW);
server.sendHeader("Location", "/");
server.send(303);
});
server.begin();
Serial.println("Servidor HTTP iniciado.");
}
void loop() {
server.handleClient();
}