<?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>nRF52840DK as central cannot establish a connection to a peripheral anymore</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/99278/nrf52840dk-as-central-cannot-establish-a-connection-to-a-peripheral-anymore</link><description>Hello. 
 In my current project I have a nRF52840DK as central and multiple nrf52832 on custom boards as peripherals. This worked fine until a few days ago. 
 I am currently facing a bit of a weird behaviour. As my central device do not establish a connection</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 03 May 2023 14:10:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/99278/nrf52840dk-as-central-cannot-establish-a-connection-to-a-peripheral-anymore" /><item><title>RE: nRF52840DK as central cannot establish a connection to a peripheral anymore</title><link>https://devzone.nordicsemi.com/thread/423601?ContentTypeID=1</link><pubDate>Wed, 03 May 2023 14:10:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ac09939-bbdf-4a93-9145-9823306400d8</guid><dc:creator>Sigurd</dc:creator><description>[quote user="Michael111"]This means, that I am indeed scanning. But there is a problem with my filters, right?[/quote]
&lt;p&gt;Correct!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840DK as central cannot establish a connection to a peripheral anymore</title><link>https://devzone.nordicsemi.com/thread/423361?ContentTypeID=1</link><pubDate>Tue, 02 May 2023 15:16:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:921fd559-ef67-4881-a08f-1a37a598a80c</guid><dc:creator>Michael111</dc:creator><description>&lt;p&gt;Hello Sigurd,&lt;/p&gt;
&lt;p&gt;thanks for the help so far.&lt;/p&gt;
&lt;p&gt;I&amp;nbsp;modified the scan_evt_handler, so that I can log every event.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Function for handling Scanning Module events.
 */
