#include #include #include #include // defino credenciales red const char* ssid = "CASA"; const char* password = "Caramel0"; float val; float temp; String ids = "T00"; int id = 1; int temp1; int hume1; WiFiClient client; void setup() { Serial.begin(115200); WiFi.begin(ssid, password); Serial.print("Conectando..."); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("Conexión OK!"); Serial.print("IP Local: "); Serial.println(WiFi.localIP()); } void loop() { val = analogRead(A0); temp = log(((10240000 / val) - 10000)); temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * temp * temp )) * temp ); temp = temp - 318.15; Serial.print(temp); Serial.println("°C"); delay(10000); EnvioDatos(); double temp; } // rutina de envio de datos por POST void EnvioDatos() { if (WiFi.status() == WL_CONNECTED) { temp1 = random(2,8); hume1 = random(2,8); HTTPClient http; // creo el objeto http String datos_a_enviar = "idsensor=" + ids + id + "&temp=" + temp1 + "&hume=" + hume1; http.begin(client, "http://server.mxsig.com.mx:9000/sensoresf/"); http.addHeader("Content-Type", "application/x-www-form-urlencoded"); // defino texto plano.. int codigo_respuesta = http.POST(datos_a_enviar); if (codigo_respuesta > 0) { Serial.println("Código HTTP: " + String(codigo_respuesta)); if (codigo_respuesta == 200) { String cuerpo_respuesta = http.getString(); Serial.println("El servidor respondió: "); Serial.println(cuerpo_respuesta); } } else { Serial.print("Error enviado POST, código: "); Serial.println(codigo_respuesta); } if (id < 4){ id++ ; } else { id =1 ; } Serial.print("temp: "); Serial.print(temp1); Serial.print(" hume: "); Serial.println(hume1); http.end(); // libero recursos } else { Serial.println("Error en la conexion WIFI"); } delay(500); //espera 60s }