<?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>Disable BLE failed</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/54799/disable-ble-failed</link><description>Hi, 
 I am using nrf52832 with softdevice s132. The peripheral device is nrf52832 and central device is a mobile app. I want to disable BLE in nrf52832 and I am using this: 
 
 I see that when I call this function without connection between my app and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 26 Nov 2019 03:35:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/54799/disable-ble-failed" /><item><title>RE: Disable BLE failed</title><link>https://devzone.nordicsemi.com/thread/221973?ContentTypeID=1</link><pubDate>Tue, 26 Nov 2019 03:35:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5848bbb6-5821-4d83-b706-e48579cd1937</guid><dc:creator>nghia</dc:creator><description>&lt;p&gt;Thanks for your respond, it&amp;#39;s a good solution for this. I found another workaround: There are 2 case happen when we disable BLE, when connecting and when non-connecting. In case of connecting. I disconnect and in on_adv_evt(), case BLE_ADV_EVT_FAST (I am using fast adv), I call sd_ble_gap_adv_stop(). In case of non-connecting, it means ble is advertising, I just have to call sd_ble_gap_adv_stop() in disable_ble().&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;bool run_adv = true;

uint32_t disable_ble(void)
{
    uint32_t err_code;
    if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
    {
        err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
        run_adv = false;
    }
    else
    {
        err_code = sd_ble_gap_adv_stop(m_advertising.adv_handle);
    }
    return err_code;
}

static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
    uint32_t err_code;
    switch (ble_adv_evt)
    {
        case BLE_ADV_EVT_FAST:
            if (run_adv == false)
            {
                sd_ble_gap_adv_stop(m_advertising.adv_handle);
            }
            break;
        case BLE_ADV_EVT_IDLE:
            sleep_mode_enter();
            break;
        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disable BLE failed</title><link>https://devzone.nordicsemi.com/thread/221897?ContentTypeID=1</link><pubDate>Mon, 25 Nov 2019 14:48:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2c234ad-a429-4417-9673-aeedf5cc365f</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user=""]my app try to reconnect immediately, and the app can reconnect.[/quote]
&lt;p&gt;Did you enable auto-connect function on the mobile app as this &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/9199/i-want-my-app-to-auto-connect-to-my-nrf51822-device"&gt;post&lt;/a&gt;?&amp;nbsp; If so, you could disable the function.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;-Amanda H.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>