Este cacharrillo que parece no decir ni pío, pero en realidad es más listo que el hambre, puedes hacer virguerías en un plis-plas. Solo tienes que conectarlo a tu Wi-Fi, y ¡zas!, ya estás listo para mandar peticiones HTTP como si nada.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const char* ssid = "nombre_de_tu_wifi";
const char* password = "tu_contraseña";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Conectando al Wi-Fi...");
}
Serial.println("¡Conectado al Wi-Fi!");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin("http://ejemplo.com/api"); // URL de la petición HTTP
int httpResponseCode = http.GET(); // Puedes usar GET, POST, PUT, lo que necesites
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
} else {
Serial.print("Error en la petición: ");
Serial.println(httpResponseCode);
}
http.end();
}
delay(5000); // Espera 5 segundos antes de enviar la siguiente petición
}