<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/113297/ble-how-to-set-the-device-name-dynamically</link><description>I have seen a few posts including: 
 
 Change advertised name (Bluetooth) - Nordic Q&amp;amp;A - Nordic DevZone - Nordic DevZone (nordicsemi.com) 
 NCS bt_set_name() - Nordic Q&amp;amp;A - Nordic DevZone - Nordic DevZone (nordicsemi.com) 
 Setting Bluetooth Device Name</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 25 Sep 2025 11:17:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/113297/ble-how-to-set-the-device-name-dynamically" /><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/549793?ContentTypeID=1</link><pubDate>Thu, 25 Sep 2025 11:17:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:baf3f4ef-5fe6-440e-a828-a18b878e6c88</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;Ok. I resolved the -5 issue but still cannot change the name dynamically:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;   LOG_DBG(&amp;quot;Initializing BLE manager with name: %s&amp;quot;, dynamic_name);

    int err;


    bt_addr_le_t addr;
	err = bt_addr_le_from_str(&amp;quot;FF:EE:DD:CC:BB:AA&amp;quot;, &amp;quot;random&amp;quot;, &amp;amp;addr);
	if (err) {
		LOG_ERR(&amp;quot;Invalid BT address (err %d)&amp;quot;, err);
        return err;
	} else {
        LOG_DBG(&amp;quot;BT address set&amp;quot;);
    }


    err = bt_id_create(&amp;amp;addr, NULL);
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Creating new ID failed (err %d)&amp;quot;, err);
        return err;
	} else {
        LOG_DBG(&amp;quot;New ID created with index %d&amp;quot;, err);
    }

    err = bt_enable(NULL);
    if (err) {
        LOG_ERR(&amp;quot;Bluetooth init failed (err %d)&amp;quot;, err);
        return err;
    } else {
        LOG_DBG(&amp;quot;Bluetooth enabled&amp;quot;);
    }

    // set the device name
    err = bt_set_name(dynamic_name);
    if (err) {
        LOG_ERR(&amp;quot;Setting device name failed (err %d)&amp;quot;, err);
        return err;
    } else {
        LOG_DBG(&amp;quot;Device name set to %s&amp;quot;, dynamic_name);
    }

    // set the advertising data
    err = bt_le_adv_update_data(ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
    if (err) {
        LOG_ERR(&amp;quot;Updating advertising data failed (err %d)&amp;quot;, err);
        return err;
    } else {
        LOG_DBG(&amp;quot;Advertising data updated&amp;quot;);
    }


	k_work_init(&amp;amp;adv_work, adv_work_handler);
	advertising_start();

    return 0;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;but I get this error in the log:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;dbg&amp;gt; ew_ble_manager: ew_ble_manager_init: Bluetooth enabled
&amp;lt;dbg&amp;gt; ew_ble_manager: ew_ble_manager_init: Device name set to TEST001
&amp;lt;err&amp;gt; ew_ble_manager: Updating advertising data failed (err -11)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;if I comment out the &lt;code&gt;bt_le_adv_update_data&lt;/code&gt; there is no error but the name does not change.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have found this post as well &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/86994/nrf-connect-sdk-how-to-change-bt-name"&gt;[nRF Connect SDK] How to change BT name&lt;/a&gt;&amp;nbsp;which seem to be recreating the sd rather than calling apis to change the name. But I can&amp;#39;t do it exactly this way or the way I did it before because according to the latest DevAcademy lesson on &lt;a href="https://academy.nordicsemi.com/courses/bluetooth-low-energy-fundamentals/lessons/lesson-2-bluetooth-le-advertising/topic/blefund-lesson-2-exercise-3/"&gt;Bluetooth LE Advertising (Lesson 2)&lt;/a&gt;&amp;nbsp;for v3.1.1-v3.0.0 you need to do things a little differently because &amp;quot;Starting from version 3.0.0 of the nRF Connect SDK, advertising is automatically turned off when a peripheral connects to a central device, and it remains off after the disconnection.&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Ok. Took away static const on &lt;code&gt;ad&lt;/code&gt; and did this on top of all that:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;    ad[1].data = dynamic_name;
	ad[1].data_len = strlen(dynamic_name);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Which works, but I don&amp;#39;t understand what&amp;nbsp;&lt;code&gt;bt_set_name(dynamic_name);&lt;/code&gt; actually does here if I&amp;#39;m udating the array directly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/549638?ContentTypeID=1</link><pubDate>Wed, 24 Sep 2025 07:36:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee3db760-3bb0-4493-96af-621737f03ecb</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Leo&lt;/p&gt;
&lt;p&gt;Error message -5 points to an input/output error reported when trying to start the advertisement. Can you share the full log and your main.c file so I can take a better look at what is going on here? I assume you&amp;#39;re still trying to set a dynamic device name when advertising.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/549463?ContentTypeID=1</link><pubDate>Mon, 22 Sep 2025 16:57:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:26eb25e2-7f4e-4503-87de-5f8cd9870388</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;Now I&amp;#39;m getting a &amp;quot;Advertising failed to start (err -5)&amp;quot;:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;    const struct bt_data ad[] = {
        BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR),
        BT_DATA(BT_DATA_NAME_COMPLETE, dynamic_name, sizeof(dynamic_name)),
        BT_DATA(BT_DATA_MANUFACTURER_DATA, (unsigned char *)&amp;amp;adv_mfg_data, sizeof(adv_mfg_data)),
    };&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This is frustrating.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/513416?ContentTypeID=1</link><pubDate>Wed, 04 Dec 2024 12:33:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c19d2a7-39cc-4d93-a0e3-d5286eb4005f</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;I was able to do it, but not as I expected. I was thinking I would be able to use&amp;nbsp;&lt;code&gt;bt_le_adv_update_data&lt;/code&gt; or &lt;code&gt;bt_le_ext_adv_set_data&lt;/code&gt; and the &lt;code&gt;bt_set_name()&lt;/code&gt; function, but that did not seem to work. I really don&amp;#39;t know if it matters, but I was thinking there might be a simple example showing how they work.&lt;/p&gt;
