import network
from machine import ADC, Pin
import time
from time import sleep
from machine import Pin
import dht
import ujson
from umqtt.simple import MQTTClient
import _thread
import time
import machine
# my leds
coldLed = Pin(13, machine.Pin.OUT)
bomba = Pin(12, machine.Pin.OUT)
warmLed = Pin(14, machine.Pin.OUT)
# turn off/on leds
def turnOnLed(led):
coldLed.off()
bomba.off()
warmLed.off()
led.on()
# callback for the messages from mqtt broker
sensor = dht.DHT22(Pin(15))
lastMessage = None
while True:
sensor.measure()
message = ujson.dumps({
"temp": sensor.temperature(),
"humidity": sensor.humidity(),
})
if (lastMessage != sensor.temperature()):
lastMessage = sensor.temperature()
if(sensor.temperature() > 41):
turnOnLed(warmLed)
print("PELIGRO EN EL INVERNADERO",warmLed)
elif(sensor.temperature() > 15 and sensor.temperature() < 40):
turnOnLed(bomba)
print("RIEGO ACTIVADO",bomba)
elif(sensor.temperature() < 15):
turnOnLed(coldLed)
print("RIEGO DESACTIVADO", coldLed)
time.sleep(1)