nRF5 SDK v15.3.0
Text record generation

Text records contain descriptive text and can be added to any type of message. The Text records module provides functions for creating and encoding text records.

Text records contain a payload (the actual text string) and a language identifier. Note that a message can contain only one text record per language code, so you cannot add two different text records with language code "en" to the same message, for example.

The following code example shows how to generate a raw text message that contains a text record.

First, generate the text record. In this example, the record contains the text "Hello World!" and the language code "en":

static const uint8_t en_payload[] =
{
'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'
};
static const uint8_t en_code[] = {'e', 'n'};
ret_code_t err_code;
/* Create NFC NDEF text record description in English */
en_code,
sizeof(en_code),
en_payload,
sizeof(en_payload));

Next, create an empty message descriptor. At this time, you specify how many records the message will contain, but you do not specify the actual records yet:

NFC_NDEF_MSG_DEF(nfc_text_msg, MAX_REC_COUNT);

Add the record that you created to the message:

err_code = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(nfc_text_msg),
&NFC_NDEF_TEXT_RECORD_DESC(nfc_en_text_rec));
VERIFY_SUCCESS(err_code);

Finally, encode the message:

err_code = nfc_ndef_msg_encode(&NFC_NDEF_MSG(nfc_text_msg),
p_buffer,
p_len);
return err_code;

Documentation feedback | Developer Zone | Subscribe | Updated