<?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>Stop advertising permanantly in nRF52 SDK15.2</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/47242/stop-advertising-permanantly-in-nrf52-sdk15-2</link><description>Hi, I am using nRF52 DK with SDK 15.2 and SD132 for my project and use &amp;quot;ble_app_uart&amp;quot; as a reference. In my project, I want to start and stop advertisment manually through UART. 
 When I received adv_stop command, I use &amp;quot;sd_ble_gap_adv_stop(m_advertising</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 20 Aug 2019 01:11:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/47242/stop-advertising-permanantly-in-nrf52-sdk15-2" /><item><title>RE: Stop advertising permanantly in nRF52 SDK15.2</title><link>https://devzone.nordicsemi.com/thread/204881?ContentTypeID=1</link><pubDate>Tue, 20 Aug 2019 01:11:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1697749-9495-40cf-9354-19e70aad54f6</guid><dc:creator>Vasiliy Baryshnikov</dc:creator><description>&lt;p&gt;In SDK 15, if you are using a template derived project, you should use the following statement with the parameter to stop advertising:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;sd_ble_gap_adv_stop(m_advertising.adv_handle);&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Stop advertising permanantly in nRF52 SDK15.2</title><link>https://devzone.nordicsemi.com/thread/189127?ContentTypeID=1</link><pubDate>Sat, 25 May 2019 09:33:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c468d60a-5b87-406b-a6af-5ff813618d03</guid><dc:creator>AnthonyThet</dc:creator><description>&lt;p&gt;Hi, sorry for not replying. Actually the issue was in my code coz I tried to recreate a new application file, compile and tested on it and it worked. Really appreciate and thanks for spending your time on the issue and apology again for not updating.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Stop advertising permanantly in nRF52 SDK15.2</title><link>https://devzone.nordicsemi.com/thread/187488?ContentTypeID=1</link><pubDate>Thu, 16 May 2019 10:21:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78955d64-c491-4f8f-a295-ee0524b2b8c5</guid><dc:creator>cbd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know if you have solved your problem or not.&lt;/p&gt;
&lt;p&gt;on_connected, on_disconnected and on_terminated are just calls to functions to handle behaviour of the advertising when certain Bluetooth events occur.&lt;/p&gt;
&lt;p&gt;If you&amp;#39;re only triggering advertising based on your UART input then I would be tempted to just comment out the calls to see if that helps.&lt;/p&gt;
&lt;p&gt;I suspect that on_connected will just disable advertising.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Stop advertising permanantly in nRF52 SDK15.2</title><link>https://devzone.nordicsemi.com/thread/187098?ContentTypeID=1</link><pubDate>Wed, 15 May 2019 01:10:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb11bf41-ab63-4f86-8e00-8d57db7eb314</guid><dc:creator>AnthonyThet</dc:creator><description>&lt;p&gt;Hi cbd, I fount out &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/15608/stop-ble-advertising"&gt;this&lt;/a&gt; which I think quite related to my issues. Here I found out&amp;nbsp;ble_advertising_on_ble_evt() function and all the advertising event&amp;nbsp;on&amp;nbsp;termination, disconnection and connection implemented here.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void ble_advertising_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
{
    ble_advertising_t * p_advertising = (ble_advertising_t *)p_context;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connected(p_advertising, p_ble_evt);
            break;

        // Upon disconnection, whitelist will be activated and direct advertising is started.
        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnected(p_advertising, p_ble_evt);
            break;

        // Upon terminated advertising (time-out), the next advertising mode is started.
        case BLE_GAP_EVT_ADV_SET_TERMINATED:
            on_terminated(p_advertising, p_ble_evt);
            break;

        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But how can I control these functions not to advertise again? Please help me to solve this and thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Stop advertising permanantly in nRF52 SDK15.2</title><link>https://devzone.nordicsemi.com/thread/187043?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 14:47:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:019006ed-621a-48a7-bbd7-9e73e51a211c</guid><dc:creator>AnthonyThet</dc:creator><description>&lt;p&gt;Hi cbd, thanks so much for your help, please let me test in my application and get back to you again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Stop advertising permanantly in nRF52 SDK15.2</title><link>https://devzone.nordicsemi.com/thread/187035?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 14:32:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:250563d7-95ce-46f2-bcba-7b52d0c67d8b</guid><dc:creator>cbd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s some code from a current project that doesn&amp;#39;t rely any library application code.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;///############################################################################
/// @fn              BLE_AdvertisingInit
/// @remark          None
/// @return          ret_code_t error code
/// @see Description Initialises the advertising functionality.
///                  Encodes and passes to the BLE stack data that it uses both
///                  before and during advertising
/// @warning
///#############################################################################
ret_code_t BLE_AdvertisingInit(void)
{
    ret_code_t err_code;

    ble_lms_t lms = LMS_GetServiceData();

    /* Data space is limited within the advertising packet. */
    /* Advertise custom service for easy pickup */
    // TODO: maybe replace the data with manufacturing data */
    ble_uuid_t adv_uuids[] = {{LMS_UUID_SERVICE, lms.uuid_type}};


    /* Build and set advertising data */
    ble_advdata_t advdata;
    memset(&amp;amp;advdata, 0, sizeof(advdata));

    advdata.name_type = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance = true;
    advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

    err_code = ble_advdata_encode(&amp;amp;advdata, m_adv_data.adv_data.p_data, &amp;amp;m_adv_data.adv_data.len);
    APP_ERROR_CHECK(err_code);


    /* Build and set scan response data */
    ble_advdata_t srdata;
    memset(&amp;amp;srdata, 0, sizeof(srdata));
    srdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    srdata.uuids_complete.p_uuids = adv_uuids;

    err_code =
        ble_advdata_encode(&amp;amp;srdata, m_adv_data.scan_rsp_data.p_data, &amp;amp;m_adv_data.scan_rsp_data.len);
    APP_ERROR_CHECK(err_code);

    /* Set advertising parameters */
    ble_gap_adv_params_t adv_params;
    memset(&amp;amp;adv_params, 0, sizeof(adv_params));

    adv_params.primary_phy = BLE_GAP_PHY_1MBPS;
    adv_params.duration = APP_ADV_DURATION;
    adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
    adv_params.p_peer_addr = NULL;
    adv_params.filter_policy = BLE_GAP_ADV_FP_ANY;
    adv_params.interval = APP_ADV_INTERVAL;

    err_code = sd_ble_gap_adv_set_configure(&amp;amp;m_adv_handle, &amp;amp;m_adv_data, &amp;amp;adv_params);
    APP_ERROR_CHECK(err_code);
    return err_code;
}

///############################################################################
/// @fn              BLE_AdvertisingStart
/// @remark          None
/// @return          ret_code_t error code
/// @see Description Triggers BLE advertising through the SoftDevice
/// @warning
///#############################################################################
ret_code_t BLE_AdvertisingStart(void)
{
    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);
    NRF_LOG_INFO(&amp;quot;BLE Advertising started.&amp;quot;);
    return err_code;
}

///############################################################################
/// @fn              BLE_AdvertisingStop
/// @remark          None
/// @return          ret_code_t error code
/// @see Description Terminate BLE advertising through the SoftDevice
/// @warning
///#############################################################################
ret_code_t BLE_AdvertisingStop(void)
{
    ret_code_t err_code = NRF_SUCCESS;

    if (m_adv_handle != BLE_GAP_ADV_SET_HANDLE_NOT_SET)
    {
        NRF_LOG_INFO(&amp;quot;BLE Stop advertising.&amp;quot;);
        err_code = sd_ble_gap_adv_stop(m_adv_handle);
        if (err_code != NRF_ERROR_INVALID_STATE)
        {
            APP_ERROR_CHECK(err_code);
        }
        m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
    }

    return err_code;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I extracted library app code relating to Bluetooth into my own code file. The above code is what I&amp;#39;m using to set-up, start and stop advertising on my current project.&lt;/p&gt;
&lt;p&gt;I hope that this helps.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Stop advertising permanantly in nRF52 SDK15.2</title><link>https://devzone.nordicsemi.com/thread/187000?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 13:35:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4fda059-2ab8-446a-9709-e607c6c99493</guid><dc:creator>AnthonyThet</dc:creator><description>&lt;p&gt;Hi cbd,&lt;/p&gt;
[quote userid="72220" url="~/f/nordic-q-a/47242/stop-advertising-permanantly-in-nrf52-sdk15-2/186993"]I&amp;#39;ve had a quick look again and couldn&amp;#39;t initially see where those even triggers are set-up, if at all, but I must ask how do you trigger advertising to start with and are you attempting to debug using breakpoints?[/quote]
&lt;p&gt;I am waiting for the uart command and start advertising when I recieved the command.&lt;/p&gt;
[quote userid="72220" url="~/f/nordic-q-a/47242/stop-advertising-permanantly-in-nrf52-sdk15-2/186993"]I ask because if you automatically start advertising on power-up (as the example does) and you&amp;#39;re using breakpoints for debugging then this will cause the Soft Device to trigger a reset due to BLE timeouts and advertising will restart.[/quote]
&lt;p&gt;No, I run the code in the release mode.&lt;/p&gt;
&lt;p&gt;Why the advertisement process seems quite complicated for me? I used ble_app_uart_c as a reference for the central role and I can manage to scan on and off successfully using the uart command. And I also tried to look for the code which calls the advertising_start function but I couldn&amp;#39;t find. Please help.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Stop advertising permanantly in nRF52 SDK15.2</title><link>https://devzone.nordicsemi.com/thread/186993?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 13:21:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:940e0597-cdf1-4f58-87a3-c6400991d527</guid><dc:creator>cbd</dc:creator><description>&lt;p&gt;I&amp;#39;ve had a quick look again and couldn&amp;#39;t initially see where those even triggers are set-up, if at all, but I must ask how do you trigger advertising to start with and are you attempting to debug using breakpoints?&lt;/p&gt;
&lt;p&gt;I ask because if you automatically start advertising on power-up (as the example does) and you&amp;#39;re using breakpoints for debugging then this will cause the Soft Device to trigger a reset due to BLE timeouts and advertising will restart.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Stop advertising permanantly in nRF52 SDK15.2</title><link>https://devzone.nordicsemi.com/thread/186844?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 07:24:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ceddf438-e540-4e04-9180-32764ee18ea9</guid><dc:creator>AnthonyThet</dc:creator><description>&lt;p&gt;Hi, really thanks for your prompt reply. I checked all these functions (&lt;span&gt;on_terminated, on_disconnected and&amp;nbsp;&lt;/span&gt;&lt;span&gt;ble_advertising_restart_without_whitelist) and yes they put advertising start again.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    ret = ble_advertising_start(p_advertising, p_advertising-&amp;gt;adv_mode_current);
    if ((ret != NRF_SUCCESS) &amp;amp;&amp;amp; (p_advertising-&amp;gt;error_handler != NULL))
    {
        p_advertising-&amp;gt;error_handler(ret);
    }

    return NRF_SUCCESS;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;but how do I control these functions outside&amp;nbsp;of &amp;quot;ble_advertising.c&amp;quot;.&amp;nbsp;&lt;br /&gt;Is there any simple way to manually stop advertising? I tried using ble_advertising_start(BLE_ADV_MODE_IDLE) but since the event&amp;nbsp;&lt;strong&gt;BLE_ADV_EVT_IDLE&amp;nbsp;&lt;/strong&gt;use &amp;quot;sleep_mode_enter()&amp;quot; function which I don&amp;#39;t need, I am still struggling with this.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;And thanks again for your help.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Stop advertising permanantly in nRF52 SDK15.2</title><link>https://devzone.nordicsemi.com/thread/186842?ContentTypeID=1</link><pubDate>Tue, 14 May 2019 07:14:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3604733-6e11-43f5-bbd6-7ca10855d695</guid><dc:creator>cbd</dc:creator><description>&lt;p&gt;I believe that this code restarts advertising on disconnection, connection terminated events and communication timeout event.&lt;/p&gt;
&lt;p&gt;The actual call to start advertising is sd_ble_gap_adv_start, which in the BLE UART app is called from ble_advertising_start in ble_advertising.c&lt;/p&gt;
&lt;p&gt;Check out calls to:&lt;/p&gt;
&lt;p&gt;on_terminated, on_disconnected and&amp;nbsp;&lt;span style="background-color:#ffffff;"&gt;ble_advertising_restart_without_whitelist&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>