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 very new to BLE development, and am building my application on top of the ble_central\ble_app_uart_c example.

    Welcome! :) Thank you for clarifying this, this is good for me to know when I write my answers. 

    This is the function where I am initializing the module: 

    This is just the ble_gap_scan_params_t parameters used for initializing the scanning module.

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

    This is the same code snippet as the previous one, did you perhaps mean to copy paste something else here?

    Where do I set the address I want to filter for? It merely advertises and I can't connect to it.

    Could you detail more what you are trying to achieve? Would you like your central to scan for the address of a specific device, and only connect to that device?
    The wording of your question here makes me wonder what you mean when you say that it merely advertises. You are currently working with the ble_app_uart_c example, which is a central example. Centrals never advertise - instead, they scan for the advertisements sent out by peripherals.
    If you intend to create a peripheral device, you should instead be looking at the BLE NUS peripheral example.

    Once the address is set, is this implementation correct?

    I cant say, because you have only shown me the ble_gap_scan_params_t parameters at this point. Please share the rest of your scan initialization, and I'll take a look.

    Best regards,
    Karl

  • Hi Karl, 

    Apologies for the duplicate code snippets and unclear explanations! I have a sensor periodically advertising packets. I would like to implement a filter on my BLE central module (NRF52DK) to read these packets. The sensor does not allow for connection, so all I wish to do is read the packets. I know the address of the sensor. You are also helping me with another ticket, this is the same issue if that helps give background.

    This is where I am initializing the module in the scan_start() function.

    /**@brief Function to start scanning.
     */
    static void scan_start(void)
    {
        ret_code_t ret;  
    
        ret = sd_ble_gap_scan_start(&m_scan_params);
        APP_ERROR_CHECK(ret);
    
        // Enable the filter on the address in the normal mode.
        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_ADDR_FILTER, false);
        APP_ERROR_CHECK(err_code);    
    
        ret = bsp_indication_set(BSP_INDICATE_SCANNING);
        APP_ERROR_CHECK(ret);
    }

    The scan_start function is called in main.

    Thanks for your help!

  • Hello again, 

    panda_noob_2000 said:
    Apologies for the duplicate code snippets and unclear explanations!

    No need to apologize :)

    panda_noob_2000 said:
    Thanks for your help!

    No problem at all, I am happy to help!

    panda_noob_2000 said:
    This is where I am initializing the module in the scan_start() function.

    You will need to set up a ADDR_FILTER before you can enable it, this is done using the nrf_ble_scan_filter_set function. It might also be helpful to have a look at the Scanning Module's documentation Filter section for future reference.

    panda_noob_2000 said:
    You are also helping me with another ticket, this is the same issue if that helps give background.

    Yes, I remember! Did you get to set up the sniffer yet? In this case it would make it a lot easier to design filters and parsing functions if you are able to see the packets directly, such as the sniffer allows you to. I still highly recommend giving it a try! :)

    Best regards,
    Karl

Reply
  • Hello again, 

    panda_noob_2000 said:
    Apologies for the duplicate code snippets and unclear explanations!

    No need to apologize :)

    panda_noob_2000 said:
    Thanks for your help!

    No problem at all, I am happy to help!

    panda_noob_2000 said:
    This is where I am initializing the module in the scan_start() function.

    You will need to set up a ADDR_FILTER before you can enable it, this is done using the nrf_ble_scan_filter_set function. It might also be helpful to have a look at the Scanning Module's documentation Filter section for future reference.

    panda_noob_2000 said:
    You are also helping me with another ticket, this is the same issue if that helps give background.

    Yes, I remember! Did you get to set up the sniffer yet? In this case it would make it a lot easier to design filters and parsing functions if you are able to see the packets directly, such as the sniffer allows you to. I still highly recommend giving it a try! :)

    Best regards,
    Karl

Children
No Data
Related