try:
client = conectar_y_suscribir()
except OSError as e:
reiniciar_y_reconectar()
while True:
try:
client.check_msg()
sensor.measure()
temperatura = sensor.temperature()
hum = sensor.humidity()
sleep_ms(100)
if temperatura > 25 and temperatura < 27:
aceptable.on()
moderado.off()
alto.off()
muy_alto.off()
if temperatura > 27 and temperatura < 29:
aceptable.off()
moderado.on()
alto.off()
muy_alto.off()
if temperatura > 29 and temperatura < 31:
aceptable.off()
moderado.off()
alto.on()
muy_alto.off()
if temperatura > 31:
aceptable.off()
moderado.off()
alto.off()
muy_alto.on()
if boton.value() == 0:
client.publish(topic_pub2, '26')
if temperatura != temp_prev or hum != hum_prev:
valores = ujson.dumps({
'temperatura': temperatura,
'humedad': hum,
})
client.publish(topic_pub, valores)
temp_prev = temperatura
hum_prev = hum
sleep_ms(125)
except OSError as e:
reiniciar_y_reconectar()