<?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 switch from connectable mode to beacon mode after disconnection</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/86473/how-to-switch-from-connectable-mode-to-beacon-mode-after-disconnection</link><description>Currently I have been able to advertise and connect through debug app using nRF52 DK. My target is: 
 1. After the link is lost the bluetooth gets disconnected and at this time I want the DK to advertise in the beacon mode. 
 2. My purpose is that when</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 22 Apr 2022 08:19:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/86473/how-to-switch-from-connectable-mode-to-beacon-mode-after-disconnection" /><item><title>RE: How to switch from connectable mode to beacon mode after disconnection</title><link>https://devzone.nordicsemi.com/thread/364394?ContentTypeID=1</link><pubDate>Fri, 22 Apr 2022 08:19:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0d87d90c-2b9d-4262-a569-2cf1b1804409</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Vishnu,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You are mixing&amp;nbsp;ble_advertising and the calling sd_ble_gap_adv directly.&lt;br /&gt;I would suggest to follow exactly what I did in the example. Only use sd_ble_gap_adv API and not the&amp;nbsp;&lt;span&gt;ble_advertising&amp;nbsp; module.&amp;nbsp;&lt;br /&gt;Note&amp;nbsp;that I only used one&amp;nbsp;advertising_start() function.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to switch from connectable mode to beacon mode after disconnection</title><link>https://devzone.nordicsemi.com/thread/362800?ContentTypeID=1</link><pubDate>Mon, 11 Apr 2022 10:07:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69a3fc4e-147d-47ff-b1bb-04fb17e42857</guid><dc:creator>VISHNU D PAI</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void advertising_beacon_init(void)
{
    uint32_t      err_code;

    ble_advdata_t advdata1;
    ble_advdata_t srdata1;


    memset(&amp;amp;advdata1, 0, sizeof(advdata1));

    advdata1.name_type          = BLE_ADVDATA_NO_NAME;
    advdata1.include_appearance = true;
    advdata1.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

    memset(&amp;amp;srdata1, 0, sizeof(srdata1));
    srdata1.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    srdata1.uuids_complete.p_uuids  = m_adv_uuids;

    err_code = ble_advdata_encode(&amp;amp;advdata1, m_adv_data1.adv_data1.p_data1, &amp;amp;m_adv_data1.adv_data1.len1);
    APP_ERROR_CHECK(err_code);

    err_code = ble_advdata_encode(&amp;amp;srdata1, m_adv_data1.scan_rsp_data1.p_data1, &amp;amp;m_adv_data1.scan_rsp_data1.len1);
    APP_ERROR_CHECK(err_code);
    ble_gap_adv_params_t adv_params1;

    // Set advertising parameters.
    memset(&amp;amp;adv_params1, 0, sizeof(adv_params1));

    adv_params1.primary_phy     = BLE_GAP_PHY_1MBPS;
    adv_params1.duration        = APP_ADV_DURATION;
    adv_params1.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED;
    adv_params1.p_peer_addr     = NULL;
    adv_params1.filter_policy   = BLE_GAP_ADV_FP_ANY;
    adv_params1.interval        = APP_ADV_INTERVAL;

    err_code = sd_ble_gap_adv_set_configure(&amp;amp;m_adv_handle1, &amp;amp;m_adv_data1, &amp;amp;adv_params1);
    //APP_ERROR_CHECK(err_code);
   
    }


/**@brief Function for initializing the Advertising functionality.
 */
