Arm Mbed OS support forum

Looking for MBED BLE Scanner (Central Function) with filter scanning

I am having a hard time finding a MBED OS BLE central function example. If anyone knows of a suitable example that can provide filter scanning (i.e. filter for a specific advertising service UUID), in particular, please let me know.

What I’ve seen so far on the MBED GitHub repository is not great. Most examples are for peripheral device functionality. The closest if this BLE GAP example, but this example simply rotates through different GAP modes and only provides GAP type information on duration and interval data, as per this output:

Starting next GAP demo mode
DEVICE MAC ADDRESS: :::::

Scanning started (interval: 100ms, window: 62ms, timeout: 3000ms).
Stopped scanning early due to timeout parameter
We have scanned for 3182ms with an interval of 160 timeslots and a window of 100 timeslots
We have been listening on the radio for at least 1937ms

Starting next GAP demo mode
DEVICE MAC ADDRESS: :::::

Scanning started (interval: 100ms, window: 25ms, timeout: 0ms).
We have scanned for 5999ms with an interval of 160 timeslots and a window of 40 timeslots
We have been listening on the radio for at least 1475ms

Starting next GAP demo mode
DEVICE MAC ADDRESS: :::::

Scanning started (interval: 312ms, window: 6ms, timeout: 0ms).
We have scanned for 5999ms with an interval of 500 timeslots and a window of 10 timeslots
We have been listening on the radio for at least 118ms

Starting next GAP demo mode
DEVICE MAC ADDRESS: :::::

Advertising started (type: 0x0, interval: [25 : 50]ms)
We have advertised for 5999ms with an interval of at least 80 timeslots
We created at least 0 tx and rx events

Starting next GAP demo mode
DEVICE MAC ADDRESS: :::::

Advertising started (type: 0x2, interval: [62 : 125]ms)
Advertiser xAdvertising started (type: 0x2, interval: [62 : 125]ms)

… etc.

It’s also rather difficult to actually work out how to get the MBED BLE central function firmware to connect to a peripheral device and bond, if necessary.

But for now I simply wish to parse out scan results and analyse UUID and UUID data/payload (e.g. create a Beacon scanner).

After trawling through the BLE_GAP example code, I see that this example does in fact provide scan result data via the virtual void onAdvertisingReport ( const AdvertisingReportEvent & event ) function but that the example code had used an arbitrary condition, which meant that I did not see any results

if (event.getRssi() < -65) { return; }

Then there is another function called AdvertisingDataParser which will parse out the payload.

It is still not clear from this where I find the advertising UUID. I assume it is somewhere in the
ble::AdvertisingDataParser::element_t field = adv_parser.next();

Any idea?

As no one else has contributed, thought to share further discoveries as I make them.

I found that within the onAdvertisingReport function we can make some changes.

First change I made is to let the routine while (adv_parser.hasNext()) { ... } loop through all the “fields”.

Then I can apply this check, or equivalent:

if (field.type == ble::adv_data_type_t::INCOMPLETE_LIST_16BIT_SERVICE_IDS) { ... }

That check seems to at least confirm if a 16bit SSID exists etc.

Next challenge is to actually check the SSID value…

EDIT: Which it turns out is very easy to get using field.value[x]

If you use field.value.size() to confirm you’ll find this to be divisible by 2, depending on how many 16 bit UUID’s are listed etc.