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
  • Hi Karl,

    I haven't implemented the sniffer as I only have one NRF52DK to use. I think a higher priority right now is to implement the filter without any errors. I have followed your advice in your previous reply (code pictured below) and have 3 main issues.

    // Enable the filter on the address in the normal mode.
    	  ret_code_t set_err_code;
        set_err_code = nrf_ble_scan_filters_set(&m_scan_params, SCAN_ADDR_FILTER, {0x6b, 0xc6, 0x51, 0x6f, 0x7c, 0xb8});
        APP_ERROR_CHECK(set_err_code);    
    	  ret_code_t en_err_code;
        en_err_code = nrf_ble_scan_filters_enable(&m_scan_params, NRF_BLE_SCAN_ADDR_FILTER, false);
        APP_ERROR_CHECK(en_err_code);

    1. On lines 3 and 6, I am getting implicit function declaration errors for nrf_ble_scan_filters_set() and nrf_ble_scan_filters_enable(). Am I missing a library?

    2. On line 3 I am getting a 'use of undeclared identifier SCANN_ADDR_FILTER' error. I checked the documentation, and I do not know how to define SCAN_ADDR_FILTER properly.This is all I can find:

    3. The documentation is either very vague regarding the third argument for the nrf_ble_scan_filters function, or I don't know what I am doing. All it says is that it should be a constant. How should I input the address?

    Thank you!

    Maria

  • Hello again, Maria

    panda_noob_2000 said:
    I haven't implemented the sniffer as I only have one NRF52DK to use.

    Yes, I understand this - but the sniffer only needs to run once, and collect a trace of the communication that the lock device is sending out, since this advertising does not change its format. This way, if you have the trace, you can go back to look at it whenever you will be making the parse functions, for example.
    I understand that you would like to prioritize the firmware directly, I am just making this recommendation again because I think you will benefit from it in both the medium and long term.
    The sniffer can also wait until the filters are up an running properly - it will be most useful when the data is to be parsed.

    panda_noob_2000 said:
    1. On lines 3 and 6, I am getting implicit function declaration errors for nrf_ble_scan_filters_set() and nrf_ble_scan_filters_enable(). Am I missing a library?
    panda_noob_2000 said:
    2. On line 3 I am getting a 'use of undeclared identifier SCANN_ADDR_FILTER' error. I checked the documentation, and I do not know how to define SCAN_ADDR_FILTER properly.This is all I can find:

    These two issues are likely happening for the same reason. Have you remembered to include the scanner header nrf_ble_scan.h file in your project? 

    panda_noob_2000 said:
    3. The documentation is either very vague regarding the third argument for the nrf_ble_scan_filters function, or I don't know what I am doing. All it says is that it should be a constant. How should I input the address?

    The void part here is just because it is not given what type the pointer will have before the function is called - since you might be filtering on name, address, uuid's, etc.
    Declare the address as a static const hex at the beginning of your file, and pass its pointer to the function as the third argument.
    You could take a look at how this is done in the other central example projects, if you would like to see exactly how you could implement this.

    Best regards,
    Karl

Reply
  • Hello again, Maria

    panda_noob_2000 said:
    I haven't implemented the sniffer as I only have one NRF52DK to use.

    Yes, I understand this - but the sniffer only needs to run once, and collect a trace of the communication that the lock device is sending out, since this advertising does not change its format. This way, if you have the trace, you can go back to look at it whenever you will be making the parse functions, for example.
    I understand that you would like to prioritize the firmware directly, I am just making this recommendation again because I think you will benefit from it in both the medium and long term.
    The sniffer can also wait until the filters are up an running properly - it will be most useful when the data is to be parsed.

    panda_noob_2000 said:
    1. On lines 3 and 6, I am getting implicit function declaration errors for nrf_ble_scan_filters_set() and nrf_ble_scan_filters_enable(). Am I missing a library?
    panda_noob_2000 said:
    2. On line 3 I am getting a 'use of undeclared identifier SCANN_ADDR_FILTER' error. I checked the documentation, and I do not know how to define SCAN_ADDR_FILTER properly.This is all I can find:

    These two issues are likely happening for the same reason. Have you remembered to include the scanner header nrf_ble_scan.h file in your project? 

    panda_noob_2000 said:
    3. The documentation is either very vague regarding the third argument for the nrf_ble_scan_filters function, or I don't know what I am doing. All it says is that it should be a constant. How should I input the address?

    The void part here is just because it is not given what type the pointer will have before the function is called - since you might be filtering on name, address, uuid's, etc.
    Declare the address as a static const hex at the beginning of your file, and pass its pointer to the function as the third argument.
    You could take a look at how this is done in the other central example projects, if you would like to see exactly how you could implement this.

    Best regards,
    Karl

Children
No Data
Related