Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # Run this code with python2.7
- #
- #if you need to configure postfix, please use https://easyengine.io/tutorials/linux/ubuntu-postfix-gmail-smtp/
- import os
- import sys
- import RPi.GPIO as GPIO
- button = 17 #GPIO pin where we put the button, dry reed switch, or anything another sensor for door opening
- active = 1 #if set to 0 the daemon will stop
- email = "user@gmail.com" #your email address
- def my_callback(pin):
- input_value = GPIO.input(pin)
- print "The GPIO pin input "+str(pin)+" changed value: "+str(input_value)
- os.system('echo "Door opened" | mail -s "alarm" '+email)
- os.system('modprobe w1-gpio')
- GPIO.setmode(GPIO.BCM)
- GPIO.setwarnings(False)
- GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
- GPIO.add_event_detect(button, GPIO.BOTH)
- GPIO.add_event_callback(button, my_callback)
- while active:
- time.sleep(10)
- print "Exiting"
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement