How to loop thru messages and records

Asked by Juan Trujillo

I'm assuming that I can have multiple NDEF messages stored in a tag. I'm also assuming that I can have multiple NDEF records stored in one NDEF message...

My questions is how do I can I loop thru the messages on a tag? And how do I loop thru the records in a message?

Based on the following test code, tag.ndef.message object should have everything I need...

def connected(tag):
  print tag
  if tag.ndef:
    print tag.ndef.message.pretty()
    "Sorry, no NDEF"

clf = nfc.ContactlessFrontend('tty:AMA0:pn53x')
clf.connect(rdwr={'on-connect': connected})


Question information

English Edit question
nfcpy Edit question
No assignee Edit question
Solved by:
Stephen Tiedemann
Last query:
Last reply:
Revision history for this message
Best Stephen Tiedemann (stephen-tiedemann) said :

There should only be one NDEF message on a tag. Technically some tags support more in a proprietary way but that is not interoperable (can't be copied between different tags) and also dangerous as touching a tag should yield one reproducible result and not an arbitrary decision of the reader.

There can of course be multiple records in a message and the nfc.ndef.Message object that tag.ndef.message provides presents them as an iterable list.

for record in tag.ndef.message:
    print record.pretty()

Revision history for this message
Juan Trujillo (juancarlos-trujillo) said :

Thanks Stephen Tiedemann, that solved my question.