"""
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 all what u need
import network
import time
from machine import Pin
import dht
import ujson
from umqtt.simple import MQTTClient
import machine
import time
# port mte3 Photorésistance
ldr_pin = machine.Pin(34, machine.Pin.IN, machine.Pin.PULL_DOWN)
adc = machine.ADC(ldr_pin)
# port mte3 dht22
sensor = dht.DHT22(Pin(15))
led_pin1 = machine.Pin(33, machine.Pin.OUT)
led_pin2 = machine.Pin(26, machine.Pin.OUT)
while True:
# affiche data de Photorésistance
ldr_value = adc.read()
print("LDR Value:", ldr_value)
# affiche le value de temp et humidity
sensor.measure()
temperature = [sensor.temperature(),sensor.humidity()]
print(f"temp : {temperature[0]} and humidity : {temperature[1]}")
if temperature[0] > 24 :
led_pin1.on()
else :
led_pin1.off()
if temperature[0] < 0 :
led_pin2.on()
else:
led_pin2.off()
time.sleep(1)