static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{
    ret_code_t err_code;

    switch(p_scan_evt-&amp;gt;scan_evt_id)
    {
        case NRF_BLE_SCAN_EVT_WHITELIST_REQUEST:
        {
            NRF_LOG_INFO(&amp;quot;NRF_BLE_SCAN_EVT_WHITELIST_REQUEST&amp;quot;);
            on_whitelist_req();
            m_whitelist_disabled = false;
        } break;
         
        case NRF_BLE_SCAN_EVT_CONNECTING_ERROR:
        {
            NRF_LOG_INFO(&amp;quot;NRF_BLE_SCAN_EVT_CONNECTING_ERROR&amp;quot;);
            err_code = p_scan_evt-&amp;gt;params.connecting_err.err_code;
            APP_ERROR_CHECK(err_code);
        } break;

        case NRF_BLE_SCAN_EVT_CONNECTED:
        {
            ble_gap_evt_connected_t const * p_connected =
                           p_scan_evt-&amp;gt;params.connected.p_connected;
                           // Scan is automatically stopped by the connection.
                           NRF_LOG_INFO(&amp;quot;Connecting to target %02x%02x%02x%02x%02x%02x&amp;quot;,
                                    p_connected-&amp;gt;peer_addr.addr[0],
                                    p_connected-&amp;gt;peer_addr.addr[1],
                                    p_connected-&amp;gt;peer_addr.addr[2],
                                    p_connected-&amp;gt;peer_addr.addr[3],
                                    p_connected-&amp;gt;peer_addr.addr[4],
                                    p_connected-&amp;gt;peer_addr.addr[5]
                                    );
        } break;
        
        case NRF_BLE_SCAN_EVT_FILTER_MATCH:
        {
            NRF_LOG_INFO(&amp;quot;NRF_BLE_SCAN_EVT_FILTER_MATCH&amp;quot;);
            break;
        }

        case NRF_BLE_SCAN_EVT_WHITELIST_ADV_REPORT:
        {
           NRF_LOG_INFO(&amp;quot;NRF_BLE_SCAN_EVT_WHITELIST_ADV_REPORT&amp;quot;);
           ble_gap_evt_connected_t const * p_connected = p_scan_evt-&amp;gt;params.connected.p_connected;
           // Scan is automatically stopped by the connection.
           if(cli_activated)
           {
            nrf_fprintf(m_cli_uart.p_fprintf_ctx, &amp;quot;Address: %02x %02x %02x %02x %02x %02x\r&amp;quot; ,p_connected-&amp;gt;peer_addr.addr[0],  p_connected-&amp;gt;peer_addr.addr[1],
            p_connected-&amp;gt;peer_addr.addr[2],  p_connected-&amp;gt;peer_addr.addr[3],  p_connected-&amp;gt;peer_addr.addr[4], p_connected-&amp;gt;peer_addr.addr[5]);  
           }      
        }  break;

        
        case NRF_BLE_SCAN_EVT_SCAN_TIMEOUT:
        {
           NRF_LOG_INFO(&amp;quot;Scan timed out.&amp;quot;);
           scan_start();
        } break;

        case NRF_BLE_SCAN_EVT_NOT_FOUND:
        {
            NRF_LOG_INFO(&amp;quot;NRF_BLE_SCAN_EVT_NOT_FOUND&amp;quot;);
        } break;

        default:
           break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;My result is:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: NRF_BLE_SCAN_EVT_WHITELIST_REQUEST
&amp;lt;info&amp;gt; app: Peer Count: 0
&amp;lt;info&amp;gt; app: Scan Address Count: 0
&amp;lt;info&amp;gt; app: NRF_BLE_SCAN_EVT_NOT_FOUND
&amp;lt;info&amp;gt; app: NRF_BLE_SCAN_EVT_NOT_FOUND
&amp;lt;info&amp;gt; app: NRF_BLE_SCAN_EVT_NOT_FOUND
&amp;lt;info&amp;gt; app: NRF_BLE_SCAN_EVT_NOT_FOUND
&amp;lt;info&amp;gt; app: NRF_BLE_SCAN_EVT_NOT_FOUND
&amp;lt;info&amp;gt; app: NRF_BLE_SCAN_EVT_NOT_FOUND
&amp;lt;info&amp;gt; app: NRF_BLE_SCAN_EVT_NOT_FOUND
&amp;lt;info&amp;gt; app: NRF_BLE_SCAN_EVT_NOT_FOUND
&amp;lt;info&amp;gt; app: NRF_BLE_SCAN_EVT_NOT_FOUND
&amp;lt;info&amp;gt; app: NRF_BLE_SCAN_EVT_NOT_FOUND&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This means, that I am indeed scanning. But there is a problem with my filters, right?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840DK as central cannot establish a connection to a peripheral anymore</title><link>https://devzone.nordicsemi.com/thread/423344?ContentTypeID=1</link><pubDate>Tue, 02 May 2023 14:19:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:be63c248-734c-42a1-97eb-65c1073064fa</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="Michael111"]2) No. But it is part auf our application to scan basically indefinetly. So this would not be triggered.[/quote]
&lt;p&gt;If the filter matching is enabled and no filter is matched, NRF_BLE_SCAN_EVT_NOT_FOUND is generated. So if you have BLE devices around you, and this is not triggering, this could indicate that you are not scanning.&lt;/p&gt;
&lt;p&gt;Could you add some logging to your&amp;nbsp;scan_evt_handler(), and see what events are generated ?&lt;/p&gt;
&lt;p&gt;(&lt;span&gt;scan_evt_handler =&amp;nbsp;&lt;/span&gt;The event handler that is registered when you called nrf_ble_scan_init())&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840DK as central cannot establish a connection to a peripheral anymore</title><link>https://devzone.nordicsemi.com/thread/423281?ContentTypeID=1</link><pubDate>Tue, 02 May 2023 12:07:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1883d5a0-29e1-4498-a535-d4466a8ae5c4</guid><dc:creator>Michael111</dc:creator><description>&lt;p&gt;Hello Sigurd.&lt;br /&gt;Thank you very much for your reply.&lt;/p&gt;
&lt;p&gt;1) Unfortunately, I cannot post my full main.c file, as it is large and part of a product. But I think I narrowed the problem down a bit to the following code part:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void whitelist_load()
{
    ret_code_t   ret;
    pm_peer_id_t peers[8];
    uint32_t     peer_cnt;

    memset(peers, PM_PEER_ID_INVALID, sizeof(peers));
    peer_cnt = (sizeof(peers) / sizeof(pm_peer_id_t));

    // Load all peers from flash and whitelist them.
    peer_list_get(peers, &amp;amp;peer_cnt);

    NRF_LOG_INFO(&amp;quot;Peer Count: %d&amp;quot;,peer_cnt)

    ret = pm_whitelist_set(peers, peer_cnt);
    APP_ERROR_CHECK(ret);

    // Setup the device identies list.
    // Some SoftDevices do not support this feature.
    ret = pm_device_identities_list_set(peers, peer_cnt);
    if (ret != NRF_ERROR_NOT_SUPPORTED)
    {
        APP_ERROR_CHECK(ret);
    }
}



static void on_whitelist_req(void)
{
    ret_code_t err_code;

    // Whitelist buffers.
    ble_gap_addr_t whitelist_addrs[8];
    ble_gap_irk_t  whitelist_irks[8];

    memset(whitelist_addrs, 0x00, sizeof(whitelist_addrs));
    memset(whitelist_irks,  0x00, sizeof(whitelist_irks));

    uint32_t addr_cnt = (sizeof(whitelist_addrs) / sizeof(ble_gap_addr_t));
    uint32_t irk_cnt  = (sizeof(whitelist_irks)  / sizeof(ble_gap_irk_t));

    // Reload the whitelist and whitelist all peers.
    whitelist_load();

    // Get the whitelist previously set using pm_whitelist_set().
    err_code = pm_whitelist_get(whitelist_addrs, &amp;amp;addr_cnt,
                                whitelist_irks,  &amp;amp;irk_cnt);

    NRF_LOG_INFO(&amp;quot;Scan Address Count: %d&amp;quot;, addr_cnt)
    for (int i = 0; i &amp;lt; addr_cnt; i++) {
      NRF_LOG_INFO(&amp;quot;Scanning for address: %02X %X %X %X %X %X \n&amp;quot;, whitelist_addrs[i].addr[5],
                  whitelist_addrs[i].addr[4], whitelist_addrs[i].addr[3], whitelist_addrs[i].addr[2],
                  whitelist_addrs[i].addr[1], whitelist_addrs[i].addr[0]);
    }

    if (((addr_cnt == 0) &amp;amp;&amp;amp; (irk_cnt == 0)) ||
        (m_whitelist_disabled))
    {
    // Don&amp;#39;t use whitelist.
        err_code = nrf_ble_scan_params_set(&amp;amp;m_scan, NULL);
        APP_ERROR_CHECK(err_code);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In our application the ble adresses of the peripherals are saved in the flash. When we boot up the central device, the ble adresses got read from the flash and applied to the whitelist. It seems like that this the problem. Since I receive&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: Peer Count: 0
&amp;lt;info&amp;gt; app: Scan Address Count: 0&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;when I run the code. Maybe you can take a look to this code snippet.&lt;/p&gt;
&lt;p&gt;2) No. But it is part auf our application to scan basically indefinetly. So this would not be triggered.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840DK as central cannot establish a connection to a peripheral anymore</title><link>https://devzone.nordicsemi.com/thread/423226?ContentTypeID=1</link><pubDate>Tue, 02 May 2023 09:32:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2175c17d-0f1e-45cb-94c8-4f9d3c1f82da</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;1) Could you post your main.c file?&lt;/p&gt;
&lt;p&gt;2) Are you getting the event&amp;nbsp;NRF_BLE_SCAN_EVT_NOT_FOUND&amp;nbsp; in your&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;scan_evt_handler?&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840DK as central cannot establish a connection to a peripheral anymore</title><link>https://devzone.nordicsemi.com/thread/423223?ContentTypeID=1</link><pubDate>Tue, 02 May 2023 09:24:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e23fa59-4a85-4739-bb01-c12a159d0954</guid><dc:creator>Michael111</dc:creator><description>&lt;p&gt;nRF5 SDK 17&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840DK as central cannot establish a connection to a peripheral anymore</title><link>https://devzone.nordicsemi.com/thread/423222?ContentTypeID=1</link><pubDate>Tue, 02 May 2023 09:23:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b492138c-db36-4b37-b53f-89f3a9be2945</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;What SDK are you using ? nRF Connect SDK or nRF5-SDK?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>