Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Filtering based on 128 bit uuid using whitelist

Hi there,

@Simonr, I need further help on this case 

https://devzone.nordicsemi.com/f/nordic-q-a/58464/filtering-based-on-128-bit-uuid

It is said that it is possible to use " a whitelist that holds the UUIDs you want to scan in order to filter these beacons".

To add these UUIDs to the whitelist it recommends to use sd_ble_gap_whitelist_set. However this funtion only accepts a list of the ble_gap_addr_t structure.

This structure is defined as follows:

uint8_t addr_id_peer: 1

uint8_t addr_type: 7

uint8_t addr [(6)]

I dont's see the way to fit a 128-bit UUID there. So, the question remains. Is it possible to filter scan packages using a 128-bit UUID? If yes, how?

Thanks!

  • Hi

    One of our previous colleagues, Jimmy, made a very good blog post here on how to do BLE scanning with Whitelist using the nRF5 SDK. Amongst other things it explains how to use UUIDs by setting and using the UUID filter type.

    Best regards,

    Simon

  • Thanks for the information. I could not see any related information on how to filter 128-bit UUID. 

    I repeat my query. Please be specific in your reply.

    I want to either use scan filter or whitelist to filter 128-bit UUID

    Is it possible to filter scan packages using a 128-bit UUID? If yes, how?

  • Hi

    Right, there are some modifications necessary to hold and store 128-bit UUIDs. Here's a quick mock-up on how you can do it on the central end (please note that this is not a full example, and just a snippet of code to be added to an existing central project):

    /* Two-dimensional array to hold the UUIDs that should be "whitelisted" */
    uint8_t whitelist[30][16] = {0};
    
    /*NRF FSTORAGE instance*/
    NRF_FSTORAGE_DEF(nrf_fstorage_t whitelist_storage) =
    {
        /* Set a handler for fstorage events. */
        .evt_handler = fstorage_evt_handler,
        .start_addr = 0x3e000,
        .end_addr   = 0x3ffff,
    };  
    
    /*Function for reading UUIDs from flash and putting them in whitelist on start-up*/
    static void read_flash(void)
    {
        ret_code_t err_code;
        /*Read flash at the address where uuid_number is stored*/
        err_code = nrf_fstorage_read(&whitelist_storage, 0x3e000, &uuid_number, 4);
        APP_ERROR_CHECK(err_code);
    
        /*If nothing has previously been written to flash, uuid_number will equal 255*/
        if(uuid_number == 255)
        {
            uuid_number = 0;
        }
        else
        {
            /*Read out as many UUIDs as indicated by uuid_number*/
            for(uint8_t i = 0; i < uuid_number; i++)
            {
                nrf_fstorage_read(&whitelist_storage, flash_addr, &whitelist[i], 16);
                flash_addr += 0x10;
            }
        } 
    }
    
    int main(void)
    {
        ret_code_t rc;
        
        /*Initiate the fstorage instance*/
        rc = nrf_fstorage_init(&whitelist_storage, &nrf_fstorage_sd, NULL);
        APP_ERROR_CHECK(rc);
    }

    Best regards,

    Simon

  • Many thanks. Is it possible to do any modifications on the filters' side instead of the whitelist? Is that snippet portable to the latest nRF Connect SDK?

  • The filter can't be changed to support 128 bit as that is not a filter option by default. The snippet was part of a student project once upon a time that used the nRF5 SDK, so some changes will be necessary to make it work on the nRFConnect SDK.

    Best regards,

    Simon

Related