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 <Anna.Schumaker@Netapp.com>
This commit is contained in:
Anna Schumaker 2015-04-07 14:23:15 -04:00
parent c318e74ea0
commit 27fdb0fd9c
2 changed files with 47 additions and 22 deletions

14
doorrc Normal file
View File

@ -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

View File

@ -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)