Created
February 19, 2020 00:14
-
-
Save parzibyte/1039cdd23e55fd7de77657e7a070b274 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
// Si han pasado más de 2 segundos desde la última vez, enviar un mensaje | |
if (millis() - ultimaVez > TIEMPO_ESPERA) | |
{ | |
humedad = sensor.readHumidity(); | |
temperaturaEnGradosCelsius = sensor.readTemperature(); | |
// En ocasiones puede devolver datos erróneos; por eso lo comprobamos | |
if (isnan(temperaturaEnGradosCelsius) || isnan(humedad)) | |
{ | |
ultimaVez = millis(); | |
return; | |
} | |
// Formatear la temperatura y humedad | |
sprintf(mensaje, "Temperatura: %.2f. Humedad: %.2f", temperaturaEnGradosCelsius, humedad); | |
clienteMqtt.publish("jardin/temperatura", mensaje); | |
ultimaVez = millis(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment