How do I write an NDEF message that has two or more records?

Asked by Juan Trujillo

I would like to write to my NFC tag an NDEF message that contains two ore more records. For example, I would like to write a WiFi and a Text records to my tag. Of course I'll be limited by the amount of available space on the NFC tag.

I have successfully able to write one record with the following code:

import nfc
from time import sleep
import time

clf = nfc.ContactlessFrontend('tty:AMA0:pn53x')
print(clf)

def connected(tag): print tag

""" Wait for NFC tag """
timeOut = lambda: time.time() - started > (10)
started = time.time()
myNfcTag = clf.connect(rdwr={'on-connect': connected}, terminate=timeOut)

myMsg = nfc.ndef.TextRecord()
myMsg.text = "This is a test..."
print(myMsg.pretty())

myNfcTag.ndef.message = nfc.ndef.Message(myMsg)
clf.close()

Unfortunately I haven't found a way to write multiple records.

Please help!!!

Question information

Language:
English Edit question
Status:
Answered
For:
nfcpy Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#1

A Message object can be initialized with multiple Records, Records can be appended to an existing Message and a Message can be extended with a list of Records. Here's a tutorial: http://nfcpy.org/latest/topics/ndef.html#creating-ndef.

Can you help with this problem?

Provide an answer of your own, or ask Juan Trujillo for more information if necessary.

To post a message you must log in.