<?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>scan to connect to a specified address</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81324/scan-to-connect-to-a-specified-address</link><description>Hello, 
 SD: 122 
 part nrf52833 
 
 I need to do the following: 
 a. scan for advertisements containing a particular MAC address without connecting. This works. 
 b. the scanned MAC addresses are reviewed by another MCU. This works. 
 c. if the MAC address</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 04 Nov 2021 14:31:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81324/scan-to-connect-to-a-specified-address" /><item><title>RE: scan to connect to a specified address</title><link>https://devzone.nordicsemi.com/thread/337525?ContentTypeID=1</link><pubDate>Thu, 04 Nov 2021 14:31:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4dfad4e5-c557-4c53-aeba-3adbcac75704</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;If you want to modify this during runtime, I suspect that the simplest way would be to handle this in your main.c file, and let nrf_ble_scan.c remain unchanged. This was the way it was done in the earlier versions of the SDK (don&amp;#39;t remember what version that changed it).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Try to add the&amp;nbsp;BLE_GAP_EVT_ADV_REPORT event to your ble_evt_handler() in main.c, and handle the incoming advertising packets there as well. In this case, you can keep a custom array of the whitelisted addresses that are approved by your host.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Something like: (pseudo)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ret_code_t            err_code;
    ble_gap_evt_t const * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
        ...
        
        case BLE_GAP_EVT_ADV_REPORT:
        if (address_is_approved_by_host(p_ble_evt-&amp;gt;...address))
        {
            err_code = sd_ble_gap_connect(..., address);
            APP_ERRORO_CHECK(err_code);
        }&lt;/pre&gt;&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><item><title>RE: scan to connect to a specified address</title><link>https://devzone.nordicsemi.com/thread/337479?ContentTypeID=1</link><pubDate>Thu, 04 Nov 2021 12:58:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e999e2d-d36c-490c-b19e-98f1c2f9299a</guid><dc:creator>DanPhelan</dc:creator><description>&lt;p&gt;Edvin,&lt;/p&gt;
&lt;p&gt;Thanks for your suggestions.&amp;nbsp; I found that one of my modifications to nrf_ble_scan.c was most of the problem.I do not want the Scan to automatically connect at first pass which it seems to do when scanning with the&amp;nbsp;NRF_BLE_SCAN_EVT_FILTER_MATCH and &amp;quot;connect_if_match&amp;quot; set to false.&amp;nbsp; I added in an If statement as shown&lt;/p&gt;
&lt;p&gt;below so that the connection only ccurs when the filter on Address and connect if match are true.&amp;nbsp; Is this the best way to do it?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The goal is to first scan the first three characters of the Address to match our company ID, then send any found advertisements to a host.&amp;nbsp; The host will then decide to request a scan with a connect.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Dan&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1636030409561v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: scan to connect to a specified address</title><link>https://devzone.nordicsemi.com/thread/337471?ContentTypeID=1</link><pubDate>Thu, 04 Nov 2021 12:49:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97059fa5-34c2-4a41-9986-9910d29d6af4</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;First of all, does all the APP_ERROR_CHECK()&amp;#39;s in the snippet that you provided succeed? (are all the err_code == 0?)&lt;/p&gt;
&lt;p&gt;Have you tried to debug the&amp;nbsp;nrf_ble_scan_on_adv_report() in nrf_ble_scan.c? See what&amp;nbsp;adv_addr_compare() returns in an advertising packet that you know comes from the correct device, and why it doesn&amp;#39;t return true. Is the filter not enabled as you suspect? Is the address stored properly in the filter? Did you store it in the correct byte order?&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>