URI messages and records
URI messages contain exactly one URI record, which in turn contains an address that an NFC polling device can open. In the most typical use case, the URI record contains a web address like “http://www.nordicsemi.com” that the polling device opens in a web browser.
URI records consist of a URI field (the actual address) and a URI identifier that specifies the protocol of the URI and is prepended to the URI.
See nfc_ndef_uri_rec_id
for the available protocols.
The URI records module provides functions for creating the record, and the URI messages module provides functions for creating and encoding the message.
The following code snippets show how to generate a URI message. First, define the URI string and create a buffer for the message:
static const uint8_t m_url[] =
{'n', 'o', 'r', 'd', 'i', 'c', 's', 'e', 'm', 'i', '.', 'c', 'o', 'm'}; //URL "nordicsemi.com"
uint8_t m_ndef_msg_buf[256];
Then create the URI message with one URI record.
As parameters, provide the URI identifier code (NFC_URI_HTTP_WWW
in this example), the URI string, the length of the URI string, the message buffer, and the size of the available memory in the buffer:
int err;
err = nfc_ndef_uri_msg_encode( NFC_URI_HTTP_WWW,
m_url,
sizeof(m_url),
m_ndef_msg_buf,
&len);
if (err < 0) {
printk("Cannot encode message!\n");
return err;
}
API documentation
URI messages
include/nfc/ndef/uri_msg.h
subsys/nfc/ndef/uri_msg.c
URI records
include/nfc/ndef/uri_rec.h
subsys/nfc/ndef/uri_rec.c