ondryaso / pi-rc522

Raspberry Pi Python library for SPI RFID RC522 module
MIT License
417 stars 149 forks source link

Reading card content to text #30

Open o15a3d4l11s2 opened 7 years ago

o15a3d4l11s2 commented 7 years ago

Could you please include or point me to an example for how to read the whole content of a card and print it as a string?

I have checked your examples but could not wrap my head around the whole logic for reading the data from the card.

I understand the sectors and blocks, but what exactly should be done in order to read the whole card and output the whole data as a textual content?

mattelacchiato commented 6 years ago

Got this working. But keep in mind that this lib is heavily byte-oriented. I'll guess, you'll have to figure out the corresponding formats for your own...

This is how i read out the first 20 blocks:

def read_out(block_address):
    if not util.is_tag_set_auth():
        return True

    error = util.do_auth(block_address)
    if not error:
        (error, data) = util.rfid.read(block_address)
        #print(util.sector_string(block_address) + ": " + data)
        print(util.sector_string(block_address) + ": " + "".join(chr(e) for e in data))
    else:
        print("Error on " + util.sector_string(block_address))

for i in range(0,19):
    read_out(i)
o15a3d4l11s2 commented 6 years ago

Thanks a lot, @mattelacchiato, will try this out in the next days.

ogroef commented 6 years ago

Got this working. But keep in mind that this lib is heavily byte-oriented. I'll guess, you'll have to figure out the corresponding formats for your own...

This is how i read out the first 20 blocks:

def read_out(block_address):
    if not util.is_tag_set_auth():
        return True

    error = util.do_auth(block_address)
    if not error:
        (error, data) = util.rfid.read(block_address)
        #print(util.sector_string(block_address) + ": " + data)
        print(util.sector_string(block_address) + ": " + "".join(chr(e) for e in data))
    else:
        print("Error on " + util.sector_string(block_address))

for i in range(0,19):
    read_out(i)

How did you, @mattelacchiato, handle invalid unicode values? How do you ensure that you have readable charachters.

Kind Regards Olivier

mattelacchiato commented 6 years ago

Yeah, this lib is indeed very byte-oriented. I've found this article very helpful: https://learn.adafruit.com/adafruit-pn532-rfid-nfc/mifare

I don't read the content as string, so I don't have a problem with wrong unicode values. I read only NDEF format (https://learn.adafruit.com/adafruit-pn532-rfid-nfc/ndef) and pass those bytes to a NDEF lib (https://ndeflib.readthedocs.io/en/stable/). But which bytes to read and how many can be tricky, too ;-)

Woppilif commented 5 years ago

Yeah, this lib is indeed very byte-oriented. I've found this article very helpful: https://learn.adafruit.com/adafruit-pn532-rfid-nfc/mifare

I don't read the content as string, so I don't have a problem with wrong unicode values. I read only NDEF format (https://learn.adafruit.com/adafruit-pn532-rfid-nfc/ndef) and pass those bytes to a NDEF lib (https://ndeflib.readthedocs.io/en/stable/). But which bytes to read and how many can be tricky, too ;-)

@mattelacchiato , Can you please show your snippet of this code?

mattelacchiato commented 5 years ago

Sure: https://github.com/mattelacchiato/hoerspieler/blob/master/main.py#L44

Hope this helps...

Woppilif commented 5 years ago

Sure: https://github.com/mattelacchiato/hoerspieler/blob/master/main.py#L44

Hope this helps...

Thank you! Have you tried to read tags from phone? I'm getting some errors with auth.

mattelacchiato commented 5 years ago

Jeah, that works in my case. You have to be compliant to the standard...

Sergey Karsten notifications@github.com schrieb am Mo., 29. Apr. 2019, 17:30:

Sure: https://github.com/mattelacchiato/hoerspieler/blob/master/main.py#L44

Hope this helps...

Thank you! Have you tried to read tags from phone? I'm getting some errors.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ondryaso/pi-rc522/issues/30#issuecomment-487627135, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAZYYI7JPKFMRTGH7RZ22TPS4ICJANCNFSM4DQSUC3A .

Woppilif commented 5 years ago

Jeah, that works in my case. You have to be compliant to the standard... Sergey Karsten notifications@github.com schrieb am Mo., 29. Apr. 2019, 17:30: Sure: https://github.com/mattelacchiato/hoerspieler/blob/master/main.py#L44 Hope this helps... Thank you! Have you tried to read tags from phone? I'm getting some errors. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#30 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAZYYI7JPKFMRTGH7RZ22TPS4ICJANCNFSM4DQSUC3A .

Tell me please which app do you use to send data between devices. And is this complete code that you use to do this? https://github.com/mattelacchiato/hoerspieler/blob/master/main.py#L44 Have you changed rc522 lib? I'm trying to understand this case but still geting nothing.

mattelacchiato commented 5 years ago

I use this only for communication between the NFC module and an NFC card, not between devices.

This is my complete code, i didn't changed anything. But I've copied and modified some methods from pi-rc522 to fit them for my needs.

Sergey Karsten notifications@github.com schrieb am Mo., 29. Apr. 2019, 18:02:

Jeah, that works in my case. You have to be compliant to the standard... Sergey Karsten notifications@github.com schrieb am Mo., 29. Apr. 2019, 17:30: … <#m-5456195668244917234> Sure: https://github.com/mattelacchiato/hoerspieler/blob/master/main.py#L44 Hope this helps... Thank you! Have you tried to read tags from phone? I'm getting some errors. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#30 (comment) https://github.com/ondryaso/pi-rc522/issues/30#issuecomment-487627135>, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAZYYI7JPKFMRTGH7RZ22TPS4ICJANCNFSM4DQSUC3A .

Tell me please which app do you use to send data between devices. And is this complete code that you use to do this? https://github.com/mattelacchiato/hoerspieler/blob/master/main.py#L44 Have you changed rc522 lib? I'm trying to understand this case but still geting nothing.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ondryaso/pi-rc522/issues/30#issuecomment-487639557, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAZYYJWEPMPWAI7EQ6OVZ3PS4LZHANCNFSM4DQSUC3A .

Woppilif commented 5 years ago

I use this only for communication between the NFC module and an NFC card, not between devices. This is my complete code, i didn't changed anything. But I've copied and modified some methods from pi-rc522 to fit them for my needs. Sergey Karsten notifications@github.com schrieb am Mo., 29. Apr. 2019, 18:02: Jeah, that works in my case. You have to be compliant to the standard... Sergey Karsten @.*** schrieb am Mo., 29. Apr. 2019, 17:30: … <#m-5456195668244917234> Sure: https://github.com/mattelacchiato/hoerspieler/blob/master/main.py#L44 Hope this helps... Thank you! Have you tried to read tags from phone? I'm getting some errors. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#30 (comment) <#30 (comment)>>, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAZYYI7JPKFMRTGH7RZ22TPS4ICJANCNFSM4DQSUC3A . Tell me please which app do you use to send data between devices. And is this complete code that you use to do this? https://github.com/mattelacchiato/hoerspieler/blob/master/main.py#L44 Have you changed rc522 lib? I'm trying to understand this case but still geting nothing. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#30 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAZYYJWEPMPWAI7EQ6OVZ3PS4LZHANCNFSM4DQSUC3A .

Ah. Okay thou. Now it's become absolutely clear for me. As I see there is no opportunity to use rc522 and NFC on Phone.

Thank you btw!