I have the following python code which continuously listens for NFC tag presence and when detected it prints the UID (ident)
from nfc import ContactlessFrontend
from time import sleep
def connected(tag):
ident = ''.join('{:02x}'.format(ord(c)) for c in tag.identifier)
print(ident)
return False
clf = ContactlessFrontend('usb')
while True:
clf.connect(rdwr={'on-connect': connected})
sleep(1)
This works well. However, the problem I face is that if a user holds the NFC tag down then the script reads the same “ident” value over and over again. I want to solve this by possibly temporarily storing the value of “ident” so that it doesn’t print if the value is the same as last scanned for at least X seconds before it is allowed to re-print the same UID (almost like a timeout). Can someone kindly help me modify the code above to do this please?
Thank you.