<?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>Clear GATT Cache</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/72117/clear-gatt-cache</link><description>I have a sensor that uses 3 different BLE mechanisms. It is part of a mesh, it sometimes sends beacons and it provides GATT services in a peripheral role. The project I&amp;#39;m working on needs to connect to this sensor. So, I set up a filter that filters on</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 01 Mar 2021 14:30:57 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/72117/clear-gatt-cache" /><item><title>RE: Clear GATT Cache</title><link>https://devzone.nordicsemi.com/thread/296902?ContentTypeID=1</link><pubDate>Mon, 01 Mar 2021 14:30:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5f387669-629a-45e4-8038-4551c3958778</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;What SDK are you using? nRF5 SDK or NCS (nRF Connect SDK)? And what release version?&lt;/p&gt;
&lt;p&gt;My guess is that you are using the nRF5 SDK, is that correct?&lt;/p&gt;
&lt;p&gt;In our examples, the&amp;nbsp;&lt;span&gt;NRF_BLE_SCAN_EVT_NOT_FOUND event is not really used for anything. It really just means that an advertising report was found, but it didn&amp;#39;t match your filter. It has no recognition of previous advertisements from the same device. So unless you need this event, I suggest you remove it from your scan event handler (don&amp;#39;t use case: NRF_BLE_SCAN_EVT_NOT_FOUND).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The event that you are actually looking for is the NRF_BLE_SCAN_EVT_FILTER_MATCH, which will occur if you actually get a match on your filters. But if you have the nrf_ble_scan_connect_with_target() in the event handler, you don&amp;#39;t really need this either. Look at the end of the&amp;nbsp;nrf_ble_scan_on_adv_report() in nrf_ble_scan.c:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    // In the multifilter mode, the number of the active filters must equal the number of the filters matched to generate the notification.
    if (all_filter_mode &amp;amp;&amp;amp; (filter_match_cnt == filter_cnt))
    {
        scan_evt.scan_evt_id = NRF_BLE_SCAN_EVT_FILTER_MATCH;
        nrf_ble_scan_connect_with_target(p_scan_ctx, p_adv_report);
    }
    // In the normal filter mode, only one filter match is needed to generate the notification to the main application.
    else if ((!all_filter_mode) &amp;amp;&amp;amp; is_filter_matched)
    {
        scan_evt.scan_evt_id = NRF_BLE_SCAN_EVT_FILTER_MATCH;
        nrf_ble_scan_connect_with_target(p_scan_ctx, p_adv_report);
    }
    else
    {
        scan_evt.scan_evt_id        = NRF_BLE_SCAN_EVT_NOT_FOUND;
        scan_evt.params.p_not_found = p_adv_report;

    }&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Most of our examples, such as the ble_app_uart_c doesn&amp;#39;t use any of these events. Looking at this example, the scan_evt_handler() only checks for a few events:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&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_CONNECTING_ERROR:
         {
              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.
         } break;

         case NRF_BLE_SCAN_EVT_SCAN_TIMEOUT:
         {
             NRF_LOG_INFO(&amp;quot;Scan timed out.&amp;quot;);
             scan_start();
         } break;

         default:
             break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;End neither of them are&amp;nbsp;&lt;span&gt;NRF_BLE_SCAN_EVT_NOT_FOUND nor NRF_BLE_SCAN_EVT_FILTER_MATCH. As you can see, the on_adv_report() function calls nrf_ble_scan_connect_with_target().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So exactly what is not working sometimes? It doesn&amp;#39;t connect? Are you sure that the device you are trying to connect to is advertising at that point in time?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best Regards,&lt;br /&gt;Edvin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>