Changing the device name during runtime

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.wsdof.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
6 posts / 0 new
Last post
Niekvdd
Offline
Last seen:1 year 11 months ago
Joined:2017-01-25 09:29
Changing the device name during runtime

Hi all,

I want to change the advertising device name on the fly (during runtime, changeable by an android app). I've the forum thoroughly and came to the conclusion that I should write to NVDS_TAG_DEVICE_NAME, please correct me if I am wrong. I am working from the ble_app_peripheral project from the SDK.

However, I could nowhere find a way to alter this value. Can anybode please tell me how to write to NVDS_TAG_DEVICE_NAME? Alternative ways to change the device name during runtime are also very welcome.
It is not an issue to restart advertising after the device name has been changed.

Kind regards,
Niek

注,我使用SDK 5.0.3.268 5.0.2.1but this option was not selectable

Device:
MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
Joined:2015-06-08 11:34
Hi Niekvdd,

Hi Niekvdd,

Change the name of the device during runtime on the advertising string is possible, and changing the device's name from the android phone is also possible but this requires to connect to the device and provide one through a custom characteristic. So the name of the device is provided through the NVDS_TAG_DEVICE_NAME and that is what is entered into the advertising string, so in order to change that you will have to customize the advertising function. The app_easy_gap_undirected_advertise_start_create_msg() which is the function that fills in the parameters for the message takes by default the name from the NVDS_TAG_DEVICE_NAME, so you can leave that value blank in the SDK use the app_easy_gap_undirected_advertise_get_active() to allocate the message with all the appropriate values and then target the member that holds the advertising string and apply the name that you would like, you will have to TAG the name with the 0x09 flash in order for other devices to know that this is the name of the device.

Thanks MT_dialog

Niekvdd
Offline
Last seen:1 year 11 months ago
Joined:2017-01-25 09:29
Hi MT_dialog,

Hi MT_dialog,

I can follow your explaination up untill "So the name of the device is provided through the NVDS_TAG_DEVICE_NAME ".

1) What does TAGing a name mean?

2) "so in order to change that you will have to customize the advertising function" Do you mean that I should not be altering the contents/value of NVDS_TAG_DEVICE_NAME, but instead modify the functions so that they don't use NVDS_TAG_DEVICE_NAME as a resource? I tried this as follows, however the advertising name is not changing..

in static struct gapm_start_advertise_cmd* app_easy_gap_undirected_advertise_start_create_msg(void) in app.c from example ble_app_peripheral I edited the following from:
uint8_t device_name_length = 0;
uint8_t device_name_temp_buf[NVDS_LEN_DEVICE_NAME];
// Check if data can be added to the Advertising data
if ((adv_avail_space > 0) || (scan_avail_space > 0))
{
// Get the Device Name to add in the Advertising Data
// Get default Device Name (No name if not enough space)
device_name_length = NVDS_LEN_DEVICE_NAME;
if (nvds_get(NVDS_TAG_DEVICE_NAME, &device_name_length, &device_name_temp_buf[0]) != NVDS_OK)
{
// Restore the default value
ASSERT_WARNING(0);
device_name_length = 0;
}
}

to:

// uint8_t device_name_length = 0;
// uint8_t device_name_temp_buf[NVDS_LEN_DEVICE_NAME];

uint8_t device_name_length = 6;
uint8_t device_name_temp_buf[6] = "1test1" ;
// memcpy(&cmd->info.host.adv_data[cmd->info.host.adv_data_len + 2], device_name_temp_buf, device_name_length);
//
// Check if data can be added to the Advertising data
// if ((adv_avail_space > 0) || (scan_avail_space > 0))
// {
// // Get the Device Name to add in the Advertising Data
// // Get default Device Name (No name if not enough space)
// device_name_length = NVDS_LEN_DEVICE_NAME;
// if (nvds_get(NVDS_TAG_DEVICE_NAME, &device_name_length, &device_name_temp_buf[0]) != NVDS_OK)
// {
// // Restore the default value
// ASSERT_WARNING(0);
// device_name_length = 0;
// }
// }

To my understanding, the (original) snippet at the bottom of static struct gapm_start_advertise_cmd* app_easy_gap_undirected_advertise_start_create_msg(void) should then make 1test1 the advertising name:

