<?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>Change device name during BLE Connection (SDK 15.0.0)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/41404/change-device-name-during-ble-connection-sdk-15-0-0</link><description>Hi everyone, 
 My hw/sw configuration: 
 - nRF52840 - sdk 15.0.0 - softdevice: s140_nrf52_6.0.0 
 I would like to change the device name and update it in advertising packet, during a BLE connection. 
 
 Reading this post: 
 https://devzone.nordicsemi</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 10 Dec 2018 10:22:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/41404/change-device-name-during-ble-connection-sdk-15-0-0" /><item><title>RE: Change device name during BLE Connection (SDK 15.0.0)</title><link>https://devzone.nordicsemi.com/thread/160930?ContentTypeID=1</link><pubDate>Mon, 10 Dec 2018 10:22:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24452508-474e-4f75-8645-cb258653b03a</guid><dc:creator>leoc7</dc:creator><description>&lt;p&gt;I think I&amp;#39;ve solved it&lt;/p&gt;
&lt;p&gt;I modified&amp;nbsp;&lt;strong&gt;change_ble_device_name&lt;/strong&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;function in this way:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void change_ble_device_name(uint8_t *device_name){
    ble_gap_conn_sec_mode_t sec_mode;
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;sec_mode);

    /* Change device name */
    uint32_t err_code = sd_ble_gap_device_name_set(&amp;amp;sec_mode,
                                          (const uint8_t *)device_name,
                                          strlen(device_name));
    APP_ERROR_CHECK(err_code);

    /* Store Current connection state od adv lib */
    uint16_t m_adv_current_slave_link_conn_handle_saved = m_advertising.current_slave_link_conn_handle;

    /* Re-initialize advertising module */
    advertising_init();

    /* Re-store Current connection state lib */
    m_advertising.current_slave_link_conn_handle = m_adv_current_slave_link_conn_handle_saved;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I saved&amp;nbsp;&lt;strong&gt;current_slave_link_conn_handle&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;variable, because adv init function set&amp;nbsp;&lt;strong&gt;current_slave_link_conn_handle&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;to&amp;nbsp;&lt;strong&gt;BLE_CONN_HANDLE_INVALID.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t ble_advertising_init(ble_advertising_t            * const p_advertising,
                              ble_advertising_init_t const * const p_init)
{
//...
    p_advertising-&amp;gt;adv_mode_current               = BLE_ADV_MODE_IDLE;
    p_advertising-&amp;gt;adv_modes_config               = p_init-&amp;gt;config;
    p_advertising-&amp;gt;conn_cfg_tag                   = BLE_CONN_CFG_TAG_DEFAULT;
    p_advertising-&amp;gt;evt_handler                    = p_init-&amp;gt;evt_handler;
    p_advertising-&amp;gt;error_handler                  = p_init-&amp;gt;error_handler;
    p_advertising-&amp;gt;current_slave_link_conn_handle = BLE_CONN_HANDLE_INVALID;
    p_advertising-&amp;gt;p_adv_data                     = &amp;amp;p_advertising-&amp;gt;adv_data;
//...
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Setting&amp;nbsp;current_slave_link_conn_handle&amp;nbsp;to&amp;nbsp;BLE_CONN_HANDLE_INVALID,&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;on_disconnected&amp;nbsp;&lt;/strong&gt;function inside ble_advertising.c, doesn&amp;#39;t restart advertising.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void on_disconnected(ble_advertising_t * const p_advertising, ble_evt_t const * p_ble_evt)
{
    uint32_t ret;

    p_advertising-&amp;gt;whitelist_temporarily_disabled = false;

    if (p_ble_evt-&amp;gt;evt.gap_evt.conn_handle == p_advertising-&amp;gt;current_slave_link_conn_handle &amp;amp;&amp;amp;
        p_advertising-&amp;gt;adv_modes_config.ble_adv_on_disconnect_disabled == false)
    {
       ret = ble_advertising_start(p_advertising, BLE_ADV_MODE_DIRECTED_HIGH_DUTY);
       if ((ret != NRF_SUCCESS) &amp;amp;&amp;amp; (p_advertising-&amp;gt;error_handler != NULL))
       {
           p_advertising-&amp;gt;error_handler(ret);
       }
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Change device name during BLE Connection (SDK 15.0.0)</title><link>https://devzone.nordicsemi.com/thread/160910?ContentTypeID=1</link><pubDate>Mon, 10 Dec 2018 09:46:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:119a2297-6c5c-4e35-9a6c-06dabb226db3</guid><dc:creator>Pertti Kasanen</dc:creator><description>&lt;p&gt;Sorry, edited that. I thought I had that edited before posting but failed somehow :(&lt;br /&gt;&lt;br /&gt;Changing the advertising packet content on the fly is a complex task - with everything that is needed around. We use SDK 15.2.0 and it is already different than&amp;nbsp;SDK15.0. Cannot remember how we had it implemented on the 15.0.&amp;nbsp;&lt;span&gt;15.2 has additional functions for the task - but it is more complex.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;With default setup you device stops advertising already when you connect. You need to catch the disconnect event and restart the advertising.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Change device name during BLE Connection (SDK 15.0.0)</title><link>https://devzone.nordicsemi.com/thread/160894?ContentTypeID=1</link><pubDate>Mon, 10 Dec 2018 09:09:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a4b31ba-b363-49f5-ae55-03c0f50be165</guid><dc:creator>leoc7</dc:creator><description>&lt;p&gt;I don&amp;#39;t understand your solution.&lt;br /&gt;What is seed_advertising_init() function?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I tried to&lt;br /&gt;- change name&lt;/p&gt;
&lt;p&gt;- stop adv&lt;/p&gt;
&lt;p&gt;- re-init advertising&lt;/p&gt;
&lt;p&gt;But when you disconnect from device, device stops to advertise.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Change device name during BLE Connection (SDK 15.0.0)</title><link>https://devzone.nordicsemi.com/thread/160891?ContentTypeID=1</link><pubDate>Mon, 10 Dec 2018 09:03:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fdd1e089-c322-401a-9561-9e14c13f88ee</guid><dc:creator>Pertti Kasanen</dc:creator><description>&lt;p&gt;I remember solving that once but not 100% of the complex details. &lt;br /&gt;&lt;br /&gt;I&amp;nbsp;think it included calling first sd_ble_gap_device_name_set(), then sd_ble_gap_adv_stop() and then&lt;/p&gt;
&lt;pre&gt;[edit:] ble_advertising_init().&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Change device name during BLE Connection (SDK 15.0.0)</title><link>https://devzone.nordicsemi.com/thread/160885?ContentTypeID=1</link><pubDate>Mon, 10 Dec 2018 08:45:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:241fd9d7-f11e-44db-aa63-0053d2b2e8c1</guid><dc:creator>leoc7</dc:creator><description>&lt;p&gt;Edit:&amp;nbsp;&lt;br /&gt;After changing name and disconnecting, device didn&amp;#39;t advertising.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>