&lt;p&gt;By moving the&amp;nbsp;&lt;code&gt;bt_data&lt;/code&gt; into the main function, I was able to change the BT device name.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int ble_manager_init()
{
    LOG_DBG(&amp;quot;Starting &amp;#39;%s&amp;#39;&amp;quot;, DEVICE_NAME);

    int err;

    err = bt_enable(NULL);
    if (err) {
        LOG_ERR(&amp;quot;Bluetooth init failed (err %d)&amp;quot;, err);
        return -1;
    }
    LOG_DBG(&amp;quot;Bluetooth initialized&amp;quot;);

#ifdef CONFIG_BT_DEVICE_NAME_DYNAMIC

    // Generate a random 6-digit number
    unsigned int random_number = 100000 + rand() % 900000; // Ensures a range from 100000 to 999999
    LOG_DBG(&amp;quot;Random number: %d&amp;quot;, random_number);

    // Assuming random_number is already defined and holds a random 6-digit number
    char device_name[18]; // Ensure this is large enough to hold the resulting string
    
    // Create a formatted string with the random number
    snprintf(device_name, sizeof(device_name), &amp;quot;DeviceName %d&amp;quot;, random_number);
    
    // Set the Bluetooth device name
    //bt_set_name(device_name);
    LOG_DBG(&amp;quot;Bluetooth device name: %s&amp;quot;, device_name);

    //bt_set_name(device_name);

    //param.options = BT_LE_ADV_OPT_USE_NAME;
    //bt_le_ext_adv_create(&amp;amp;param, NULL, &amp;amp;adv_set);
    //bt_le_per_adv_start(adv_set);

    //ad[1].data = device_name;
	//ad[1].data_len = strlen(device_name);

    /* didn&amp;#39;t work
    err = bt_le_adv_update_data(ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
    if (err) {
        LOG_ERR(&amp;quot;Failed to update (err %d)&amp;quot;, err);	
        return -1;
    }
    */


    struct bt_le_adv_param *adv_param = BT_LE_ADV_PARAM(
	(BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_IDENTITY), /* Connectable advertising and use identity address */
	800, /* Min Advertising Interval 500ms (800*0.625ms) */
	801, /* Max Advertising Interval 500.625ms (801*0.625ms) */
	NULL); /* Set to NULL for undirected advertising */

    const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR),
	BT_DATA(BT_DATA_NAME_COMPLETE, device_name, strlen(device_name)),
    /* STEP 3 - Include the Manufacturer Specific Data in the advertising packet. */
	BT_DATA(BT_DATA_MANUFACTURER_DATA, (unsigned char *)&amp;amp;adv_mfg_data, sizeof(adv_mfg_data)),
};


