<?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>Dynamically changing Advertisement name when using PHY ENCODED</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/91710/dynamically-changing-advertisement-name-when-using-phy-encoded</link><description>I&amp;#39;m using the nRF52840 with NCS SDK 2.0.2 and need to be able to change the BLE advertisement name of the peripheral device dynamically. 
 I have this working when using &amp;quot;normal&amp;quot; BLE strength. This is accomplished by calling &amp;quot;bt_le_adv_update_data()&amp;quot;</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 11 Sep 2022 00:09:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/91710/dynamically-changing-advertisement-name-when-using-phy-encoded" /><item><title>RE: Dynamically changing Advertisement name when using PHY ENCODED</title><link>https://devzone.nordicsemi.com/thread/385591?ContentTypeID=1</link><pubDate>Sun, 11 Sep 2022 00:09:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc8fdf8d-532c-431d-b374-919fc38444b1</guid><dc:creator>CktDesigner</dc:creator><description>&lt;p&gt;OK...&amp;nbsp; &amp;nbsp;Now I see what is happening...&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When I changed from &amp;quot;normal&amp;quot; to &amp;quot;coded&amp;quot; BLE modes, I had to move the advertised name from the sd[] array to the ad[] array.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When changing the advertised name, I failed to change the &amp;quot;index&amp;quot; (using the index of the advertised name in sd[] when modifying the (now moved) advertised name in ad[]) when making the modification.&lt;/p&gt;
&lt;p&gt;The modified values made it into the ad[] array, but the old name was also still there and was used by BLE when advertising.&amp;nbsp; &amp;nbsp; Using the proper index fixed things.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamically changing Advertisement name when using PHY ENCODED</title><link>https://devzone.nordicsemi.com/thread/385545?ContentTypeID=1</link><pubDate>Fri, 09 Sep 2022 14:27:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37f97935-9c26-41c9-9c3e-cf1ad06e029e</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Can you please share the contents of your&amp;nbsp;&lt;em&gt;ad&lt;/em&gt; array before and after you try to set the new name using coded phy?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamically changing Advertisement name when using PHY ENCODED</title><link>https://devzone.nordicsemi.com/thread/385344?ContentTypeID=1</link><pubDate>Thu, 08 Sep 2022 14:42:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b0b6abc6-2540-4817-94ff-524fdfe3f52d</guid><dc:creator>CktDesigner</dc:creator><description>&lt;p&gt;Thanks...&amp;nbsp; &amp;nbsp;But I don&amp;#39;t think this is set.&amp;nbsp; &amp;nbsp;Here is the code used to start advertising:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void btAdvertisingStart(void) {
  int err;
printk(&amp;quot;Start Avertisement\n&amp;quot;);

  struct bt_le_adv_param param =
  BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_CONNECTABLE |
                        BT_LE_ADV_OPT_EXT_ADV |
                        BT_LE_ADV_OPT_CODED,
                        BT_GAP_ADV_FAST_INT_MIN_2,
                        BT_GAP_ADV_FAST_INT_MAX_2,
                        NULL);

	err = bt_le_ext_adv_create(&amp;amp;param, NULL, &amp;amp;adv);
	if (err) {
		printk(&amp;quot;Failed to create advertiser set (%d)\n&amp;quot;, err);
		return err;
	}

printk(&amp;quot;Created adv: %p\n&amp;quot;, adv);

	//err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
  err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), NULL, 0);
	if (err) {
		printk(&amp;quot;Failed to set advertising data (%d)\n&amp;quot;, err);
		return err;
	}

  err = bt_le_ext_adv_start(adv, NULL);
	if (err) {
		printk(&amp;quot;Failed to start advertising set (%d)\n&amp;quot;, err);
		return;
	} else {
    printk(&amp;quot;Advertising successfully started\n&amp;quot;);
  }

    // Change the name of the module
#if 1
  printf(&amp;quot;After bt ready: Setting name to %s\n&amp;quot;,telemetry1Name.name.chars);
      err= newBleAdvName(telemetry1Name.name.chars);
      if(err &amp;lt; 0) {
  printk(&amp;quot;Error setting device name at startup: %d\n&amp;quot;,err);
      }
