from machine import Pin
from time import sleep
import dht
import network
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected():
print('connecting to network...')
sta_if.active(True)
sta_if.connect('Wokwi-GUEST', "")
while not sta_if.isconnected():
pass
print('network config:', sta_if.ifconfig())
sensor = dht.DHT22(Pin(15))
while True:
try:
sleep(2)
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
print('Temperature: %3.1f C' % temp)
print('Humidity: %3.1f %%' % hum)
# Condiciones de calidad del aire
if temp > 25.0 and hum > 70.0:
print("La calidad del aire puede ser mala (temperatura y humedad elevadas).")
elif temp < 20.0 and hum < 30.0:
print("La calidad del aire puede ser mala (baja temperatura y humedad).")
else:
print("La calidad del aire parece normal.")
except OSError as e:
print('Failed to read sensor.')