import network, time
from machine import Pin
from utelegram import Bot
from dht import DHT22
Token= '6237109625:AAHOJ79k-NrRgVKtUhqUC5FS3vucEiveelc'
bot=Bot(Token)
led=Pin(2, Pin.OUT)
sensor_DHT = DHT22(Pin(15))
def connect(red, password):
global miRed
miRed=network.WLAN(network.STA_IF)
if not miRed.isconnected():
miRed.active(True)
miRed.connect(red, password)
print('connecting to', red +'...')
timeout=time.time()
while not miRed.isconnected():
if (time.ticks_diff (time.time (), timeout)>10):
return False
return True
if connect("Wokwi-GUEST", ""):
print("conexion exitosa")
print('network config:', miRed.ifconfig())
@bot.add_message_handler('Hola')
def help(update):
update.reply('Hola cómo estás?')
@bot.add_message_handler('Temp')
def sensor(update):
sensor_DHT.measure()
temp = sensor_DHT.temperature()
update.reply('La temperatura de la habitacion es: ' + str(temp))
@bot.add_message_handler('1')
def encender(update):
led.value(1)
update.reply('Encendido')
@bot.add_message_handler('0')
def apagar(update):
led.value(0)
update.reply('Led apagado')
bot.start_loop()
else:
print("Imposible conectar")
miRed.active(False)