cool
commit
f4ae4e7a74
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: ascii -*-
|
||||
from time import sleep
|
||||
import os
|
||||
import pifacedigitalio as p
|
||||
p.init ()
|
||||
DELAY = 30.0 # seconds
|
||||
while True:
|
||||
x = p.digital_read(0)
|
||||
if x == 1:
|
||||
os.system("echo \"La alarma se ha ejecutado, compruebe si es real \"|mutt -s \"Alarma lanzada\" aip@gmail.com")
|
||||
p.digital_write(0, 1)
|
||||
sleep (DELAY)
|
|
@ -0,0 +1,56 @@
|
|||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
import smtplib
|
||||
|
||||
pir_sensor = 11
|
||||
piezo = 7
|
||||
|
||||
|
||||
GPIO.setmode(GPIO.BOARD)
|
||||
|
||||
GPIO.setup(piezo,GPIO.OUT)
|
||||
|
||||
GPIO.setup(pir_sensor, GPIO.IN)
|
||||
|
||||
current_state = 0
|
||||
try:
|
||||
while True:
|
||||
time.sleep(0.1)
|
||||
current_state = GPIO.input(pir_sensor)
|
||||
if current_state == 1:
|
||||
|
||||
print("GPIO pin %s is %s" % (pir_sensor, current_state))
|
||||
GPIO.output(piezo,True)
|
||||
time.sleep(1)
|
||||
GPIO.output(piezo,False)
|
||||
FROM = "aip@gmail.com"
|
||||
|
||||
#Lista de correos a enviar ...
|
||||
TO = ['aip@gmail.com','aip2@gmail.com']
|
||||
|
||||
TOstr = 'aip@gmail.com'
|
||||
|
||||
|
||||
server = smtplib.SMTP('smtp.gmail.com',587)
|
||||
server.ehlo()
|
||||
server.starttls()
|
||||
server.ehlo
|
||||
|
||||
|
||||
server.login(FROM,'aip@gmail.com')
|
||||
|
||||
|
||||
header = 'To:' + TOstr + '\n' + 'From: ' + FROM + '\n' + 'Subject:Alarma en casa \n'
|
||||
print header
|
||||
msg = header + '\n ALARMA EN CASA\n'
|
||||
|
||||
|
||||
server.sendmail(FROM,TO,msg)
|
||||
print "Listo !"
|
||||
server.quit()
|
||||
|
||||
time.sleep(5)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
GPIO.cleanup()
|
Loading…
Reference in New Issue