GRACIAS!
VUELVA
PRONTOS!
#include <ESP32Servo.h>
// Configuración de la red WiFi
const char* ssid = “AQUÍ ESCRIBE EL NOMBRE DE TU RED WIFI”;
const char* password = “Y ACÁ TU CONTRASEÑA”;
Servo myServo;
int servoPin = 14; // Cámbialo si conectaste tu servo a otro pin
// Servidor web en el puerto 80
WebServer server(80);
// Función que se ejecuta cuando llega el webhook
void handleMover() {
Serial.println(“Webhook recibido: moviendo servo…”);
myServo.write(180); // Mueve el servo a 180°
delay(2000); // Mantiene la posición 2 segundos
myServo.write(0); // Regresa a 0°
server.send(200, “text/plain”, “Servo movido”);
}
// Página principal
void handleRoot() {
server.send(200, “text/plain”, “Servidor ESP32 activo. Usa /mover para accionar el servo.”);
}
void setup() {
Serial.begin(115200);
// Conectar a la red WiFi
WiFi.begin(ssid, password);
Serial.print(“Conectando a WiFi…”);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println(“\nConectado a WiFi!”);
Serial.print(“IP del ESP32: “);
Serial.println(WiFi.localIP());
// Inicializar el servo
myServo.attach(servoPin);
myServo.write(0);
// Configurar las rutas del servidor
server.on(“/”, handleRoot);
server.on(“/mover”, handleMover);
// Iniciar el servidor web
server.begin();
Serial.println(“Servidor HTTP iniciado”);
}
void loop() {
server.handleClient();
}
copia y pega en tu IDE preferido, compila y a darle átomos!