Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import time
- import serial
- import smtplib
- import subprocess
- from array import array
- from time import sleep
- TO = 'you@host.tld'
- GMAIL_USER = 'MAKEME'
- GMAIL_PASS = 'SETME'
- SUBJECT = 'Intrusion!!'
- TEXT = 'Your PIR sensor detected movement'
- ser = serial.Serial('/dev/rfcomm0', 9600)
- ledctrlpath = '/usr/local/bin/ledwifi'
- ledip = '192.168.0.200:5577'
- def send_email():
- print("Sending Email")
- smtpserver = smtplib.SMTP("smtp.gmail.com",587)
- smtpserver.ehlo()
- smtpserver.starttls()
- smtpserver.ehlo
- smtpserver.login(GMAIL_USER, GMAIL_PASS)
- header = 'To:' + TO + '\n' + 'From: ' + GMAIL_USER
- header = header + '\n' + 'Subject:' + SUBJECT + '\n'
- print header
- msg = header + '\n' + TEXT + ' \n\n'
- smtpserver.sendmail(GMAIL_USER, TO, msg)
- smtpserver.close()
- while True:
- message = ser.readline()
- print(message)
- if message[0] == 'M' :
- send_email()
- # get and save current color
- currentcolor = subprocess.check_output([ledctrlpath,'local','--host=' + ledip,'get-state']).split('\n')[5].split(' ')[1]
- # blank
- subprocess.call([ledctrlpath,'local','--host=' + ledip,'set-color','#000000'])
- sleep(.2)
- #flash light quickly times
- for i in range(4):
- subprocess.call([ledctrlpath,'local','--host=' + ledip,'set-color','#ff0000'])
- sleep(.2)
- subprocess.call([ledctrlpath,'local','--host=' + ledip,'set-color','#000000'])
- sleep(.2)
- # set color back to what it was before alert
- subprocess.call([ledctrlpath,'local','--host=' + ledip,'set-color',currentcolor])
- time.sleep(10)
- ser.readline()
- # the software is...
- #pi@tumor:~ $ ledwifi
- #zengge-lightcontrol is a command line tool for controlling zengge lights
- #Usage:
- # zengge-lightcontrol [command]
- #Available Commands:
- # local local commands
- # manage management commands
- # remote remote commands
- #Flags:
- # -h, --help[=false]: help for zengge-lightcontrol
- #Use "zengge-lightcontrol [command] --help" for more information about a command.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement