From b1c569e86f79cfc29932d492b5cf2635e89a28a5 Mon Sep 17 00:00:00 2001 From: Ondrej Mikle Date: Sun, 20 Jul 2014 21:44:51 +0200 Subject: [PATCH] Added timeouts so that reader doesn't bombard with UIDs. Changed queue length to 1 to make it block. --- brmdoor_nfc_daemon.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/brmdoor_nfc_daemon.py b/brmdoor_nfc_daemon.py index 8b9a2db..a6a5e33 100644 --- a/brmdoor_nfc_daemon.py +++ b/brmdoor_nfc_daemon.py @@ -4,6 +4,7 @@ import sys import threading import Queue import logging +import time from binascii import hexlify @@ -31,9 +32,11 @@ class NfcThread(threading.Thread): try: uid_hex = hexlify(self.nfc.scanUID()) logging.info("Got UID %s" % uid_hex) - self.uidQueue.put(uid_hex) + if len(uid_hex) > 0: + self.uidQueue.put(uid_hex) + time.sleep(0.3) except NFCError, e: - logging.warn("Failed to wait for RFID card", e) + logging.warn("Failed to wait for RFID card: %s", e) class UnlockThread(threading.Thread): @@ -61,14 +64,16 @@ class UnlockThread(threading.Thread): if record is None: logging.info("Unknown UID %s", uid_hex) + time.sleep(1) else: logging.info("Unlocking for %s", record) + time.sleep(1) if __name__ == "__main__": logging.basicConfig(stream=sys.stderr, level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s [%(pathname)s:%(lineno)d]") - uidQueue = Queue.Queue(512) + uidQueue = Queue.Queue(1) #TODO use SafeConfigParser to get actual config data nfcThread = NfcThread(uidQueue)