import network, time, urequests
from machine import Pin
from utime import sleep, sleep_ms
from dht import DHT22
import ujson
from utelegram import Bot
sensor_dht = DHT22(Pin(15))
rele= Pin (12,Pin.OUT)
TOKEN = "6397674039:AAGXeRQZLM6zBU8wahrrd9A5OIGrUuqL8I4"
bot = Bot (TOKEN)
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 ("Conexión exitosa!")
print('Datos de la red (IP/netmask/gw/DNS):', miRed.ifconfig())
@bot.add_message_handler("holy")
def help (update):
update.reply('''Menu:
\n Encender led :On \U0001F600
\n Apagar led : Off
\n Estado del led : Estado
\n Temperatura : Tem
\n No olvides que estoy para tu seguridad y confort
\n Gracias \U0001F600
\n Ver en línea tu DashBoard:
\n No olvides que estoy para tu seguridad y confort
\n Gracias \U0001F600
\n Ver en línea tu DashBoard:
\n https://thingspeak.com/channels/1807893
''')
@bot.add_message_handler("on")
def help (update):
rele.on()
update.reply("encendido")
@bot.add_message_handler("off")
def help (update):
rele.off()
update.reply("apagado")
@bot.add_message_handler("estado")
def help (update):
lectura=rele.value()
if lectura==0:
update.reply("el rele esta apagado")
else:
update.reply("el rele esta encendido")
@bot.add_message_handler("Tem")
def help (update):
sensor_dht.measure()
temperatura = sensor_dht.temperature()
update.reply("la temperatura es: " + str(temperatura))
bot.start_loop()
#while True:
#sensor_dht.measure()
#temperatura = sensor_dht.temperature()
#humedad = sensor_dht.humidity()
#print ("T: {} C H:{} %".format(temperatura,humedad))
#sleep_ms(50)
#rele.on()
#sleep(0.5)
#rele.off()
#sleep(0.5)
else:
print ("Pailis de conectar")
miRed.active (False)