Guest User

PIR motion and led RGB strip

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