<?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>How to advertise a DYNAMIC name after the deprecation of BT_LE_ADV_CONN_NAME ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/115746/how-to-advertise-a-dynamic-name-after-the-deprecation-of-bt_le_adv_conn_name</link><description>To advertise a *configurable* device name the previous guidance seemed to be: 
 prj.conf 
 
 
 
 Code Snippet 
 
 
 
 Please note I have intentionally removed all error handling from the code snippet for brevity. 
 
 BT_LE_ADV_CONN_NAME and similar macros</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 23 Oct 2024 12:19:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/115746/how-to-advertise-a-dynamic-name-after-the-deprecation-of-bt_le_adv_conn_name" /><item><title>RE: How to advertise a DYNAMIC name after the deprecation of BT_LE_ADV_CONN_NAME ?</title><link>https://devzone.nordicsemi.com/thread/507576?ContentTypeID=1</link><pubDate>Wed, 23 Oct 2024 12:19:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:545b09b6-c74f-46ec-b37f-9147555a30a6</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]&lt;span&gt;&lt;span&gt;the advertising data however&amp;nbsp;you cannot reference&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;strong&gt;bt_get_name()&lt;/strong&gt; from ad[][/quote]
&lt;p&gt;To enable dynamic updates of the ad[] struct, remove the const keyword. This allows the app to modify the advertisement payload and call bt_le_adv_update_data() to update it on the fly.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct bt_data ad[] = {
		BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
		BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};

int main(void)
{
    
    int counter = 0;
	int len;
	uint8_t dev_name[BT_GAP_ADV_MAX_ADV_DATA_LEN];

    ...

	for (;;) {
		k_msleep(1000);
		len = sprintf(dev_name, &amp;quot;Hello_World_%d&amp;quot;, counter);
		printk(&amp;quot;New device name %s. Len %d\n&amp;quot;, dev_name, len);
		err = bt_set_name(dev_name);
		if (err) {
			printk(&amp;quot;bt_set_name() failed. (err %d)\n&amp;quot;, err);
		}
		
		/* Update adv. payload with new device name */
		ad[1].data = dev_name;
		ad[1].data_len = len;
		ad[1].type = BT_DATA_NAME_COMPLETE;

		err = bt_le_adv_update_data(ad, ARRAY_SIZE(ad), NULL, 0);
		if (err) {
			printk(&amp;quot;bt_le_adv_update_data() failed. (err %d)\n&amp;quot;, err);
		}

		counter++;
	}
	return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Edit: &lt;/strong&gt;Please note that bt_set_name() will update the device name in BT settings (NV storage) if CONFIG_BT_SETTINGS is enabled. This can result in excessive flash usage if the name is updated too frequently. In that&amp;nbsp;case, you may want to update the name only in the advertisement payload, without&amp;nbsp;updating the attribute table.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>