From 743ac56d3a8f6ec9e55a399d63ffeb1ec07214dd Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 30 Aug 2023 23:34:33 +0100 Subject: [PATCH] Improve recovery after NFC comms failure --- main.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 114366e..68a939c 100644 --- a/main.py +++ b/main.py @@ -124,14 +124,20 @@ def reader_thread(card_data_queue): with open(TEST_PIPE, 'r') as pipe: success, card = (True, pipe.readline()) else: + nfc.SAMConfig() success, card = nfc.readPassiveTargetID(pn532.PN532_MIFARE_ISO14443A_106KBPS) - try: - # ensure we have communication with the reader - if nfc.getFirmwareVersion(): - feed_watchdog() - except: - continue + if not TEST: + try: + # ensure we have communication with the reader + if nfc.getFirmwareVersion(): + feed_watchdog() + else: + raise + except: + logging.error('Problem communicating with NFC reader!') + time.sleep(1) + continue try: card = binascii.hexlify(card).decode().strip()