问题描述
我正在使用 Raspberry Pi 和 RFID-RC522 板开展 Python 项目.作为 NFC 标签,我使用 NXP NTAG213.我现在的计划是在标签上存储链接.我可以毫无问题地读/写它们.但我不明白如何为标签上存储的数据定义 NDEF 标头.
当我用智能手机在标签上写一个链接并用我的程序读取它时,标签上存储的数据如下所示:
网址http://www.gmx.at"的 NDEF 标头是
[3, 11, 209, 1, 7, 85, 1, ... (数据)]
当我编写另一个链接时,我意识到其中一些参数会发生变化,但有些参数仍然保持不变.
我发现了这个教程它描述了 NDEF 标头的不同字段,但我仍然不知道如何设置它们以存储指向网站的链接.
如果有人能描述我需要如何正确计算/定义链接的参数,我会很高兴.
为了了解 NDEF 格式以及 NDEF 格式的数据如何存储在 NFC Forum Type 2 标签(这是由NTAG213),建议您阅读以下NFC论坛规范:
您从标签中读取的数据是一个 NDEF 消息 TLV 对象,其中包含一个 NDEF 消息,该消息由一个 URI 记录组成.
NDEF 消息 TLV:
0x03 TLV 标签 = NDEF 消息 TLV0x0B TLV 长度 = 11 字节0xD1 ... 0x74 TLV 值 = NDEF 消息这意味着该标签包含一个长度为 11 个字节的 NDEF 消息.NDEF 消息是
0xD1 ... 0x74
.NDEF 消息:
0xD1 记录头位 7 = MB = 1:NDEF 消息的第一条记录位 6 = ME = 1:NDEF 消息的最后一条记录位 5 = CF = 0:链的最后或唯一记录位 4 = SR = 1:短记录长度字段位 3 = IL = 0:无 ID/ID 长度字段位 2..0 = TNF = 0x1:类型字段代表 NFC 论坛众所周知的类型名称0x01 类型长度 = 1 字节0x07 有效载荷长度 = 7 字节0x55 类型字段 = "U"(在 US-ASCII 中) = 类型名称 urn:nfc:wkt:U 的二进制形式0x01 ... 0x74 有效载荷字段 = URI 记录有效载荷这意味着 NDEF 消息包含一个 URI 记录(类型名称 urn:nfc:wkt:U),跟在 URI 记录类型定义之后.
URI 记录负载:
0x01 标识符字节 = URI 前缀http://www."0x67 ... 0x74 URI 字段(UTF-8 编码)=gmx.at"这意味着 URI 记录指向 URIhttp://www.gmx.at".
I am working on a Python project with my Raspberry Pi and the RFID-RC522 board. As NFC tags I use NXP NTAG213. My plan now is to store links on the tags. I can read/write on them without a problem. But I don't understand how to define the NDEF header for the stored data on the tags.
When I write a link on the tags with my smartphone and read it with my program the stored data on the tag looks like this:
The NDEF header for the URL "http://www.gmx.at" is
[3, 11, 209, 1, 7, 85, 1, ... (Data)]
I recognized that some of these parameters change when I write another link, but some still stay the same.
I found this tutorial which describes the different fields of the NDEF header but I still don't get how I need to set them to store a link to a website.
I would be very happy if someone can describe how I need to calculate/define the parameters for a link correctly.
In order to understand the NDEF format and the way how NDEF formatted data is stored on an NFC Forum Type 2 tag (which is the tag platform that is implemented by the NTAG213), I suggest that you read the following NFC Forum specifications:
The data that you read from the tag is an NDEF Message TLV object containing an NDEF message that consists of one URI record.
NDEF Message TLV:
0x03 TLV tag = NDEF Message TLV 0x0B TLV length = 11 bytes 0xD1 ... 0x74 TLV value = NDEF message
This means that the tag contains an NDEF message with a length of 11 bytes. The NDEF message is
0xD1 ... 0x74
.NDEF Message:
0xD1 Record header Bit 7 = MB = 1: first record of NDEF message Bit 6 = ME = 1: last record of NDEF message Bit 5 = CF = 0: last or only record of chain Bit 4 = SR = 1: short record length field Bit 3 = IL = 0: no ID/ID length fields Bit 2..0 = TNF = 0x1: Type field represents an NFC Forum well-known type name 0x01 Type length = 1 byte 0x07 Payload length = 7 bytes 0x55 Type field = "U" (in US-ASCII) = binary form of type name urn:nfc:wkt:U 0x01 ... 0x74 Payload field = URI record payload
This means that the NDEF message consists of one URI record (type name urn:nfc:wkt:U) following the URI Record Type Definition.
URI record payload:
0x01 Identifier byte = URI prefix "http://www." 0x67 ... 0x74 URI field (UTF-8 encoded) = "gmx.at"
This means that the URI record points to the URI "http://www.gmx.at".
这篇关于定义 NDEF 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!