-
-
Save parzibyte/b50c12b9b67ac53c8a108b2465cbfca3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Nuestra pequeña API | |
void rutaJson() | |
{ | |
// Calcular última lectura exitosa en segundos | |
unsigned long tiempoTranscurridoEnMilisegundos = millis() - ultimaLecturaExitosa; | |
int tiempoTranscurrido = tiempoTranscurridoEnMilisegundos / 1000; | |
// Búfer para escribir datos en JSON | |
char bufer[50]; | |
// Crear la respuesta pasando las variables globales | |
// La salida será algo como: | |
// {"t":14.20,"h":79.20,"l":5.00} | |
sprintf(bufer, "{\"t\":%.2f,\"h\":%.2f,\"u\":%d}", temperatura, humedad, tiempoTranscurrido); | |
// Responder con ese JSON | |
servidor.send(200, "application/json", bufer); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment