The NRF52840 can not filter by MAC Address other BLE devices that are from other manufacturers.

Hi all!

I am working in a BLE scanner but I have enabled the filter by MAC ADDRESS.  I can filter  beacons that are produced  based in NRF52 and NRF51. But when i try set a MAC ADDRESS of a SOC produced by other company  the filter no match.

wich could be the problem?

Parents
  • Hi eudaldo!

    That should not happen at all. May I ask how you set up the other company device? Are you certain it is advertising? Can you see it on your phone, for example, with the nRF Connect app?

    Best regards,

    Hieu

  • I store the MAC ADDRESS in array of char, I put them in reverse (LSB  --> MSB) attach an example:

    char target_device[][6] = {
    {0x96, 0xEA, 0x57, 0x6E, 0x91, 0xDF},
    {0x13, 0x48, 0x35, 0x79, 0xBE, 0xEB},
    {0x68, 0xDA, 0xFC, 0x71, 0x77, 0x60},
    {0xBF, 0x92, 0xD9, 0x70, 0xAF, 0xFD},
    {0x8C, 0x4B, 0x7A, 0xD6, 0xAB, 0xFE},
    {0x0E, 0x2B, 0xE6, 0x5A, 0xA8, 0xE7},
    {0xC3, 0x6B, 0xD2, 0x56, 0x79, 0xEB}
    };

    I have try put the MAC ADDRESS in the normal form (MSB--->LSB), but it does not work.

    For set the filter I use the following code:

     //Setting filters for scanning.
    
    
        int rows =  sizeof (target_device) / 6;
    
        for (int t=0 ; t<rows; t++)
        {
              char td[] = { target_device[t][0],target_device[t][1]  ,target_device[t][2]  ,target_device[t][3] ,target_device[t][4]  ,target_device[t][5]};
              
              err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_ADDR_FILTER, td);
              
              APP_ERROR_CHECK(err_code);    
        }
    
       
         err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_ADDR_FILTER, false);
         APP_ERROR_CHECK(err_code);

    I attach the devices that I want to scan:

  • I think the address being flipped is just some not-obvious problem in extracting the data. In any cases, NRF_BLE_SCAN_EVT_NOT_FOUND means that the application never sees that beacon at all.
    Also, if you could share how you extract the addresses out of the events, I can look into why addresses are flipped/not flipped.

    I misspoke, in the handler function scan_evt_handler I print via UART the MAC ADDRESS of the device, both  NRF_BLE_SCAN_EVT_NOT_FOUND and NRF_BLE_SCAN_EVT_FILTER_MATCH, but when I print them,  I flip them :

    static void scan_evt_handler(scan_evt_t const * p_scan_evt)
    {
        ret_code_t err_code;
        char data_hex[10];
        char len[10];
        
    
        switch(p_scan_evt->scan_evt_id)
        {
    
            case NRF_BLE_SCAN_EVT_NOT_FOUND:           
    
    
                    unsigned char* addr       =  p_scan_evt->params.p_not_found->peer_addr.addr;      
                    
                   
    
                    uart_putstring("NFND:");
    
                    for (int a=5; a>=0; a--)
                    {
                      sprintf(data_hex,"%02x", addr[a] );
                      uart_putstring(data_hex);
                        
                    }
    
                    uart_putstring("\r\n");
                    
                }
                
    
            break;
    
    
    
            //  FILTER MATCH
            case NRF_BLE_SCAN_EVT_FILTER_MATCH:
    
                  
    
                 uint8_t *addr =  p_scan_evt->params.filter_match.p_adv_report->peer_addr.addr;      
                 
                    uart_putstring("ADDR:");
    
                    for (int a=5; a>=0; a--)
                    {
                      sprintf(data_hex,"%02x",addr[a] );
                      uart_putstring(data_hex);
                       
                    }
                    
                    uart_putstring("\r\n");
                    
                 
               break;
    
    
            
            default:
            break;
    
        }
    }

    the results are the follow (an example):

    NFND:1804ED65A2EE   //Not found
    ADDR:DF916E57EA97   //Filter match
    ADDR:607771FCDA68   //Filter match

    However, it could be that the scanning timeout'd before it sees Beacon 3. Or the timeout might seems enough for 2-3 advertising interval, but the scanner still could (very) unfortunately miss the packets.
    How do you setup the scan itself, as in how do your scanning init and start function calls look like?

    these are my functions:

    scan_params:

    #define SCAN_INTERVAL                   0x00A0                              /**< Determines scan interval in units of 0.625 millisecond. */
    #define SCAN_WINDOW                     0x009f                              /**< Determines scan window in units of 0.625 millisecond. */
    #define SCAN_DURATION                   0x0000                              /**< Timout when scanning. 0x0000 disables timeout. */
    
    #define MIN_CONNECTION_INTERVAL         MSEC_TO_UNITS(7.5, UNIT_1_25_MS)    /**< Determines minimum connection interval in milliseconds. */
    #define MAX_CONNECTION_INTERVAL         MSEC_TO_UNITS(30, UNIT_1_25_MS)     /**< Determines maximum connection interval in milliseconds. */
    #define SLAVE_LATENCY                   0                                   /**< Determines slave latency in terms of connection events. */
    #define SUPERVISION_TIMEOUT             MSEC_TO_UNITS(4000, UNIT_10_MS)     /**< Determines supervision time-out in units of 10 milliseconds. */
    
    #define APP_BLE_CONN_CFG_TAG            1                                   /**< A tag identifying the SoftDevice BLE configuration. */
    #define APP_BLE_OBSERVER_PRIO           3 
    
    
    
    static ble_gap_scan_params_t const m_scan_param =
    	{
    		.active        = 0x00,
    		.interval      = SCAN_INTERVAL,
    		.window        = SCAN_WINDOW,
    		.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
    		.timeout       = SCAN_DURATION,
    		.scan_phys     = BLE_GAP_PHY_AUTO,
    		.extended      = false,
    	};

    scan_init  (in my previous comment , I write about it and the variables):

    static void scan_init(void)
    {
        ret_code_t          err_code;
        nrf_ble_scan_init_t init_scan;
    
        memset(&init_scan, 0, sizeof(init_scan));
    
        init_scan.connect_if_match = false;
        init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;
        init_scan.p_scan_param     = &m_scan_param;
    
        
    
        err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
        APP_ERROR_CHECK(err_code);
    
        //Setting filters for scanning.
    
    
        int rows =  sizeof (target_device) / 6;
    
        for (int t=0 ; t<rows; t++)
        {
              char td[] = { target_device[t][0],target_device[t][1]  ,target_device[t][2]  ,target_device[t][3] ,target_device[t][4]  ,target_device[t][5]};
              err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_ADDR_FILTER, td);
              APP_ERROR_CHECK(err_code);    
        }
    
        
       
         err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_ADDR_FILTER, false);
         APP_ERROR_CHECK(err_code);
     
    }

    scan start:

    static void scan_start(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_ble_scan_params_set(&m_scan, &m_scan_param);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_ble_scan_start(&m_scan);
        APP_ERROR_CHECK(err_code);
    
        //USE LED TO INDICATE THE STATUS BLE AS SCANNER  <------
    }

    Can you try setting the timeout to unlimited and let the app run for a while?

    The scanning timeout already disable

  • I don't see anything wrong here. It really could just be that the nRF chip doesn't see beacon 3 at all...

    As a final test, could you reconfigure the scan module to print all BLE addresses it see without any filtering, and let it run for 1~2 minute?

    If beacon 3 still won't show up in that, perhaps we need to look at a sniffer trace

  • I have done, I modified the scan_init and scan_evt_handler and scan the beacon 2 and beacon 3:

    scan_init:

    static void scan_init(void)
    {
        ret_code_t          err_code;
        nrf_ble_scan_init_t init_scan;
    
        memset(&init_scan, 0, sizeof(init_scan));
    
        init_scan.connect_if_match = false;
        init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;
        init_scan.p_scan_param     = &m_scan_param;
    
        err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
        APP_ERROR_CHECK(err_code);
     
    }

    scan_evt_handler:

    static void scan_evt_handler(scan_evt_t const * p_scan_evt)
    {
        ret_code_t err_code;
        char data_hex[10];
        char len[10];
        
    
        switch(p_scan_evt->scan_evt_id)
        {
    
            case NRF_BLE_SCAN_EVT_NOT_FOUND:  //FOB filter, it is filtered by the company ID           
                
                unsigned char* addr       =  p_scan_evt->params.p_not_found->peer_addr.addr;      
                   
                uart_putstring("ADDR:");
    
                for (int a=5; a>=0; a--)
                {
                      sprintf(data_hex,"%02x", addr[a] );
                      uart_putstring(data_hex);
                        
                }
    
                uart_putstring("\r\n");
                
            break;
    
    
            
            case NRF_BLE_SCAN_EVT_FILTER_MATCH:
           
                 
            break;
    
    
            
            default:
            break;
    
        }
        
    }

    and the result is the next:

    The NRF52 is able to see both beacons, but the problem is in NRF_BLE_SCAN_EVT_FILTER_MATCH, for some reason the Beacon 3 does not trigger the scan event. Disappointed

  • That is really very strange...

    Nothing stands out immediately to me right now. What is the advertising period of beacon 3? Other than let the filtered scan run for a long while and see how it goes, I don't have anything to recommend today...

    I am out of office today and tomorrow, so I will go over your code carefully one more time on Monday. If you need something urgent, please let me know here and we can arrange some alternatives.

  • Hi Hieu! 

    I managed to filter all the beacons!!! I have tried in differents version of the SDK, and with the SDK 17.1 with the with the most updated Soft Device S140, I succeeded

    thanks a lot Hieu!

Reply Children
Related