Arm Mbed OS support forum

How do you register for a BLE characteristic Notification/Indication events (BLE central/client)

I am working on a BLE central application (client function) using MBED OS 6.

My external BLE peripheral device uses the NOTIFY property.

As such, I need my MBED BLE central application to enable notifications for that characteristic.

Unfortunately, I cannot find much information about how to go about this.

We have a small paragraph here within “the details”: https://os.mbed.com/docs/mbed-os/v6.2/mbed-os-api-doxy/classble_1_1_gatt_client.html#details

And somehow I need to incorporate all data here: https://os.mbed.com/docs/mbed-os/v6.2/mbed-os-api-doxy/struct_gatt_h_v_x_callback_params.html

But that’s it.

Laboriously trawling through the OS code, does not give much more about the function I need, which is found within the GattClient.h file…

/**
* Register an handler for Handle Value Notification/Indication events.
* @param callback Event handler to register.
* @note It is possible to unregister a callback by using
* onHVX().detach(callbackToRemove).
*/
void onHVX(HVXCallback_t callback);

As you see the code documentation does not tell me much.

So, assuming this is the right function, how do I attach this to a particular characteristic handle for example.

Then where should I place this code - I assume this “onHVX” is best placed within the discovery_termination function, if I was using the LEDblinker example as my reference.

Any guidance, is greatly appreciated.

Thanks.

Colin

Enabling the notify is proving quite difficult to find.

Using the LEDblinker example as my guide, I have added in an option for HVX within the LEDBlinkerDemo class:

_ble.gattClient().onDataRead(trigger_toggled_write);
 _ble.gattClient().onDataWritten(trigger_read);
 _ble.gattClient().onHVX(trigger_hvx);

Then added a new function “trigger_hvx”

void trigger_hvx(const GattHVXCallbackParams *response) { ... }

BUT… I cannot find out how to enable the characteristic NOTIFY property so that this callback triggers. I need to find some way of getting the CCCD attribute first.

I’ve discovered that the handling of CCCD and writing this attribute to enable notify is covered in the example BLE_GattClient, but it almost seems as if the coders want to rather demonstrate their superior prowess at C++ than try and simplify all the BLE examples for learning purposes by creating an easy to understand and well documented structure. Instead the structure of this example is completely different to the others, without any explanation as to why.

Hence, I now find myself trying to fit this “square peg” into the “round” BLE_LEDBlinker example, and this is proving quite difficult as the descriptor class also requires call backs etc. So this looks like a rejigging of the whole example.

As mentioned before, any guidance is greatly appreciated.

1 Like

my exact feeling when I read the examples…