#endif

    err = bt_le_adv_start(adv_param, ad, ARRAY_SIZE(ad),sd, ARRAY_SIZE(sd));
    if (err) {
        LOG_ERR(&amp;quot;Advertising failed to start (err %d)&amp;quot;, err);	
        return -1;
    }

    LOG_DBG(&amp;quot;Bluetooth advertising&amp;quot;);

    return 0;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/513005?ContentTypeID=1</link><pubDate>Mon, 02 Dec 2024 14:27:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b8ebd0b-1f40-49f2-9c01-c85b73945199</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;Can you change/update it dynamically? Can you post the code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/512836?ContentTypeID=1</link><pubDate>Sat, 30 Nov 2024 10:13:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a1b4a56-8726-468b-926c-e1a1e1095a17</guid><dc:creator>lara</dc:creator><description>&lt;p&gt;i got it solved.adding&lt;/p&gt;
&lt;div style="background-color:#1f1f1f;color:#cccccc;font-family:Consolas, &amp;#39;Courier New&amp;#39;, monospace;font-size:14px;font-weight:normal;line-height:19px;white-space:pre;"&gt;
&lt;div&gt;&lt;span style="color:#569cd6;"&gt;static char &lt;/span&gt;&lt;span style="color:#9cdcfe;"&gt;device_name&lt;/span&gt;&lt;span style="color:#569cd6;"&gt;[&lt;/span&gt;&lt;span style="color:#569cd6;"&gt;DEVICE_NAME_LEN&lt;/span&gt;&lt;span style="color:#569cd6;"&gt;] &lt;/span&gt;&lt;span style="color:#d4d4d4;"&gt;=&lt;/span&gt;&lt;span style="color:#569cd6;"&gt; &lt;/span&gt;&lt;span style="color:#ce9178;"&gt;&amp;quot;nRF52833_Device&amp;quot;&lt;/span&gt;&lt;span style="color:#569cd6;"&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;also in proj.conf&lt;/p&gt;
&lt;div style="background-color:#1f1f1f;color:#cccccc;font-family:Consolas, &amp;#39;Courier New&amp;#39;, monospace;font-size:14px;font-weight:normal;line-height:19px;white-space:pre;"&gt;
&lt;div&gt;&lt;span style="color:#6a9955;"&gt;#&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#6a9955;"&gt;# Copyright (c) 2018 Nordic Semiconductor&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#6a9955;"&gt;#&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#6a9955;"&gt;# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#6a9955;"&gt;#&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#569cd6;"&gt;CONFIG_NCS_SAMPLES_DEFAULTS&lt;/span&gt;&lt;span style="color:#cccccc;"&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span style="color:#569cd6;"&gt;CONFIG_BT&lt;/span&gt;&lt;span style="color:#cccccc;"&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#569cd6;"&gt;CONFIG_BT_PERIPHERAL&lt;/span&gt;&lt;span style="color:#cccccc;"&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#569cd6;"&gt;CONFIG_BT_DEVICE_NAME_DYNAMIC&lt;/span&gt;&lt;span style="color:#cccccc;"&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#6a9955;"&gt;#CONFIG_BT_DEVICE_NAME=&amp;quot;NRF52833&amp;quot;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span style="color:#6a9955;"&gt;# Enable the LBS service&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#569cd6;"&gt;CONFIG_BT_LBS&lt;/span&gt;&lt;span style="color:#cccccc;"&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#569cd6;"&gt;CONFIG_BT_LBS_POLL_BUTTON&lt;/span&gt;&lt;span style="color:#cccccc;"&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#569cd6;"&gt;CONFIG_DK_LIBRARY&lt;/span&gt;&lt;span style="color:#cccccc;"&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span style="color:#569cd6;"&gt;CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE&lt;/span&gt;&lt;span style="color:#cccccc;"&gt;=2048&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/512814?ContentTypeID=1</link><pubDate>Fri, 29 Nov 2024 16:21:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74f033ed-7f99-4499-911a-48f39a4f8674</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;I to switch to something else as I could not resolve this but need to get back to it. I&amp;nbsp;was working on a simple example of how to change the name starting with the code above.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/512673?ContentTypeID=1</link><pubDate>Fri, 29 Nov 2024 06:42:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:025f7914-6d3a-4483-ba16-7e7cc60bb7e1</guid><dc:creator>lara</dc:creator><description>&lt;p&gt;iam facing the same issue,have u got the solution? now u can change the name dynamically?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/497944?ContentTypeID=1</link><pubDate>Tue, 13 Aug 2024 07:45:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:690c055f-56f1-440f-a29a-5e1588a385c9</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;You need to update the device name by calling&amp;nbsp;&lt;strong&gt;bt_le_adv_update_data&lt;/strong&gt; or&amp;nbsp;&lt;strong&gt;bt_le_ext_adv_set_data&amp;nbsp;&lt;/strong&gt;and the &lt;strong&gt;bt_set_name&lt;/strong&gt;() inside there (with a &lt;em&gt;constant character&lt;/em&gt; as the new name). In the code snippet you uploaded the &lt;strong&gt;bt_set_name&lt;/strong&gt;() function is commented out.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**
 * @brief Set Bluetooth Device Name
 *
 * Set Bluetooth GAP Device Name.
 *
 * When advertising with device name in the advertising data the name should
 * be updated by calling @ref bt_le_adv_update_data or
 * @ref bt_le_ext_adv_set_data.
 *
 * @note Requires @kconfig{CONFIG_BT_DEVICE_NAME_DYNAMIC}.
 *
 * @sa @kconfig{CONFIG_BT_DEVICE_NAME_MAX}.
 *
 * @param name New name
 *
 * @return Zero on success or (negative) error code otherwise.
 */
