Advertisement
Guest User

PIR motion and led RGB strip

a guest
May 16th, 2018
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.25 KB | None | 0 0
  1.   #!/usr/bin/python
  2.   import time
  3.   import serial
  4.   import smtplib
  5.   import subprocess
  6.   from array import array
  7.   from time import sleep
  8.  
  9.   TO = 'you@host.tld'
  10.   GMAIL_USER = 'MAKEME'
  11.   GMAIL_PASS = 'SETME'
  12.  
  13.   SUBJECT = 'Intrusion!!'
  14.   TEXT = 'Your PIR sensor detected movement'
  15.  
  16.   ser = serial.Serial('/dev/rfcomm0', 9600)
  17.  
  18.   ledctrlpath = '/usr/local/bin/ledwifi'
  19.   ledip = '192.168.0.200:5577'
  20.  
  21.   def send_email():
  22.       print("Sending Email")
  23.       smtpserver = smtplib.SMTP("smtp.gmail.com",587)
  24.       smtpserver.ehlo()
  25.       smtpserver.starttls()
  26.       smtpserver.ehlo
  27.       smtpserver.login(GMAIL_USER, GMAIL_PASS)
  28.       header = 'To:' + TO + '\n' + 'From: ' + GMAIL_USER
  29.       header = header + '\n' + 'Subject:' + SUBJECT + '\n'
  30.       print header
  31.       msg = header + '\n' + TEXT + ' \n\n'
  32.       smtpserver.sendmail(GMAIL_USER, TO, msg)
  33.       smtpserver.close()
  34.  
  35.   while True:
  36.       message = ser.readline()
  37.       print(message)
  38.       if message[0] == 'M' :
  39.           send_email()
  40.  
  41.           # get and save current color
  42.           currentcolor = subprocess.check_output([ledctrlpath,'local','--host=' + ledip,'get-state']).split('\n')[5].split(' ')[1]
  43.  
  44.  
  45.           # blank
  46.           subprocess.call([ledctrlpath,'local','--host=' + ledip,'set-color','#000000'])
  47.           sleep(.2)
  48.  
  49.  
  50.           #flash light quickly  times
  51.           for i in range(4):
  52.               subprocess.call([ledctrlpath,'local','--host=' + ledip,'set-color','#ff0000'])
  53.               sleep(.2)
  54.               subprocess.call([ledctrlpath,'local','--host=' + ledip,'set-color','#000000'])
  55.               sleep(.2)
  56.  
  57.  
  58.           # set color back to what it was before alert
  59.           subprocess.call([ledctrlpath,'local','--host=' + ledip,'set-color',currentcolor])
  60.  
  61.  
  62.       time.sleep(10)
  63.       ser.readline()
  64.  
  65. # the software is...
  66. #pi@tumor:~ $ ledwifi
  67. #zengge-lightcontrol is a command line tool for controlling zengge lights
  68.  
  69. #Usage:
  70. #  zengge-lightcontrol [command]
  71.  
  72. #Available Commands:
  73. #  local       local commands
  74. #  manage      management commands
  75. #  remote      remote commands
  76.  
  77. #Flags:
  78. #  -h, --help[=false]: help for zengge-lightcontrol
  79.  
  80. #Use "zengge-lightcontrol [command] --help" for more information about a command.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement