NfcPy Tag identifier output does'nt match Tag ID

Viewed 31

I'm trying to use the module NfcPy to output the unique identifier of a NFC Tag. I've gotten NfcPy to output the ID in bytes format. However it doesn't match what i'm seeing when reading the ID with my phone. I've tried using decoding (UTF-8 and others) but I cant seem to get the right output. Here is the output i'm getting from NfcPy:

b"\x04`\xa5\xd2/f\x80"

and here is the output i'm looking for: "04:60:A5:D2:2F:66:80".

Does anyone know how to convert it properly?

Thanks in advance David

1 Answers

Here is an example of how to turn the bytes into a string with : as the separator:

>>> import binascii
>>> data = b"\x04`\xa5\xd2/f\x80"
>>> binascii.hexlify(data)
b'0460a5d22f6680'
>>> binascii.hexlify(data, ':')
b'04:60:a5:d2:2f:66:80'
>>> binascii.hexlify(data, ':').decode()
'04:60:a5:d2:2f:66:80' 
>>> expected = '04:60:a5:d2:2f:66:80'
>>> binascii.hexlify(data, ':').decode() == expected
True
Related