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

Asked by Juan Trujillo on 2015-09-09

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')

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..."

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

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

Please help!!!

Question information

English Edit question
nfcpy Edit question
No assignee Edit question
Last query:
Last reply:

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:

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.