// Place the Device Name in the Advertising Data or in the Scan Response Data
if(device_name_length > 0)
{
if(adv_avail_space >= device_name_length)
{
app_easy_gap_place_name_ad_struct(&cmd->info.host.adv_data_len, device_name_length,
&cmd->info.host.adv_data[cmd->info.host.adv_data_len], device_name_temp_buf);
}
if(scan_avail_space >= device_name_length)
{
app_easy_gap_place_name_ad_struct(&cmd->info.host.scan_rsp_data_len, device_name_length,
&cmd->info.host.scan_rsp_data[cmd->info.host.scan_rsp_data_len], device_name_temp_buf);
}
}
}

Kind regards,
Niek

MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
Joined:2015-06-08 11:34
Hi Niekvdd,

Hi Niekvdd,

1)在广告字符串所包含的所有数据are tagged in order for the client to be able to parse the data in the advertising string, for example in the BLE spec the 0x09 value is tagged as "Complete Local Name" the value 0xFF is tagged as "Manufacturer Specific data", for more info on this please check the BLE specification.

2) There are several ways to do this, you can either modify the advertising function in order to place the data that you would like in the advertising string. You can also leave the NVDS_TAG_DEVICE_NAME blank or even place a string in there and after the message has initialized (with the app_easy_gap_undirected_advertise_start()) overwrite the advertising data string (located in the cmd->info.host.adv_data[] array). The SDK has the default functionallity of obtaining the NVDS_TAG_DEVICE_NAME and place it in the advertising string, so you can either create a custom advertising function that doesn't do that and places in the adv string your data or leave the function as is and overwrite the name in the allocated command.

Thanks MT_dialog

Niekvdd
Offline
Last seen:1 year 11 months ago
Joined:2017-01-25 09:29
Hi MT_dialog,

Hi MT_dialog,

1) How would I place a string in NVDS_TAG_DEVICE_NAME during runtime? I see that it is initialized in const struct nvds_data_struct nvds_data_storage __attribute__((section("nvds_data_storage_area"))) but how can I alter this value during runtime?

2) How can I manually tag any value?

3) I managed to change the device name that is being advertised by putting strcpy((char*) device_name_temp_buf, "name12"); just before if(device_name_length > 0) in the function static struct gapm_start_advertise_cmd* app_easy_gap_undirected_advertise_start_create_msg(void). In this case name12 is the new name.
However, when I connect and read the Device Name (UUID 0x2A00) from the Generic Access Service (UUID 0x1800) I still get the original device name returned as set in NVDS_TAG_DEVICE_NAME. How can I change the value of the device name as returned by UUID 0x2A00 ?

Kind regards,
Niek

MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
Joined:2015-06-08 11:34
Hi Niekvdd,

Hi Niekvdd,

1) You can't do that, you cannot alter the value of the NVDS_TAG_DEVICE during runtime. The value from the NVDS_TAG_DEVICE is taken and placed in the advertising string when you start advertising, so you can directly alter the values placed in the advertising command (for example in the barebone project in the user_app_adv_start() function when the app_easy_gap_undirected_advertise_get_active() returns the pointer of the advertising string message you can alter the value of the name in the cmd->info.host.adv_data[]) and not the NVDS_TAG_DEVICE, or as mentioned above create your own function that will create the advertising message and send it to the stack.

2) The tags in the advertising string are just values of the advertising string itself, by placing the length of the data, the tag of the data and the data itself tags a specific part of the advertising string, depending on the length and the tag as a particular information. Please check the BLE specification for this.

3) Changing the name of the device in the attribute database of the Generic Access service is something different from just changing the devices name in the advertising string, the value of that characteristic is taken from the NVDS structure upon creating the databases when the device boots up, and this is defined in the BLE stack in the ROM code, there are two ways to change that, you can either use the function attmdb_att_set_value() and as parameters you should pass the GAPM_GET_ATT_HANDLE(GAP_IDX_DEVNAME) in order for the device name handle to be returned and then provide the length and value of the characteristic as you would like, or you can use the GAPM_SET_DEV_NAME_CMD message (you will find more info regarding the message in the RW-BLE-GAP-IS.pdf).

Thanks MT_dialog