#pragma once #include #include HTTPClient http; const char* serverUrl = "https://alumnos2026.unicarlos.es/mario_alcantud_bleda/MER/esp32_wifimanager_oled_dht22_php/php.php"; unsigned long lastTime = 0; const long interval = 10000; // 10 segundos void enviarDatosJSON(float temp, float hum) { if (WiFi.status() == WL_CONNECTED) { StaticJsonDocument<200> doc; doc["accion"] = "guardarTemHum"; doc["temp"] = temp; doc["hum"] = hum; String jsonString; serializeJson(doc, jsonString); http.begin(serverUrl); http.addHeader("Content-Type", "application/json"); int httpCode = http.POST(jsonString); Serial.print("Enviando PHP: "); Serial.println(jsonString); if (httpCode > 0) { String response = http.getString(); Serial.print("Respuesta PHP: "); Serial.println(response); } else { Serial.print("Error en HTTP request PHP: "); Serial.println(httpCode); } http.end(); } } void loopPHP() { unsigned long currentTime = millis(); if (currentTime - lastTime >= interval) { lastTime = currentTime; enviarDatosJSON(temperaturaFloat, humedadFloat); } }