I'm developing a nfc writer app. Mifare Ultralight tags, ACR122 reader. The reader shows me the "TAG_ISO_14443_3" standard. node.js, nfc-pcsc lib. I need to write a URL link to website, so my writing tag function looks like this (I found the NDEF structure example here link):
async function writeUrl (reader, url, block = 4) {
// +-------------------------+----------------------------------------------------------------
// | D1 | Header flags 11010001 (MB = ME = 1, CF = 0, SR = 1, IL = 0, TNF = 0x1) TNF = 0x1 is "well known NFC format"
// +-------------------------+----------------------------------------------------------------
// | 01 | Type Length (1 byte)
// +-------------------------+----------------------------------------------------------------
// | N | Payload Length (N bytes)
// +-------------------------+----------------------------------------------------------------
// | 55 | Type Name ("U")
// +-------------------------+----------------------------------------------------------------
// | 04 ... | Payload: Identifier code = 4 (prefix "https://"),
// | | truncated URI = url
// +-------------------------+----------------------------------------------------------------
let flagsByte = parseInt('D1', 16)
let typeLength = 1
let payloadLength = 1 + url.length // identifierByte + url
let typeName = parseInt('55', 16) // 'U', Url
let header = Buffer.from([flagsByte, typeLength, payloadLength, typeName]) // 4 bytes
let identifier = Buffer.from([parseInt('04', 16)]) // prefix https://, 1 byte
let urlBuffer = Buffer.from(url, 'utf8')
let payload = Buffer.concat([identifier, urlBuffer])
let length = header.length + payload.length
let remains = length % 4
length += (4 - remains) // we can write only by blocks (4 bytes)
if (length > 144) {
length = 144 // maximum bytes possible
}
let data = Buffer.concat([header, payload], length)
reader.write(block, data);
console.log(`data written`, reader, data) // data has 30+ not-zero bytes, all ok
return true;
}
What's the problem? After I wrote the message, my NFC reader app (GoToTags Windows app) shows me that my tag is empty.
Please help. I think I've missed something small but important...