SHARE
TWEET

Check door opening with Raspberry

TringaliLuca Apr 21st, 2017 (edited) 559 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Run this code with python2.7
  5. #
  6. #if you need to configure postfix, please use https://easyengine.io/tutorials/linux/ubuntu-postfix-gmail-smtp/
  7.  
  8. import os
  9. import sys
  10. import RPi.GPIO as GPIO
  11.  
  12. button = 17 #GPIO pin where we put the button, dry reed switch, or anything another sensor for door opening
  13. active = 1 #if set to 0 the daemon will stop
  14. email = "user@gmail.com" #your email address
  15.  
  16. def my_callback(pin):
  17.     input_value = GPIO.input(pin)
  18.     print "The GPIO pin input "+str(pin)+" changed value: "+str(input_value)
  19.     os.system('echo "Door opened" | mail -s "alarm" '+email)
  20.  
  21.  
  22. os.system('modprobe w1-gpio')
  23.  
  24. GPIO.setmode(GPIO.BCM)
  25. GPIO.setwarnings(False)
  26.  
  27. GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
  28. GPIO.add_event_detect(button, GPIO.BOTH)
  29. GPIO.add_event_callback(button, my_callback)
  30.  
  31. while active:
  32.     time.sleep(10)
  33. print "Exiting"
  34. sys.exit()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top