<?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>Ble Disconnect from peripheral and Stop Advertising</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/19383/ble-disconnect-from-peripheral-and-stop-advertising</link><description>Hello , 
 I&amp;#39;m working on custom board, I&amp;#39;m trying to disconnect from the Central (Andriod app) when the battery is below certain level and stop re-advertising.
Below is the piece of code i used: 
 /* Disconnect and then disable advertising */ 
 if</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 20 Apr 2017 18:12:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/19383/ble-disconnect-from-peripheral-and-stop-advertising" /><item><title>RE: Ble Disconnect from peripheral and Stop Advertising</title><link>https://devzone.nordicsemi.com/thread/75214?ContentTypeID=1</link><pubDate>Thu, 20 Apr 2017 18:12:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1fab1c2c-f762-413f-bfc4-135bc1aa4b00</guid><dc:creator>Paulo Becker</dc:creator><description>&lt;p&gt;Hey there Vijayalakshmi!&lt;/p&gt;
&lt;p&gt;Take a look into the ble_advertising.c file. There&amp;#39;s a piece of code for BLE stack event handling, line #376:
void ble_advertising_on_ble_evt(ble_evt_t const * p_ble_evt)
{
static uint16_t current_slave_link_conn_handle = BLE_CONN_HANDLE_INVALID;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;switch (p_ble_evt-&amp;gt;header.evt_id)
{
    case BLE_GAP_EVT_CONNECTED:
        if (p_ble_evt-&amp;gt;evt.gap_evt.params.connected.role == BLE_GAP_ROLE_PERIPH)
        {
            current_slave_link_conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;
        }
        break;

    // Upon disconnection, whitelist will be activated and direct advertising is started.
    case BLE_GAP_EVT_DISCONNECTED:
    {
        uint32_t err_code;
        m_whitelist_temporarily_disabled = false;

        if (p_ble_evt-&amp;gt;evt.gap_evt.conn_handle == current_slave_link_conn_handle)
        {
           err_code = ble_advertising_start(BLE_ADV_MODE_DIRECTED);
           if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp; (m_error_handler != NULL))
           {
               m_error_handler(err_code);
           }
        }
        break;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see, on the disconnecting event, advertising gets indeed resumed automatically if you set on your main.c disconnection event handling the communication handle to BLE_CONN_HANDLE_INVALID.&lt;/p&gt;
&lt;p&gt;As a rule of thumb, I noticed that changing the inner workings of the SDK files result in a lot of problems, so I came around this by adding a volatile flag to keep track of when I didn&amp;#39;t want advertising to be resumed after disconnection and that worked just fine.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Ble Disconnect from peripheral and Stop Advertising</title><link>https://devzone.nordicsemi.com/thread/75215?ContentTypeID=1</link><pubDate>Fri, 24 Mar 2017 10:07:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1d650d8-a150-4b47-bd49-efbd2bb772d3</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;It will not automatically start to advertise after a disconnection, you are probably calling something like advertising start when you get the BLE_GAP_EVT_DISCONNECTED. So you don&amp;#39;t need to call advertising stop, just don&amp;#39;t call advertising start.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Ble Disconnect from peripheral and Stop Advertising</title><link>https://devzone.nordicsemi.com/thread/75213?ContentTypeID=1</link><pubDate>Wed, 01 Feb 2017 13:11:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b83c24a-4f90-45c6-a631-ad111603890d</guid><dc:creator>gorazd</dc:creator><description>&lt;p&gt;meybe after you disconnect, the advertising hasnt started yet. So you call sd_ble_gap_adv_stop() too soon.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>