import network, time
from machine import Pin
from utime import sleep, sleep_ms, ticks_us
import ujson
from dht import DHT22
sensor_dht = DHT22(Pin(32))
#
def conectaWifi (red, password):
global miRed
miRed = network.WLAN(network.STA_IF)
if not miRed.isconnected(): #Si no está conectado…
miRed.active(True) #activa la interface
miRed.connect(red, password) #Intenta conectar con la red
print('Conectando a la red', red +"…")
timeout = time.time ()
while not miRed.isconnected(): #Mientras no se conecte..
if (time.ticks_diff (time.time (), timeout) > 10):
return False
return True
#
if conectaWifi("Wokwi-GUEST", ""):
#
print("Conexion exitosa")
print('Datos e la red IP/network/gw/DNS):',miRed.ifconfig())
#
while True:
sensor_dht.measure()
tem = sensor_dht.temperature()
hum = sensor_dht.humidity()
print("Tem: {}°c, Hum:{}%".format(tem, hum))
sleep_ms(50)
#
else:
print("Imposible Conectar")
miRed.active(False)