| nRF5 SDK v12.0.0 |

Choose documentation: | nRF5 SDK | S130 SoftDevice API | S132 SoftDevice API | S212 SoftDevice API | S332 SoftDevice API

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
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":

uint32_t err_code;
static const uint8_t en_payload[] =
{'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
static const uint8_t en_code[] = {'e', 'n'};
NFC_NDEF_TEXT_RECORD_DESC_DEF(en_text_rec,
UTF_8,
en_code,
sizeof(en_code),
en_payload,
sizeof(en_payload));

Next, create the 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(welcome_msg, 1);

Add the record that you created to the message:

err_code = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(welcome_msg),
&NFC_NDEF_TEXT_RECORD_DESC(en_text_rec));
APP_ERROR_CHECK(err_code);

Finally, encode the message:

uint32_t err_code = nfc_ndef_msg_encode(&NFC_NDEF_MSG(welcome_msg),
p_buffer,
p_len);
APP_ERROR_CHECK(err_code);