Hello,
I am writing a BLE central application that connects to a device and should then discover ALL services on the device. I am new to Nordic and am using the nRF5340 with SDK 1.5.1. My project is based on the Zephyr "central" sample app, and I have also referenced implementations in the central_hr and central_ht projects.
How can I discover all services on the peripheral device? The central_hr and central_ht projects demonstrate how to discover a couple specific services, but there is no example that I can find on how to discover all primary services, especially in the case where the UUIDs of the services are not known.
I tried configuring the bt_gatt_discover_params parameter as follows:
- uuid=NULL
- start_handle = 0x0001
- end_handle = 0xffff
- type = BT_GATT_DISCOVER_PRIMARY
My discovery callback function (func) simply returns BT_GATT_ITER_STOP if attr is Null, otherwise, it returns BT_GATT_ITER_CONTINUE.
The discovery callback function is getting called 7 times, and my device does have 7 services. However, I have tried all kinds of ways to identify and print the UUIDs but they all fail. And, if I print the (bt_gatt_attr *)->uuid->type in the discovery callback function, the type is always a BT_UUID_TYPE_16, which is not correct. Several of my UUIDs are 128-bit UUIDs. I have tried the following:
- Print 8 consecutive bytes, starting with the (bt_gatt_attr *)->uuid-> type.
- Print 8 consecutive bytes of the (bt_gatt_attr *)->user_data
- Set a U16 to BT_UUID_16((bt_gatt_attr *)->uuid)->val, and print that.
The 8 bytes of user_data is exactly the same each time the discovery callback is called. I have also examined the discovery callback data with the debugger and also found that very little changes each time the discovery callback is called. The (bt_gatt_attr *)->handle is unique, but that's about it.
What am I missing?