<?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>Can not stop advertising in BLE event handler</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/3580/can-not-stop-advertising-in-ble-event-handler</link><description>I tried code like 
 static void on_ble_evt(ble_evt_t * p_ble_evt)
{
....
 case BLE_GAP_EVT_TIMEOUT:
 if (p_ble_evt-&amp;gt;evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT)
 {	
 err_code = sd_ble_gap_adv_stop(); // Stop advertising</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 23 Aug 2014 08:12:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/3580/can-not-stop-advertising-in-ble-event-handler" /><item><title>RE: Can not stop advertising in BLE event handler</title><link>https://devzone.nordicsemi.com/thread/12977?ContentTypeID=1</link><pubDate>Sat, 23 Aug 2014 08:12:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:521ca022-4323-4fe9-9d07-7ffbe98b3295</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;When you configure advertising timeout with adv_params.timeout when you start advertising with sd_ble_gap_adv_start(&amp;amp;adv_params) it means that after this interval of time if no one connect to your device then it&amp;#39;ll stop advertising automatically.&lt;/p&gt;
&lt;p&gt;When you meet condition (p_ble_evt-&amp;gt;evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT) it meens that advertising has timed out and stopped. So you get NRF_ERROR_INVALID_STATE because advertising already stopped when you call sd_ble_gap_adv_stop().&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>