#endif
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamically changing Advertisement name when using PHY ENCODED</title><link>https://devzone.nordicsemi.com/thread/385342?ContentTypeID=1</link><pubDate>Thu, 08 Sep 2022 14:29:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:523d231c-77c9-4f33-b097-cc389e603d86</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;The &amp;quot;defines&amp;quot; are&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/connectivity/bluetooth/api/gap.html#c.@40"&gt;advertising options&lt;/a&gt;, part of the&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/connectivity/bluetooth/api/gap.html#c.bt_le_adv_param"&gt;bt_le_adv_param struct&lt;/a&gt;&amp;nbsp;passed into&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/connectivity/bluetooth/api/gap.html#c.bt_le_ext_adv_update_param"&gt;bt_le_ext_adv_update_param()&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Sounds like BT_LE_ADV_OPT_SCANNABLE should be disabled to let you update your advertising data.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamically changing Advertisement name when using PHY ENCODED</title><link>https://devzone.nordicsemi.com/thread/385327?ContentTypeID=1</link><pubDate>Thu, 08 Sep 2022 13:43:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3c79c713-8e53-4ca6-85cc-013e9b8ee0c8</guid><dc:creator>CktDesigner</dc:creator><description>&lt;p&gt;In prj.conf:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_BT_DEVICE_NAME_DYNAMIC&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Where are the &amp;quot;defines&amp;quot; you mention set?&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;I set the device name via bt_set_name().&amp;nbsp; &amp;nbsp;But to change the advertising name:&lt;/p&gt;
&lt;p&gt;for &amp;quot;normal&amp;quot; BLE, the advertised name is in the sd[] array and bt_le_adv_update_data() is used to change it.&amp;nbsp; &amp;nbsp; &amp;nbsp;This works.&lt;/p&gt;
&lt;p&gt;for &amp;quot;coded&amp;quot; BLE , the advertised name is in the ad[] array and I&amp;#39;ve tried both bt_le_ext_adv_set_data() and bt_le_adv_update_data() to change the name.&amp;nbsp; &amp;nbsp; As mentioned above, using bt_le_adv_update_data() fails.&amp;nbsp; &amp;nbsp;Using bt_le_ext_adv_set_data() does not return an error, but the advertised name doesn&amp;#39;t change.&lt;/p&gt;
&lt;p&gt;Here is the code for assigning a new name...&amp;nbsp; &amp;nbsp;Lots of debugging printk statements...&amp;nbsp; &amp;nbsp; A #ifdef is used to select one set of code.&lt;/p&gt;
&lt;p&gt;For &amp;quot;normal&amp;quot; BLE:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
        BT_DATA_BYTES(BT_DATA_UUID128_ALL, UUID_VLSI_TELEMETRY1_SERVICE_VAL),
};

