<?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>Disconnect and stop advertising after transaction</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/42204/disconnect-and-stop-advertising-after-transaction</link><description>Hi - In the examples provided, a peripheral will go to power off after completing its transactions.This means the the application does not have to &amp;quot;clean up&amp;quot; afterwards. 
 I have an application that requires the peripheral to stay on Power On mode all</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 08 Jan 2019 03:44:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/42204/disconnect-and-stop-advertising-after-transaction" /><item><title>RE: Disconnect and stop advertising after transaction</title><link>https://devzone.nordicsemi.com/thread/164405?ContentTypeID=1</link><pubDate>Tue, 08 Jan 2019 03:44:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b34f764e-3d0e-492f-9d0b-1bb5ffd76d3f</guid><dc:creator>fgeldenh</dc:creator><description>&lt;p&gt;Edvin - Thank you.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;init.config.ble_adv_on_disconnect_disabled did the trick.&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disconnect and stop advertising after transaction</title><link>https://devzone.nordicsemi.com/thread/164299?ContentTypeID=1</link><pubDate>Mon, 07 Jan 2019 14:13:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a827471-7437-49ef-8627-7a1ec60fbc27</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The device will not go to power off unless you specifically tell it to. In our examples, this is typically done in a function called&amp;nbsp;sleep_mode_enter(), which calls sd_power_system_off(), which will put the device in &amp;quot;deep sleep&amp;quot; mode (basically turning it off). The only way to recover is by either a pin interrupt, power cycle, or the NFC. So if it is possible with your accelerometer to toggle a pin on movement, you can go to deep sleep, but if it suits your application to not go to system-off mode, you don&amp;#39;t need to do this call (sd_power_system_off())&amp;nbsp;.&lt;/p&gt;
&lt;p&gt;Other than this, your approach sounds quite straight forward. You need to advertise, scan with the connecting device, and wait for them to connect. When they are connected, send the data that you need to send, and wait for the reply. If you need the reply message, you can wait for it, but if you only use the reply to verify that the data was sent successfully, you can also wait for the&amp;nbsp;BLE_GATTS_EVT_HVN_TX_COMPLETE event (you must add this to your event handler). When you have received this event the same number of times as messages you have sent, you know that all of the messsages has been ACKed. When this happens, disconnect.&lt;/p&gt;
&lt;p&gt;Note that depending on your advertisement settings, the device will automatically start to advertise on the&amp;nbsp;BLE_GAP_EVT_DISCONNECTED event. This is triggered in the on_disconnected() function in ble_advertising.c (the name may depend on the SDK version that you are using. You can change this in the advertising_init function on main.c. Note that these variables may have changed, but in SDK15.2.0 it is done like this (the advertising_init() function is from the ble_app_uart example):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function for initializing the Advertising functionality.
 */
static void advertising_init(void)
{
    uint32_t               err_code;
    ble_advertising_init_t init;

    memset(&amp;amp;init, 0, sizeof(init));

    init.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    init.advdata.include_appearance = false;
    init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;

    init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.srdata.uuids_complete.p_uuids  = m_adv_uuids;

    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;
    init.config.ble_adv_on_disconnect_disabled = true;      //ADD THIS LINE TO PREVENT ADVERTISING ON THE DISCONNECTED EVENT

    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;&lt;/p&gt;
&lt;p&gt;Now you just need to wait for your interrupt from the accelerometer to start advertising again.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>