Académique Documents
Professionnel Documents
Culture Documents
Taller Autonomo
WEB/RASPBERRY PI
OBJETIVOS:
Página Web
11. Damos click, en “Finish” y con esto concluimos los pasos para elaborar la
Primera condición.
12. Repetir los pasos anteriores para realizar la Segunda condición. Debe quedar
una ventana similar.
FIEC – ESPOL Laboratorio de Microcontroladores
Raspberry Pi
Código Emisor
def main():
GPIO.setmode(GPIO.BCM)
GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
api = ApiClient(token='X7tFdsHBTmUdkST19ysqm5caKKfiSf')#codigo de
"Default Token"
variable = api.get_variable('5a4f05fec03f97681783d7ef')#ID Sensor 1
while True:
if GPIO.input(20):#Al presionar un boton envio el valor 60 que activara la
señal Alarma
response = variable.save_value({"value": 60})
print ("Boton presionado")
sleep(10)
FIEC – ESPOL Laboratorio de Microcontroladores
else:
num = random.randint(0, 100)#Funcion para crear un numero aleatorio
entre 0 y 100 que simulara los datos que envie un "x" sensor
response = variable.save_value({"value": num})
print (num)
sleep(3)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
GPIO.cleanup()
Código Receptor
def main():
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.OUT)
api = ApiClient(token='X7tFdsHBTmUdkST19ysqm5caKKfiSf')#codigo de
"Default Token"
variable = api.get_variable("5a4f1171c03f97735b6a3ecf")#ID Alarma
leido = False
while True:
last_value = variable.get_values(1)[0]['value']
if not (leido) and last_value==1:
print "ALERTA"
GPIO.output(21, 1)#Se encendera un led cuando se active la alarma
os.system("sudo fswebcam
./"+time.strftime('%d%b%y%H%M%S')+".jpg")#Se tomara una foto cuando se
active la alarma
leido = True
time.sleep(5)
elif last_value==0:
GPIO.output(21, 0)
leido = False
time.sleep(1)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
GPIO.cleanup()