int bt_set_name(const char *name);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/497871?ContentTypeID=1</link><pubDate>Mon, 12 Aug 2024 16:13:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a7ecbfc-64a1-42a3-9516-f167fc1b0a12</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;How do I set the device name dynamically?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/497801?ContentTypeID=1</link><pubDate>Mon, 12 Aug 2024 12:02:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9da05d13-f995-4fa8-b983-86d35dab51af</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Leo,&lt;/p&gt;
&lt;p&gt;But you&amp;#39;re adding these data members in read-only objects that won&amp;#39;t be able to handle writable objects it seems.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/497602?ContentTypeID=1</link><pubDate>Fri, 09 Aug 2024 10:12:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b12928e3-1f61-49ca-8cbf-ee9936ef7ba4</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;I don&amp;#39;t think so. Same place I tried to set the name with bt_set_name, which seemed like it should work.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    // Generate a random 6-digit number
    unsigned int random_number = 100000 + rand() % 900000; // Ensures a range from 100000 to 999999
    LOG_DBG(&amp;quot;Random number: %d&amp;quot;, random_number);

    // Assuming random_number is already defined and holds a random 6-digit number
    char device_name[18]; // Ensure this is large enough to hold the resulting string
    
    // Create a formatted string with the random number
    snprintf(device_name, sizeof(device_name), &amp;quot;DeviceName %d&amp;quot;, random_number);
    
    // Set the Bluetooth device name
    //bt_set_name(device_name);
    LOG_DBG(&amp;quot;Bluetooth device name: %s&amp;quot;, device_name);

    ad[1].data = device_name;
	ad[1].data_len = strlen(device_name);

    err = bt_le_adv_update_data(ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
    if (err) {
        LOG_ERR(&amp;quot;Failed to update (err %d)&amp;quot;, err);	
        return -1;
    }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/496376?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2024 09:20:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f59df7a0-0b57-4781-b9e7-317fc3022dcc</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Where in your project are you adding these lines on your end? It seems like you&amp;#39;re trying to assign them somewhere invalid...&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/496184?ContentTypeID=1</link><pubDate>Tue, 30 Jul 2024 11:37:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6857f782-df9a-4d91-9ce0-bfda6b469acd</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;It didn&amp;#39;t work. I got an error on the build.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;error: assignment of member &amp;#39;data&amp;#39; in read-only object&lt;br /&gt; 113 | ad[1].data = device_name;&lt;br /&gt; | ^&lt;/p&gt;
&lt;p&gt;error: assignment of member &amp;#39;data_len&amp;#39; in read-only object&lt;br /&gt; 114 | ad[1].data_len = strlen(device_name);&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/496176?ContentTypeID=1</link><pubDate>Tue, 30 Jul 2024 10:32:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c349e2ef-1aca-4002-ab5b-fea19ca4df76</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;Ok. Yes. The uploaded .zip file has this:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
	/* Start advertising  */
	char * ble_name = get_adv_name(); // Need to be called before bt_enable();
	ad[1].data = ble_name;
	ad[1].data_len = strlen(ble_name);
	LOG_INF( &amp;quot;BLE name: %s&amp;quot;, nvs_store.ble_name);
	err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
	if (err) {
		LOG_ERR(&amp;quot;Advertising failed to start (err %d)&amp;quot;, err);
		return -1;
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I will test and confirm. I guess I thought&amp;nbsp;&lt;code&gt;bt_set_name(device_name);&lt;/code&gt; was a way to do this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/496148?ContentTypeID=1</link><pubDate>Tue, 30 Jul 2024 08:35:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25eddcb9-105a-4d73-9307-cbb611e0ec97</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Leo&lt;/p&gt;
&lt;p&gt;If you see in the last reply by Pedro, he uploaded a .zip file with code to &amp;quot;hopefully help someone&amp;quot;. Did you check that out as well?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/495971?ContentTypeID=1</link><pubDate>Mon, 29 Jul 2024 10:28:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ce5eddf-50d0-402d-ac15-0cbf9de14013</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;There was no code in that to change the name. Only to store to store the changed name in flash. In the ticket Pedro says: &amp;quot;&lt;span&gt;I have a BLE service which exposes the Device Name characteristic to allow user to change BLE name showed when advertising.&amp;quot; which is what I want to do.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/495947?ContentTypeID=1</link><pubDate>Mon, 29 Jul 2024 08:26:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fbc77da8-2b9b-4b97-b355-f130a0bb33e9</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Okay, please check out t&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/104220/easiest-way-to-store-in-flash-in-runtime-in-an-app-already-using-settings-with-ble/448312"&gt;his ticket by Sigurd&lt;/a&gt;, where he explains how you can use the NVS backend for storing the device name dynamically.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/495867?ContentTypeID=1</link><pubDate>Sat, 27 Jul 2024 01:44:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ba09bc5-3883-411e-832b-c147f6f0899a</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;2.6.1&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/495650?ContentTypeID=1</link><pubDate>Thu, 25 Jul 2024 13:36:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8238233-4d13-4c09-9184-b830ed84f1ee</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;First off, what SDK version are you using here. I just want to make sure we start on the same page here. It might seem like either the Bluetooth stack isn&amp;#39;t initialized yet or that the advertiser is busy with something, since the error message basically means &amp;quot;try again&amp;quot;, and doesn&amp;#39;t point to anything specific.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/495398?ContentTypeID=1</link><pubDate>Wed, 24 Jul 2024 11:16:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:162ff642-5045-4e59-a40d-1f05b09d2e57</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;I did turn Bluetooth on and off.&lt;/p&gt;
&lt;p&gt;I tried adding:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Set the Bluetooth device name
bt_set_name(device_name);
LOG_DBG(&amp;quot;Bluetooth device name: %s&amp;quot;, device_name);

err = bt_le_adv_update_data(ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
if (err) {
    LOG_ERR(&amp;quot;Failed to update (err %d)&amp;quot;, err);
    return -1;
}&lt;/pre&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;and got:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;[00:00:00.470,611] &amp;lt;err&amp;gt; ble_manager: Failed to update (err -11)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;but I don&amp;#39;t know why I would need to update the data if I&amp;#39;m setting the name before I start advertising. I guess that&amp;#39;s my question. What is the right order of methods to call in order to set the name dynamically.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE How to set the device name dynamically</title><link>https://devzone.nordicsemi.com/thread/495360?ContentTypeID=1</link><pubDate>Wed, 24 Jul 2024 08:38:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:238fb7e2-ba27-45a2-921b-9912a2a4e353</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;In the second link you provided, Einar explains that most scanners/phones will cache the device name, so in most cases you need to toggle Bluetooth on/off on the scanner side to update a name on the scanner. If you&amp;#39;ve already done that, you should make sure that the name is updated in the advertising packet with &lt;strong&gt;bt_le_adv_update_data&lt;/strong&gt;() which I don&amp;#39;t see you&amp;#39;re using.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>