Search code examples
pythonnfc

Control the sound of an NFC reader


I am using pynfc to read in NFC tags. I have an ACR 122U USB NFC reader/writes unit. This unit is capable to make a sound when it reads in a tag, however i was unable to find anything in the pynfc docs about controlling it. Is there a way with either pynfc, or some other python, or linux OS to invoke the sound of an NFC reader?


Solution

  • For nfcpy i found out that if the on-connect function returns True the buzzer and the light will go off if the reader is capable.

    #!/usr/bin/python
    import nfc
    import time
    import datetime
    
    def on_connect(tag):
        print('Last read: {}'.format(datetime.datetime.now()))
        return True
    
    while True:
        with nfc.ContactlessFrontend('usb') as clf:
            clf.connect(rdwr={'on-connect': on_connect, 'beep-on-connect': True})
        time.sleep(1)