static struct bt_data sd[] = {
        BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int newBleAdvName(char *newName) {
  int err;

  // Update the device name
  printk(&amp;quot;Set new name: %s\n&amp;quot;,newName);
  err = bt_set_name(newName);
  if(err) {
    printk(&amp;quot;Error setting device name variable: %d\n&amp;quot;, err);
  } else {
printk(&amp;quot;Changed device name to: %s\n&amp;quot;, newName);
    // Update the advertising and scan response data needed to update the advertised device name
    // Only need to modify the scan response data in this example as name is in scan response here.
    sd-&amp;gt;data = newName;
    sd-&amp;gt;data_len = strlen(newName);
    err = bt_le_adv_update_data(ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
    if(err) {
      printk(&amp;quot;Error updating advertised name: %d\n&amp;quot;, err);
    } else {
printk(&amp;quot;Changed advertised name to: %s\n&amp;quot;, newName);
    }
  }
  return err;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;For &amp;quot;coded&amp;quot; BLE:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
        BT_DATA_BYTES(BT_DATA_UUID128_ALL, UUID_VLSI_TELEMETRY1_SERVICE_VAL),
        BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
int newBleAdvName(char *newName) {
  int err;

  // Update the device name
  printk(&amp;quot;Set new name: %s\n&amp;quot;,newName);
  err = bt_set_name(newName);
  if(err) {
    printk(&amp;quot;Error setting device name variable: %d\n&amp;quot;, err);
  } else {
printk(&amp;quot;Changed device name to: %s\n&amp;quot;, newName);

btAdvertisingStop();

    // Update the advertising and scan response data needed to update the advertised device name
    //// Only need to modify the scan response data in this example as name is in scan response here.
    ad-&amp;gt;data = newName;
    ad-&amp;gt;data_len = strlen(newName);
    err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), NULL, 0);
    //err = bt_le_adv_update_data(ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
    if(err) {
      printk(&amp;quot;Error updating advertised name: %d\n&amp;quot;, err);
    } else {
printk(&amp;quot;Changed encoded advertised name to: %s\n&amp;quot;, newName);
    }
btAdvertisingReStart();
  }
  return err;
}

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Note...&amp;nbsp; &amp;nbsp;This works in &amp;quot;normal&amp;quot; BLE, but not in &amp;quot;coded&amp;quot;.&amp;nbsp; &amp;nbsp; (Is scannable data legal in &amp;quot;coded&amp;quot;)?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamically changing Advertisement name when using PHY ENCODED</title><link>https://devzone.nordicsemi.com/thread/385213?ContentTypeID=1</link><pubDate>Thu, 08 Sep 2022 09:29:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5821631e-5e63-43f6-9f61-64f4c0fdf910</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Looking at&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/connectivity/bluetooth/api/gap.html#c.bt_le_ext_adv_update_param"&gt;bt_le_ext_adv_update_param()&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When changing the option BT_LE_ADV_OPT_USE_NAME then bt_le_ext_adv_set_data needs to be called in order to update the advertising data and scan response data.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And then looking at&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/connectivity/bluetooth/api/gap.html#c.@40.BT_LE_ADV_OPT_USE_NAME"&gt;BT_LE_ADV_OPT_USE_NAME&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Include the GAP device name automatically when advertising.&lt;br /&gt; By default the GAP device name is put at the end of the scan&lt;br /&gt; response data.&lt;br /&gt; When advertising using BT_LE_ADV_OPT_EXT_ADV and not&lt;br /&gt;BT_LE_ADV_OPT_SCANNABLE then it will be put at the end of the&lt;br /&gt; advertising data. [...]&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And from&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/connectivity/bluetooth/api/gap.html#c.bt_le_ext_adv_set_data"&gt;bt_le_ext_adv_set_data()&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When both BT_LE_ADV_OPT_EXT_ADV and BT_LE_ADV_OPT_SCANNABLE are enabled then advertising data is ignored. When BT_LE_ADV_OPT_SCANNABLE is not enabled then scan response data is ignored.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;How do you currently include your advertising name in your advertising data? Is it in your advertising data or your response data? If BT_LE_ADV_OPT_SCANNABLE is disabled it seems like the GAP device name set by bt_set_name() will be included in your advertising data, have you tried this?&lt;/p&gt;
&lt;p&gt;-Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamically changing Advertisement name when using PHY ENCODED</title><link>https://devzone.nordicsemi.com/thread/385107?ContentTypeID=1</link><pubDate>Wed, 07 Sep 2022 17:06:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:816ddb24-966f-4a20-94d7-f7e3595b3a13</guid><dc:creator>CktDesigner</dc:creator><description>&lt;p&gt;Hi Einarh,&lt;/p&gt;
&lt;p&gt;Thanks...&lt;/p&gt;
&lt;p&gt;The text in the bt_set_name() definition says to use&amp;nbsp;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a class="reference internal" href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/connectivity/bluetooth/api/gap.html?highlight=bt_le_adv_update_data#group__bt__gap_1ga9a406ebfefac3dd09935a4ae0e317817"&gt;&lt;span class="std std-ref"&gt;&lt;span class="highlighted"&gt;bt_le_adv_update_data&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span&gt;&amp;nbsp;or&amp;nbsp;&lt;/span&gt;&lt;a class="reference internal" href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/connectivity/bluetooth/api/gap.html?highlight=bt_le_adv_update_data#group__bt__gap_1gad731f829b3566be3e56485b2a64f80b1"&gt;&lt;span class="std std-ref"&gt;bt_le_ext_adv_set_data&lt;/span&gt;&lt;/a&gt;&amp;nbsp;once advertising has been started.&lt;/p&gt;
&lt;p&gt;I tried using bt_le_adv_update_data, but it fails with error&amp;nbsp;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;EINVAL (-22).&amp;nbsp; &amp;nbsp;(This is the call I use to change the name when using &amp;quot;normal&amp;quot; BLE.)&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Tracing through the code, it looks like bt_le_adv_update_data expects the &amp;quot;&lt;/span&gt;&lt;span&gt;struct&lt;/span&gt;&lt;span&gt; bt_le_ext_adv&amp;quot; variable (adv) to be in the &amp;quot;bt_dev&amp;quot; structure.&amp;nbsp; &amp;nbsp; Following the &amp;quot;coded&amp;quot; example, I declared the &amp;quot;adv&amp;quot; variable separately.&amp;nbsp; &amp;nbsp;And there doesn&amp;#39;t seem to be a call to assign the value to the &amp;quot;bt_dev&amp;quot; structure.&amp;nbsp; &amp;nbsp; So the call to &amp;quot;&lt;/span&gt;bt_le_adv_lookup_legacy()&amp;quot; inside bt_le_adv_update_data returns NULL, causing the error.&lt;/p&gt;
&lt;p&gt;So I tried using bt_le_ext_adv_set_data.&lt;/p&gt;
&lt;p&gt;&amp;quot;bt_le_ext_adv_set_data&amp;quot; is used to set the advertising name after the advertising set is created (using &amp;quot;bt_le_ext_adv_create&amp;quot;),&amp;nbsp; &amp;nbsp; &amp;nbsp;It is then used again when trying to change the name.&amp;nbsp; &amp;nbsp; The function call returns without error, but the original name is still advertised.&lt;/p&gt;
&lt;p&gt;What is the appropriate way to change the advertising name (when using PHY CODED)?&amp;nbsp; &amp;nbsp; Thoughts?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;PS...&amp;nbsp; &amp;nbsp; I also tried stopping advertising prior to calling bt_le_ext_adv_set_data(), then restarting it.&amp;nbsp; &amp;nbsp; Still advertises with original name...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamically changing Advertisement name when using PHY ENCODED</title><link>https://devzone.nordicsemi.com/thread/385031?ContentTypeID=1</link><pubDate>Wed, 07 Sep 2022 12:17:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc90d526-63a4-45c7-a20b-ab093d580170</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Hello&lt;/p&gt;
&lt;p&gt;According to the description of&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/connectivity/bluetooth/api/gap.html?highlight=bt_le_adv_update_data#c.bt_set_name"&gt;bt_set_name()&lt;/a&gt;, it looks like it might be bt_le_ext_adv_set_data() you are looking for?&lt;/p&gt;
&lt;p&gt;Or have you tried using bt_set_name()?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>