0
votes

In my application I am writing a number of measurements to an NFC chip. As the number of measurements varies, I cannot define an exact length of NDEF message and implementing a function that would count the length and write the payload length just before the NFC read is not practical for the application.

What I thought of doing was to set the size of the NDEF message to maximum available memory and simply write to the free space. However, whilst using an NXP NFC scanner I get an error that my memory is not NDEF formatted. Could anyone tell me what I am doing wrong?

My current understanding is that: 0x03 defines ndef format, 0xFF flags 3 byte length format, 0x373 is the available length, 0xC5 identifies ME and MB for the single chunk, then 0x00 for type length and first two payload bytes, finally - 0x03 and 0x6D defines 0x36D payload length.

The memory (start and end) after initialization can be seen below: enter image description here enter image description here

2
How do you create and write the NDEF message? Do you use the methods built into Android, or something of your own?corvairjo

2 Answers

0
votes

You should know the size of the payload at the time write the message. It's possible to code NDEF by hand, but you need to include the TNF, type, and payload for each record in the message.

I recommend using NdefRecord and NdefMessage to encode the payload and create the message. If at later date you have a different payload with a different size, create a new message and write it to the tag. When you write a message to the tag, it overwrites the previous message.

0
votes

Use the Android Ndef.getMaxSize() method to determine the maximum size available. This however requires actually writing dummy data.

A more optimal way would be to just write the NDEF header, then later modify it as more data is coming in. If so, you should note that the NDEF message iself is wrapped in a simple container style format when actually on the tag. So you'll have to update the length more than once place.

See for example NFCTools