Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More reliable

  • Loading branch information...
commit 3084b303e1e4056f70deafb37a69f632227f83ca 1 parent d05e45c
@dustball dustball authored
Showing with 43 additions and 29 deletions.
  1. +23 −10 serialController.py
  2. +20 −19 updater.py
View
33 serialController.py
@@ -3,17 +3,20 @@
import urllib
import json
import sys
+import os
-relayfile = serial.Serial('/dev/cuau0', baudrate=9600)
-print "\nHacker Dojo RFID Entry System v0.2\n"
-
+serialport = '/dev/cuau0'
+relayfile = None
+
def relayOn():
- print '[RELAY] On'
- relayfile.setDTR(True)
+ print '[RELAYON] The door is now locked'
+ if relayfile:
+ relayfile.setDTR(True)
def relayOff():
- print '[RELAY] Off'
- relayfile.setDTR(False)
+ print '[RELAYOFF] The door is now unlocked'
+ if relayfile:
+ relayfile.setDTR(False)
def getUsers():
try:
@@ -36,7 +39,17 @@ def fatal(msg,err):
print "[ERROR] " + str(err)
sys.exit(0)
-while True:
+def main():
+ print "\nHacker Dojo RFID Entry System v0.2\n"
+ if os.path.exists(serialport):
+ relayfile = serial.Serial(serialport, baudrate=9600)
+ else:
+ print "WARNING: Serial port not found! Program will operate in 'pretend' mode.\n"
+ relayOn() # Lock the door to start ;)
+ while True:
+ scanLoop()
+
+def scanLoop():
key = raw_input('RFID> ').strip()
if key in ["exit","exit()","quit","quit()"]:
print "[EXIT] Exiting"
@@ -44,7 +57,7 @@ def fatal(msg,err):
if key:
print "[DEBUG] I just scanned " + key
userData = getUsers()
- print "[DEBUG] Comparing to " + str(len(userData)) + " RFIDs"
+ print "[DEBUG] Comparing to " + str(len(userData)) + " RFIDs..."
foundUser = None
for user in userData:
if key == user['rfid_tag']:
@@ -58,4 +71,4 @@ def fatal(msg,err):
else:
print '[NOTFOUND] Sorry, RFID key not found'
-
+main()
View
39 updater.py
@@ -10,23 +10,24 @@ def fatal(msg,err):
print "[ERROR] " + str(err)
sys.exit(0)
-try:
- userURL = urllib.urlopen('http://signup.hackerdojo.com/api/rfid')
- data = userURL.read()
- userURL.close()
-except:
- fatal("Unable to connect to server",sys.exc_info()[0])
-try:
- userData = json.loads(data)
-except:
- fatal("Unable to parse JSON",sys.exc_info()[0])
-if len(userData) < 1:
- fatal("Number of RFID tags too small")
-
-try:
- FILE = open("/tmp/rfid","w")
- FILE.writelines(data)
- FILE.close()
-except:
- fatal("Unable to write RFID data",sys.exc_info()[0])
+def main():
+ try:
+ userURL = urllib.urlopen('http://signup.hackerdojo.com/api/rfid')
+ data = userURL.read()
+ userURL.close()
+ except:
+ fatal("Unable to connect to server",sys.exc_info()[0])
+ try:
+ userData = json.loads(data)
+ except:
+ fatal("Unable to parse JSON",sys.exc_info()[0])
+ if len(userData) < 1:
+ fatal("Number of RFID tags too small")
+ try:
+ FILE = open("/tmp/rfid","w")
+ FILE.writelines(data)
+ FILE.close()
+ except:
+ fatal("Unable to write RFID data",sys.exc_info()[0])
+main()
Please sign in to comment.
Something went wrong with that request. Please try again.