This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How do I implement an address filter?

I am very new to BLE development, and am building my application on top of the ble_central\ble_app_uart_c example.

I have this tag defined at the start, with the other global variable definitions.

#define NRF_BLE_SCAN_ADDR_FILTER 0x02

This is the function where I am initializing the module: 

/**
 * @brief Parameters used when scanning.
 */
static const ble_gap_scan_params_t m_scan_params =
{
    .active   = 1,
    .interval = SCAN_INTERVAL,
    .window   = SCAN_WINDOW,
    .timeout  = SCAN_TIMEOUT,
    #if (NRF_SD_BLE_API_VERSION == 2)
        .selective   = 0,
        .p_whitelist = NULL,
    #endif
    #if (NRF_SD_BLE_API_VERSION == 3)
        .use_whitelist = 0,
    #endif
};
 

I am calling the module (or setting the filter, unsure of the terminology) here in the scan_start() function:

/**
 * @brief Parameters used when scanning.
 */
static const ble_gap_scan_params_t m_scan_params =
{
    .active   = 1,
    .interval = SCAN_INTERVAL,
    .window   = SCAN_WINDOW,
    .timeout  = SCAN_TIMEOUT,
    #if (NRF_SD_BLE_API_VERSION == 2)
        .selective   = 0,
        .p_whitelist = NULL,
    #endif
    #if (NRF_SD_BLE_API_VERSION == 3)
        .use_whitelist = 0,
    #endif
};

The scan_start() function is called in main(). I have not yet tested this implementation as it is unfinished.

My questions around this are:

  1. Where do I set the address I want to filter for? It merely advertises and I can't connect to it.
  2. Once the address is set, is this implementation correct?

Thank you!

Parents
  • Hello,

    I am experiencing something quite strange - I am getting a 'wrong filter type error' for an address filter, and no error for a uuid filter. (I do not need a uuid filter, am just comparing my implementation of an address filter to the ble_app_uart_c implementation of a uuid filter).

    Here is a comparison of the two implementations:

    UUID FILTER:

    static ble_uuid_t const m_nus_uuid =
    {
    .uuid = BLE_UUID_NUS_SERVICE,
    .type = NUS_SERVICE_UUID_TYPE
    }
    
    //in the scan init function
    err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &m_nus_uuid);
    APP_ERROR_CHECK(err_code);

    ADDRESS FILTER:

    static ble_gap_addr_t const IM21_ADDRESS =
    {
        .addr_id_peer = 0,
        .addr_type = BLE_GAP_ADDR_TYPE_PUBLIC,
        .addr = {0x6b, 0xc6, 0x51, 0x6f, 0x7c, 0xb8}
    };
    
    // in the scan_init function
    err_code = nrf_ble_scan_filters_set(&m_scan, SCAN_ADDR_FILTER, IM21_ADDRESS.addr);
    APP_ERROR_CHECK(err_code);

    The UUID filter works great. The Address filter gives an NRF_ERROR_INVALID_PARAM error, which means that SCAN_ADDR_FILTER is not being recognized or something similar. I was able to print the values of both SCAN_ADDR_FILTER and SCAN_UUID_FILTER so I know that SCAN_ADDR_FILTER is defined.  Why am I getting an NRF_ERROR_INVALID_PARAM error when I use SCAN_ADDR_FILTER, but not SCAN_UUID_FILTER?

  • Hello again,

    panda_noob_2000 said:
    Why am I getting an NRF_ERROR_INVALID_PARAM error when I use SCAN_ADDR_FILTER, but not SCAN_UUID_FILTER?

    It seems that you are passing only the address part of the ble_gap_addr_t structure.
    Please pass the entire ble_gap_addr_t structure to the filter set function, like so:

    err_code = nrf_ble_scan_filters_set(&m_scan, SCAN_ADDR_FILTER, &IM21_ADDRESS);
     

    Try this, and let me know if your INVALID_PARAM error persists.

    Best regards,
    Karl

  • I tried this and I am still getting the invalid param error. I am printing the value err_code after calling the nrf_ble_scan_filters_set function and err_code has the value 7. I know this corresponds to the NRF_ERROR_INVALID_PARAM error.  The application crashes at the next line: APP_ERROR_CHECK(err_code).

    Thank you, 

    Maria

  • Hello again, Maria

    Looking into the source code of the nrf_ble_scan_filters_set function I see that NRF_ERROR_INVALID_PARAM is returned if the defined number for that filter type.
    Have you changed your NRF_BLE_SCAN_ADDRESS_CNT to 1, in your sdk_config?

    Best regards,
    Karl

  • Hello,

    NRF_BLE_SCAN_ADDRESS_CNT was set to 0. I tried to set it to 1 in both the text editor and the configuration wizard, and both times I got this error when I tried to save the file: 

    Thanks,

    Maria

  • Hello Maria,

    panda_noob_2000 said:
    NRF_BLE_SCAN_ADDRESS_CNT was set to 0. I tried to set it to 1 in both the text editor and the configuration wizard, and both times I got this error when I tried to save the file

    That's very strange, I've never encountered this issue in Keil before.
    The Keil documentation says that this error indicates that the memory is not available to write.
    Could you check where you are storing your file, and that it is not already open in another program?
    Are you able to write any of the other defines in the sdk_config, or to change it at all?

    If the problem persists I recommend that you open a separate ticket for this, since this is diverging from the original scanning issue. This helps to keep the forum tidy and easy to navigate for other users.

    Best regards,
    Karl

Reply
  • Hello Maria,

    panda_noob_2000 said:
    NRF_BLE_SCAN_ADDRESS_CNT was set to 0. I tried to set it to 1 in both the text editor and the configuration wizard, and both times I got this error when I tried to save the file

    That's very strange, I've never encountered this issue in Keil before.
    The Keil documentation says that this error indicates that the memory is not available to write.
    Could you check where you are storing your file, and that it is not already open in another program?
    Are you able to write any of the other defines in the sdk_config, or to change it at all?

    If the problem persists I recommend that you open a separate ticket for this, since this is diverging from the original scanning issue. This helps to keep the forum tidy and easy to navigate for other users.

    Best regards,
    Karl

Children
No Data
Related