Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 26, 2020 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/b50c12b9b67ac53c8a108b2465cbfca3 to your computer and use it in GitHub Desktop.
Save parzibyte/b50c12b9b67ac53c8a108b2465cbfca3 to your computer and use it in GitHub Desktop.
// 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