#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST"; // Nombre de tu red WiFi
const char* password = ""; // Contraseña de tu red WiFi
const char* serverURL = "https://vastondev.000webhostapp.com/ahora2.php"; // URL del servidor donde deseas enviar los datos
String dataToSend = "Dato1=Valor1&Dato2=Valor2"; // Datos que deseas enviar
String url = "https://vastondev.000webhostapp.com/ahora2.php?Dato1=Valor1&Dato2=Valor2";
void setup() {
Serial.begin(115200);
delay(10);
// Conéctate 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 exitosa");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
// Construye la URL completa incluyendo los datos
http.begin(url);
// Realiza una solicitud HTTP GET
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println("Respuesta del servidor: " + response);
} else {
Serial.print("Error en la solicitud. Código de respuesta HTTP: ");
Serial.println(httpResponseCode);
}
http.end();
}
delay(5000); // Espera 5 segundos antes de realizar la siguiente solicitud
}