<?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>Prevent SD from Automatically Advertising after Disconnection</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/8841/prevent-sd-from-automatically-advertising-after-disconnection</link><description>I have an NRF51 board running as a GATT server. Using an iOS application (LightBlue) I connect to the NRF51. If I quit the iOS application then I get a disconnect event and the NRF51 starts to automatically begin advertising again. I do not want the NRF51</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 25 Aug 2015 18:31:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/8841/prevent-sd-from-automatically-advertising-after-disconnection" /><item><title>RE: Prevent SD from Automatically Advertising after Disconnection</title><link>https://devzone.nordicsemi.com/thread/32510?ContentTypeID=1</link><pubDate>Tue, 25 Aug 2015 18:31:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5f75aa64-143c-44ea-9266-7e8ead94a5c6</guid><dc:creator>F</dc:creator><description>&lt;p&gt;I was under the mistaken impression that your code was destined for the ble event handler for the disconnection event.  Placing in ble_advertising.c makes makes your code make sense now--and even better, it works as advertised (pardon the semi-intentional pun).&lt;/p&gt;
&lt;p&gt;Thanks for the help.&lt;/p&gt;
&lt;p&gt;-F&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Prevent SD from Automatically Advertising after Disconnection</title><link>https://devzone.nordicsemi.com/thread/32509?ContentTypeID=1</link><pubDate>Tue, 25 Aug 2015 08:01:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64bce25e-ae44-448d-8ff3-bb66edbb1d96</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;I think you must &amp;quot;hack&amp;quot; the ble_advertising.c in order to not restart the advertising on disconnect. The function above is the one starting the advertising with call to&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ble_advertising_start(BLE_ADV_MODE_DIRECTED);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;this call you can see in the original ble_app_hrs example. I have replaced it with the code above. The code above calls the registered event handler in main.c, i.e. the on_adv_evt in main.c. It is actually in on_adv_evt that the chip is put to System Off mode with call to sleep_mode_enter(). Before calling sleep_mode_enter(), you can perform your LED operation.&lt;/p&gt;
&lt;p&gt;If you change the ble_advertising.c file, it is a good practice to place it in your project folder, in order to have the library files unmodified.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Prevent SD from Automatically Advertising after Disconnection</title><link>https://devzone.nordicsemi.com/thread/32508?ContentTypeID=1</link><pubDate>Mon, 24 Aug 2015 21:08:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c67a927-1771-4327-bb26-80e66917460f</guid><dc:creator>F</dc:creator><description>&lt;p&gt;Thanks for the reply.  Couple questions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;m_adv_evt and m_whitelist_temporarily_disabled are statically defined in ble_advertising.h.  How can I use them in main.c without hacking ble_advertising.c where they are declared static?&lt;/li&gt;
&lt;li&gt;Which function is restarting the advertisement on a disconnection event?  Is this being internally done by the softdevice?&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;My problem with the solution is that I have a short LED animation I need to perform before the system shuts down.  I do not want the system to be advertising while it is shutting down.  My workaround works, but there is a (very) short period of time that advertising is active before the advertising event handler is called and I shut off the advertising.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Prevent SD from Automatically Advertising after Disconnection</title><link>https://devzone.nordicsemi.com/thread/32507?ContentTypeID=1</link><pubDate>Mon, 24 Aug 2015 17:20:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71a540b9-b3a6-410d-9b57-ef0a73939e1a</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you are using e.g. ble_app_hrs (heart rate example) then you will get a callback in your nRF51 application when you disconnect.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This callback will enter the ble_evt_dispatch function in the main.c file. The dispatcher will direct the BLE calls to different modules, including the advertising module, with call to ble_advertising_on_ble_evt function in the advertising module.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the ble_advertising_on_ble_evt function, there is a switch statement BLE_GAP_EVT_DISCONNECTED, which is entered upon disconnect.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Instead of starting starting advertising in BLE_ADV_MODE_DIRECTED, as done in the ble_app_hrs example, just set the advertising module into the idle state with the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  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)
  		{
  			 m_adv_evt = BLE_ADV_EVT_IDLE;
  			 m_evt_handler(m_adv_evt);
  		}
  		break;
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then the advertising module will call the registered callback handler in main.c (which was registered in call to advertising_init() in the main function). The callback handler (on_adv_evt) calls sleep_mode_enter() which makes the chip enter System Off mode and shuts down all LED activity on the development board.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>