From 27fdb0fd9cc285950dd01e9a8ec1db3a38f0192a Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 7 Apr 2015 14:23:15 -0400 Subject: [PATCH] Create a doorrc file This file contains configuration data for the door controllers that way the script doesn't need to be changed on every new device. Signed-off-by: Anna Schumaker --- doorrc | 14 ++++++++++++++ doors.py | 55 +++++++++++++++++++++++++++++++++---------------------- 2 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 doorrc diff --git a/doorrc b/doorrc new file mode 100644 index 0000000..f79e8b0 --- /dev/null +++ b/doorrc @@ -0,0 +1,14 @@ + +# Name of this Raspberry Pi unit +CONTROLLER="deadbeef01" + +# Server to send requests to +SERVER = "http://openings.workantile.com/access/" + CONTROLLER + +# Set path to RFID reader +RFID_PATH = "/dev/ttyUSB0" + +# Set Raspberry Pi GPIO pin numbers +RED_LED = 11 +GREEN_LED = 13 +DOOR_STRIKE = 15 diff --git a/doors.py b/doors.py index 72005d4..36686e5 100644 --- a/doors.py +++ b/doors.py @@ -1,27 +1,44 @@ #!/usr/bin/python -#################### -# # -# Define GPIO Pins # -# # -#################### +import socket +################## +# # +# Default values # +# # +################## + +CONTROLLER = socket.gethostname() +SERVER = "localhost" +RFID_PATH = "/dev/ttyUSB0" RED_LED = 11 GREEN_LED = 13 DOOR_STRIKE = 15 +import os +#################### +# # +# Read doorrc file # +# # +#################### + +for conf in [ "/etc/doorrc", "./doorrc" ]: + if os.path.exists(conf): + with open(conf) as f: + exec(compile(f.read(), "doorrc", 'exec')) + + + +import atexit +import RPi.GPIO as GPIO #################### # # # Set up GPIO Pins # # # #################### -import atexit -import RPi.GPIO as GPIO -import time - GPIO.setmode(GPIO.BOARD) atexit.register(GPIO.cleanup) @@ -53,36 +70,30 @@ def close_door(): +import time +#python-pyserial package. Not sure we need this. Grabbed based on +#http://allenmlabs.blogspot.se/2013/01/raspberry-pi-parallax-rfid-reader.html +import serial ###################### # # # Set up RFID Reader # # # ###################### -#python-pyserial package. Not sure we need this. Grabbed based on -#http://allenmlabs.blogspot.se/2013/01/raspberry-pi-parallax-rfid-reader.html -import serial -#Find the RFID as a USB device -#TODO: script should find it if not at USB0 -RFID_SERIAL = serial.Serial('/dev/ttyUSB0', 2400, timeout=1) +RFID_SERIAL = serial.Serial(RFID_PATH, 2400, timeout=1) +from urllib import request ############################################# # # # Verify a key with openings.workantile.com # # # ############################################# -from urllib import request - -# Which door controller are we? -CONTROLLER="deadbeef01" - - # Blocks for 5 seconds before resetting the door def verify_key(key): - url = "http://openings.workantile.com/access/%s/%s" % (CONTROLLER, key) + url = SERVER + ("/%s" % key) if request.urlopen(url).read().decode() == "OK": open_door() time.sleep(5)