<?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>Connect to peripheral while scanning is active with nrf Connect SDK</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/99197/connect-to-peripheral-while-scanning-is-active-with-nrf-connect-sdk</link><description>We&amp;#39;ve migrated our radio application from the nrf52832 based on the nRF5x SDK with the S332 softdevice to the nrf5340 based on the nrf Connect SDK (v2.2.0). In the old application, our device could connect to a HR belt using the sd_ble_gap_connect() function</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 28 Apr 2023 13:02:39 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/99197/connect-to-peripheral-while-scanning-is-active-with-nrf-connect-sdk" /><item><title>RE: Connect to peripheral while scanning is active with nrf Connect SDK</title><link>https://devzone.nordicsemi.com/thread/422993?ContentTypeID=1</link><pubDate>Fri, 28 Apr 2023 13:02:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:80e05919-19f5-4a70-af50-6875b56c446a</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;This is handled a bit differently in different samples. Some will set a scan filter which will automatically connect to a device if the filter matches, so you don&amp;#39;t see it that clear, but if you have a look at the &amp;quot;NCS\zephyr\samples\bluetooth\central&amp;quot; sample you can see that it will get a callback on all advertising reports, and try to connect to it as long as the RSSI is higher than -70. Right before it calls bt_conn_le_create() it will call bt_le_scan_stop(), probably because of what you are seeing.&lt;/p&gt;
&lt;p&gt;So try to use bt_le_scan_stop() right before you connect, and then you can resume scanning after you have connected.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The reason it is implemented like this is (probably) because in order to connect, the device needs to scan to pick up the next advertisement packet from that device.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Remember to set&amp;nbsp;&lt;/p&gt;
&lt;p&gt;CONFIG_BT_MAX_CONN=2&lt;/p&gt;
&lt;p&gt;if you want to allow the device to be in connection with one device, and then start scanning. Or set it even higher if you want more connections. Set it to N+1, where N is the number of concurrent connections you need to allow while also scanning.&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>