3 years, 8 months ago.

Scan for custom BLE UUID

Dear all,

I have an nrf51822 module and I am communicating with it via beacons.

What I have done so far is to use the BLE_API and transmit beacons and receive beacons to/from an android device.

So far so good.

What bothers me is that my code works only for the following kind of UUIDs:

0000xxxx-0000-1000-8000-00805f9b34fb.

But I would like to be able to use a custom 128-bit UUID.

What I want basically is to be able to scan for a customized UUID.

This is my callBack function when a BLE beacon is received:

include the mbed library with this snippet

void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) {
    myvector.clear();
    if(params->type == 3){
        for(int i = 0; i < params->advertisingDataLen; i++){
            if(params->advertisingData[i] == 0x16){
                if(params->advertisingData[i+1] == 0x34 && params->advertisingData[i+2] == 0x23){
                    for(int index = i+3; index < params->advertisingDataLen; index++){
                        myvector.push_back(params->advertisingData[index]);
                    }
                }
            }    
        }  
    }
}

In this way I only check for those 4 xxxx in the UUID. How can I check for example for the last 8 digits?

1 Answer

3 years, 8 months ago.

Advertising data contains a pack of records. The first byte of the record is the record length, the second the type of data contained and remaining bytes are the value. You can see parsing of advertising data in that example.