Hardware Reference
In-Depth Information
Using the RFID Reader in Python
You will need to write a new input block and an authentication block for the RFID tag reader.
The RFID Input Block
As the RFID reader inputs data from tags as if it had been typed on a keyboard, you will use
the raw_input function in Python. Add the following code (before the main function) to
get input from the RFID reader to your door_controller.py program:
class RfidInput:
def getInput(self):
print “waiting for tag”
tag = raw_input()
return AuthToken(None,tag)
The RFID Authentication Block
he RFID authentication block looks up the value from the tag to see if it is valid. It does this
by checking if it is in the tags.txt ile you created earlier. Add the following code to the
door_controller.py program so that you can check if the value read from the tag is
valid:
class RfidFileAuthenticator:
filename = “tags.txt”
tags = dict()
def __init__(self):
self.readFile()
def readFile(self):
secrets = open(self.filename, 'r')
print “reading from “ + self.filename + “ file”
for line in secrets:
line = line.rstrip('\n')
id, tag = line.split(',')
self.tags[tag] = id
def check(self,token):
print “checking if “ + token.secret + “ is valid”
if token.secret in self.tags:
print “tag found belonging to: “ + ;
self.tags[token.secret]
return True
else: “tag not found”
print
return False
Search WWH ::




Custom Search