"""
MicroPython IoT Weather Station Example for Wokwi.com
To view the data:
1. Go to http://www.hivemq.com/demos/websocket-client/
2. Click "Connect"
3. Under Subscriptions, click "Add New Topic Subscription"
4. In the Topic field, type "wokwi-weather" then click "Subscribe"
Now click on the DHT22 sensor in the simulation,
change the temperature/humidity, and you should see
the message appear on the MQTT Broker, in the "Messages" pane.
Copyright (C) 2022, Uri Shaked
https://wokwi.com/arduino/projects/322577683855704658
"""
import time #importa la libreria time que permite obtener el tiempo actual, medir tiempo y generar delays https://docs.micropython.org/en/latest/library/time.html
from machine import Pin #importa la libreria machine para emplear funciones especificas del hardware de una tarjeta, de esta libreria se importa solo la clase Pin para control del I/O de la tarjeta https://docs.micropython.org/en/latest/library/machine.html#
import dht #importa la libreria dht la cual es un driver de software para el sensor DHT one-wire facilitando la lectura de este https://docs.micropython.org/en/latest/esp32/quickref.html#dht-driver
sensor = dht.DHT22(Pin(16)) #define el pin fisico 15 para la conexion de la señal entre el sensor y la tarjeta
green_led = Pin(26, Pin.OUT)
But = Pin(25,Pin.IN)
while True: #Inicia un bucle
print("Measuring weather conditions... ", end="") #Imprime el texto para indicar que esta midiendo condiciones
sensor.measure() #realiza la lectura del sensor
print(sensor.temperature()) #asigna el nombre "temp" dentro de la estructura y le asocia el valor de temperatura leido
print(sensor.humidity()) #asigna el nombre "humidity" dentro de la estructura y le asocia el valor de la humedad leida
green_led.value(But.value())
time.sleep(1) #agrega un delay de 1