Escolar Documentos
Profissional Documentos
Cultura Documentos
This is the only interface with the NFC reader, as it can only be accessed by on
e process at a time
It:
* reads config/data.json for exsting mappings between uids and feedUrls
- if it finds a match with the current uid
- it sends a command to the server to tell it that the card for a feedUrl is p
resent
* it also saves its state continuously for other apps to read.
It assumes client-huffduffer is present (i.e. the server it sends information to
)
It triggers the POST to the server as long as the card ahs changed or been remov
ed
since it was seen last.
'''
import nxppy
import sys
import requests
import os
import json
from pprint import pprint
# this script's directory
dn = os.path.dirname(os.path.realpath(__file__))
reader = nxppy.Mifare()
print "Loaded mifare device"
currentId = None
url = ""
uid = ""
# loop forever
while True:
try:
# read the card uid
uid = reader.select()
#print "currentid is "
#print currentId
#print "uid is "
#print uid
# we don't want to read it if we've just seen it
if(uid is not None and currentId!=uid):
currentId = uid
url = None
payload = None
print "New card ID:" +currentId
# data file mapping uids and RSS feed urls. Read-only from this python scr
ipt
print "opening nfc config file "+dn+"/config/data.json"
json_data=open(dn+"/config/data.json")
data = json.load(json_data)
print data
json_data.close()
for d in data:
id = d
url = data[d]