import network,time,urequests
from machine import Pin
from utelegram import Bot
import Token
TOKEN= Token.token
bot = Bot(TOKEN)
sensor = Pin(21,Pin.IN,Pin.PULL_DOWN)
rele = Pin(22,Pin.OUT)
def conectarWiFi(red,password):
global miRed
miRed = network.WLAN(network.STA_IF)
if not miRed.isconnected():
miRed.active(True)
miRed.connect(red,password)
print('Conectandose ',red+" ...")
timeout= time.time()
while not miRed.isconnected():
if(time.ticks_diff(time.time(),timeout)>10):
return False
return True
if conectarWiFi("Wokwi-GUEST",""):
print("conexión exitosa :D")
print("Datos de la Red: (IP/netmask/DNS): ",miRed.ifconfig())
print("Conectado")
@bot.add_message_handler("Menu")
def help(update):
update.reply("Activar Sistema: ON, Desactivar sistema: OFF")
print("Activar Sistema: ON | Desactivar sistema: OFF")
@bot.add_message_handler("ON")
def help(update):
update.reply("Activado")
print("Activado|Wokwi")
medicion = sensor.value()
if medicion == 0:
rele.value(1)
update.reply("Ingresando a casa")
print("Alerta, intruso")
else:
rele.value(0)
update.reply("Nadie entra a la V. Cueva")
@bot.add_message_handler("OFF")
def help(update):
rele.value(0)
update.reply("Desactivado")
print("Desactivado|Wokwi")
bot.start_loop()
else:
print("Imposible conectar con la API")
miRed.active(False)