How to enable multiple notifications in central side

Hi,

I am currently working on creating a BLE central using nRF52840 with SDKv2.0.0.

For this, I am started with the example code ble_central_hr. I have set up a peripheral on nRF52832 and it is possible to receive the data.

To receive multiple notifications in a single service, I have set up the peripheral, and multiple notifications are available while testing this with nRF connect mobile app.

Now, I want to receive these notifications in central side. While using discover function it is possible to find out the attributes, but notifications comes out for a single characteristics only.

How can I set up these notifications for multiple characteristics in a single service

Parents Reply
  • Hello again,

    Thank you for your patience with this.

    Vishnu Vijayan said:
    Simply means it is possible for me to receive notification from battery service and heart rate service simultaneously. (That is in the case of nRF connect app;see the picture I have attached.

    To receive notifications from the heartrate and bas characteristics simultaneously you will just need to add them to your discovery function (to look for them specifically), and then to call their respective subscribe function if they are found.
    You could essentially merge the main.c from central_bas and peripheral_hrs and create two bt_gatt_dm_cb instances, and perform both in series in the gatt_discovery function - this would subscribe you to both the battery level and heart rate measurement, at the convenience cost of having to perform discovery twice.

    The best practice here, If you instead have multiple services (could also be custom), would however be to instead iteratively search through all services offered by the peripheral device by using the bt_gatt_dm_start with NULL passed as the svc_uuid argument.
    As described in the documentation, this will discover each service after the other. Once a service is found you will enter the registered callback, in which you can subscribe to the notifications for that service's characteristics, or you can use bt_gatt_dm_continue to continue the discovery for the next service in case the found service does not match the uuid you were looking for.
    This way, you can look through the entire list of available services and enable notifications if applicable.

    This is also the case for you, jpittevils - you can follow this same approach for your custom characteristics as well.

    Best regards,
    Karl

Children
No Data
Related