pi-rfid-jukebox/bin/tag-reader

30 lines
528 B
Plaintext

from pirc522 import RFID
import RPi.GPIO as GPIO
import sys
import signal
GPIO.setwarnings(False)
rdr = RFID()
def sigint_handler(signal, frame):
rdr.cleanup()
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
signal.signal(signal.SIGTERM, sigint_handler)
while True:
rdr.wait_for_tag()
(error, tag_type) = rdr.request()
if not error:
(error, uid) = rdr.anticoll()
if not error:
tag_id = ''.join(hex(x)[2:].zfill(2) for x in uid)
print(tag_id)
sys.stdout.flush()
rdr.cleanup()