<?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>S130 Permanent Advertising &amp;amp; Scanning during operation</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14643/s130-permanent-advertising-scanning-during-operation</link><description>Hi! 
 We&amp;#39;re running a S130 Stack to act as both Peripheral &amp;amp; Central at the same time. Everything is working fine but i i&amp;#39;m not quite sure about best approach for handling permanent scanning &amp;amp; advertising at the same time. 
 The question is:
After</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 22 Jun 2016 10:45:33 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14643/s130-permanent-advertising-scanning-during-operation" /><item><title>RE: S130 Permanent Advertising &amp; Scanning during operation</title><link>https://devzone.nordicsemi.com/thread/55878?ContentTypeID=1</link><pubDate>Wed, 22 Jun 2016 10:45:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a3942e0-dccf-45c9-9d8a-c14f709ba990</guid><dc:creator>Michael Mangeng</dc:creator><description>&lt;p&gt;Thanks for the exact answer!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: S130 Permanent Advertising &amp; Scanning during operation</title><link>https://devzone.nordicsemi.com/thread/55877?ContentTypeID=1</link><pubDate>Wed, 22 Jun 2016 07:13:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0d23acdb-2877-4fb5-965e-b68af9f6a444</guid><dc:creator>FormerMember</dc:creator><description>&lt;blockquote&gt;
&lt;p&gt;The question is: After which BLE-Events
do i have to restart scanning /
advertising? (With scan / adv timeout
= 0 and scan/adv timeout != 0).&lt;/p&gt;
&lt;p&gt;E.g. Do i have to start scanning/adv
after connection established? Do i
have to start scanning/adv after data
written? Do i have to start
scanning/adv after disconnect event?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Advertiser:&lt;/strong&gt; When a device is advertising connectable advertising, the device will stop advertising when a connection has been initiated by a peer device, meaning that it receives a connect request. The application will be notified the a connection has been initiated when receiving the BLE_GAP_EVT_CONNECTED event. The below figure explains what happens when a connectable advertiser receives a connection request.&lt;/p&gt;
&lt;p&gt;If you want the device to continue to advertise non-connectable advertising after the connection has been established, advertising has to be started manually.&lt;/p&gt;
&lt;p&gt;If the advertiser has a timeout, the application will receive the event BLE_GAP_EVT_TIMEOUT, see &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s130.api.v2.0.0%2Fgroup___b_l_e___g_a_p___a_d_v___m_s_c.html&amp;amp;cp=3_6_2_1_0_2_1_3_0"&gt;this&lt;/a&gt; message sequence chart.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/connection_5F00_initiation.PNG" alt="image description" /&gt;&lt;/p&gt;
&lt;p&gt;The device will not automatically (re-)start advertising after disconnecting. If the device should start advertising after a disconnect, advertising has to be started manually.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Scanner:&lt;/strong&gt; Similar to the advertiser, a scanner will stop scanning after having initiated a connection. If the scanner wants to continue scanning after a connection has been initiated, it has to be started manually. The ble_app_multilink_central example in the SDK does that.&lt;/p&gt;
&lt;p&gt;If scanning times out, the application will receive a BLE_GAP_EVT_TIMEOUT{BLE_GAP_TIMEOUT_SRC_SCAN} event, see &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s130.api.v2.0.0%2Fgroup___b_l_e___g_a_p___s_c_a_n___m_s_c.html&amp;amp;cp=3_6_2_1_0_2_1_3_11"&gt;this&lt;/a&gt; message sequence chart.&lt;/p&gt;
&lt;p&gt;Scanning and disconnection of a link are independent* operations, it is no problem to scan and have multiple links at the same time.&lt;/p&gt;
&lt;p&gt;*Scanning and disconnection of a link are independent as long as the number of links and roles are not maximized. S130/S132 v.2.0.x supports up to eight links concurrently along with either scanner or broadcaster.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;... And: is there a possibility to ask the stack whether scanning or advertising is currently active?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;There is no function for asking the stack if it is scanning/advertising or not. However, since scanning and advertising have to be started manually and since they will only stop scanning/advertising on known cases, two variables, is_scanning and is_advertising, can for example easily keep track of the advertising/scanning state.&lt;/p&gt;
&lt;p&gt;Advertising and scanning can stop in the following cases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Connected (BLE_GAP_EVT_CONNECTED)&lt;/li&gt;
&lt;li&gt;Manually calling sd_ble_gap_adv_stop()/sd_ble_gap_scan_stop()&lt;/li&gt;
&lt;li&gt;Timeout: BLE_GAP_EVT_TIMEOUT occurs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you plan to combine multiple roles for the device in your application, I would recommend you to take a look at &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s130.sds%2Fdita%2Fsoftdevices%2Fs130%2Fmultilink_scheduling%2Fmultilink_scheduling.html&amp;amp;cp=3_6_2_0_14"&gt;the scheduling chapter in the S130 softdevice specification&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>