static void advertising_init(void)
{
    ret_code_t             err_code;
    ble_advertising_init_t init;

   
    
   // ble_advdata_manuf_data_t manuf_specific_data;
    //manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
   
    memset(&amp;amp;init, 0, sizeof(init));
    
    ble_advdata_manuf_data_t                  manuf_data; //Variable to hold manufacturer specific data
    uint8_t data[]                            = {0x30,0x5F,0x1E,0xAe,0xEC,0x5E,0xE9}; //Our data to advertise
    manuf_data.company_identifier             =  0x4D4B; //Nordics company ID
    //manuf_data.hardware_type                  =  0x3;
    //manuf_data.bind_tag                       =  0x0;
    manuf_data.data.p_data                    = data;
    manuf_data.data.size                      = sizeof(data);
    init.advdata.p_manuf_specific_data        = &amp;amp;manuf_data;

    init.advdata.name_type               = BLE_ADVDATA_FULL_NAME;
    init.advdata.include_appearance      = true;
    init.advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
    init.advdata.uuids_more_available.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.advdata.uuids_more_available.p_uuids  = m_adv_uuids;
    
    //init.advdata.p_manuf_specific_data   = &amp;amp;manuf_specific_data;

    init.config.ble_adv_on_disconnect_disabled = true;
    init.config.ble_adv_fast_enabled  = true;
    init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;

    init.evt_handler = on_adv_evt;

    err_code = ble_advertising_init(&amp;amp;m_advertising, &amp;amp;init);
    APP_ERROR_CHECK(err_code);

    ble_advertising_conn_cfg_tag_set(&amp;amp;m_advertising, APP_BLE_CONN_CFG_TAG);



    
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The code above is for advertising_init and advertising_beacon_init.&lt;pre class="ui-code" data-mode="text"&gt;static void advertising_beacon_start(void)
{
    ret_code_t           err_code;

    

    err_code = sd_ble_gap_adv_start(m_adv_handle1, APP_BLE_CONN_CFG_TAG);
    NRF_LOG_INFO(&amp;quot;BEACON_STARTED&amp;quot;);
    APP_ERROR_CHECK(err_code);
    

}


/**@brief Function for starting advertising.
 */
static void advertising_start(bool erase_bonds)
{
    if (erase_bonds == true)
    {
        delete_bonds();
        // Advertising is started by PM_EVT_PEERS_DELETED_SUCEEDED event
    }
    else
    {
        ret_code_t err_code = ble_advertising_start(&amp;amp;m_advertising, BLE_ADV_MODE_FAST);

        APP_ERROR_CHECK(err_code);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;this code is for advertising_start and advertising_beacon_start.&lt;/p&gt;
[quote userid="2121" url="~/f/nordic-q-a/86473/how-to-switch-from-connectable-mode-to-beacon-mode-after-disconnection/362489#362489"]ble_app_blinky_beacon.zip[/quote]
&lt;p&gt;this example was really helpful in understanding the fundamentals, but still I am not able switch from connectable to beacon mode in my project. When I disconnect the advertisement goes back to connectable rather than going into beacon mode.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ret_code_t err_code = NRF_SUCCESS;
    bool erase_bonds;
    //pm_handler_secure_on_connection(p_ble_evt);
   
    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_DISCONNECTED:
            NRF_LOG_INFO(&amp;quot;Disconnected.&amp;quot;);
            sd_ble_gap_adv_stop(&amp;amp;m_advertising);
            app_timer_stop(m_adv_data_update_timer);
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
            advertising_beacon_init();
            advertising_beacon_start();
            NRF_LOG_INFO(&amp;quot;beacon_started&amp;quot;);
             &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Please see the code and give some light!!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to switch from connectable mode to beacon mode after disconnection</title><link>https://devzone.nordicsemi.com/thread/362489?ContentTypeID=1</link><pubDate>Fri, 08 Apr 2022 06:53:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e4043d2f-276e-40ca-a078-3d6c3f7feaff</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Vishnu,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m sorry here is the file.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/ble_5F00_app_5F00_blinky_5F00_beacon.zip"&gt;devzone.nordicsemi.com/.../ble_5F00_app_5F00_blinky_5F00_beacon.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to switch from connectable mode to beacon mode after disconnection</title><link>https://devzone.nordicsemi.com/thread/362429?ContentTypeID=1</link><pubDate>Thu, 07 Apr 2022 16:27:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6078bf35-a45f-4eb8-872f-4db122616101</guid><dc:creator>VISHNU D PAI</dc:creator><description>[quote userid="2121" url="~/f/nordic-q-a/86473/how-to-switch-from-connectable-mode-to-beacon-mode-after-disconnection/362415#362415"]Please find the example attached.[/quote]
&lt;p&gt;I can&amp;#39;t see the attached example. Can you attach the example once again!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to switch from connectable mode to beacon mode after disconnection</title><link>https://devzone.nordicsemi.com/thread/362415?ContentTypeID=1</link><pubDate>Thu, 07 Apr 2022 15:07:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e275064-f8fb-49d0-a592-ba706a0fcb83</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi ,&lt;/p&gt;
&lt;p&gt;Please find the example attached. See how I added the&amp;nbsp;advertising_init_beacon() with&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED;&lt;/p&gt;
&lt;p&gt;and calling it inside&amp;nbsp;&lt;span&gt;BLE_GAP_EVT_DISCONNECTED&amp;nbsp; event.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;When you see something doesn&amp;#39;t work please try to debug it. You can use the UART log to see if there is any assert. And you can add DEBUG into the project&amp;#39;s preprocessor symbols to have more information about the assert.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to switch from connectable mode to beacon mode after disconnection</title><link>https://devzone.nordicsemi.com/thread/362292?ContentTypeID=1</link><pubDate>Thu, 07 Apr 2022 10:29:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f6f9102-551a-4905-994a-fca4dd1e7542</guid><dc:creator>VISHNU D PAI</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void advertising_beacon_start(bool erase_bonds)
{

   if (erase_bonds == true)
    {
        delete_bonds();
        // Advertising is started by PM_EVT_PEERS_DELETED_SUCEEDED event
    }
    else
    {
        ret_code_t err_code;

      err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
      APP_ERROR_CHECK(err_code);

      err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
      APP_ERROR_CHECK(err_code); 

    }
    
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is the advertising_beacon_start function and this is called in BLE_GAP_EVT_DISCONNECTED as follows&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt; 
    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_DISCONNECTED:
            NRF_LOG_INFO(&amp;quot;Disconnected.&amp;quot;);
            
             advertising_beacon_start(erase_bonds);
             
            // LED indication will be changed when advertising starts.
            break;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Please can you give a light on what is wrong here. If possible can you give a similiar example on how to tackle this problem.&amp;nbsp;&lt;/p&gt;
[quote userid="2121" url="~/f/nordic-q-a/86473/how-to-switch-from-connectable-mode-to-beacon-mode-after-disconnection/362214#362214"]Please get familiar with how you can stop and re-start advertising.[/quote]
&lt;p&gt;can you give an example or link on how to familiarize with the same&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to switch from connectable mode to beacon mode after disconnection</title><link>https://devzone.nordicsemi.com/thread/362214?ContentTypeID=1</link><pubDate>Thu, 07 Apr 2022 07:22:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1bdeef27-341b-4a66-a6e8-22d73206cf39</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Vishnu,&lt;/p&gt;
&lt;p&gt;Please provide the code you used. I don&amp;#39;t know what you have inside&amp;nbsp;&lt;span&gt;advertising_beacon_start&amp;nbsp;().&amp;nbsp;&lt;br /&gt;Please get familiar with how you can stop and re-start advertising.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to switch from connectable mode to beacon mode after disconnection</title><link>https://devzone.nordicsemi.com/thread/362160?ContentTypeID=1</link><pubDate>Wed, 06 Apr 2022 17:07:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d3e6451-af51-414d-a571-5c9dbb0195c4</guid><dc:creator>VISHNU D PAI</dc:creator><description>&lt;p&gt;I have tried implementing what you have suggested, but after disconnection it stops advertising rather than going to beacon advertising mode. I have added an advertising_beacon_init function and advertising_beacon_start function. Inside the BLE_GAP_EVT_DISCONNECTED I called the advertising_beacon_start function to start beacon mode. Is this the right way to proceed or is there anything I need to do extra.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to switch from connectable mode to beacon mode after disconnection</title><link>https://devzone.nordicsemi.com/thread/361412?ContentTypeID=1</link><pubDate>Mon, 04 Apr 2022 08:20:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0237d95e-ccb5-451d-b168-246a3602bc47</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Vishnu,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What you need to do is in&amp;nbsp;advertising_init() you need to set:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;init.config.ble_adv_on_disconnect_disabled=true.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This will disable the feature to start advertising automatically when disconnect.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Then after that you can write your own code in the&amp;nbsp;BLE_GAP_EVT_DISCONNECTED event handler inside ble_evt_handler() function in main.c to start advertising&amp;nbsp; in beacon mode. I assume you are planning to do non-connectable advertising. Please follow what we have in the beacon example.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to switch from connectable mode to beacon mode after disconnection</title><link>https://devzone.nordicsemi.com/thread/361341?ContentTypeID=1</link><pubDate>Sat, 02 Apr 2022 05:43:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b21d0769-8563-45e9-b4a7-f6a8b306ac70</guid><dc:creator>VISHNU D PAI</dc:creator><description>[quote userid="2121" url="~/f/nordic-q-a/86473/how-to-switch-from-connectable-mode-to-beacon-mode-after-disconnection/361270#361270"]Could you please let us know the SDK you are using[/quote]
&lt;p&gt;I am currently using nRF5 SDK&amp;nbsp; and working on Proximity example from ble_pheripheral. Here I wanted to change the advertising to beacon mode when the app gets disconnected from the nRF52 DK.&amp;nbsp;&lt;/p&gt;
[quote userid="2121" url="~/f/nordic-q-a/86473/how-to-switch-from-connectable-mode-to-beacon-mode-after-disconnection/361270#361270"]I have a blog here about advertising that might be useful for you[/quote]
&lt;p&gt;this blog is based on nRF-connect-SDK, which is not what I need. Can you give some example based on nRF5 SDK.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
[quote userid="2121" url="~/f/nordic-q-a/86473/how-to-switch-from-connectable-mode-to-beacon-mode-after-disconnection/361270#361270"]Have you designed how should the device return to connectable advertising after it start non-connectable advertising ?&amp;nbsp;[/quote]
&lt;p&gt;Can you provide some example based on the same.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to switch from connectable mode to beacon mode after disconnection</title><link>https://devzone.nordicsemi.com/thread/361270?ContentTypeID=1</link><pubDate>Fri, 01 Apr 2022 14:27:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:186157f1-5bc9-460e-9b95-010a8b1b98e4</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Vishnu,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you please let us know the SDK you are using ?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Have you get your self familiar with how to do connectable advertising and non-connectable advertising ?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Have you designed how should the device return to connectable advertising after it start non-connectable advertising ?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I have a blog here about advertising that might be useful for you:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/guides/nrf-connect-sdk-guides/b/software/posts/building-a-ble-application-on-ncs-comparing-and-contrasting-to-softdevice-based-ble-applications"&gt;https://devzone.nordicsemi.com/guides/nrf-connect-sdk-guides/b/software/posts/building-a-ble-application-on-ncs-comparing-and-contrasting-to-softdevice-based-ble-applications&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>