This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Service Discovery Failed using pc-ble-driver

I am using an nRF52840 Dongle to try and connect to a product over Bluetooth and communicate with it. I have been able to open this dongle using nRF Connect Bluetooth Low Energy, and can successfully find my product, connect to it, and write to its characteristics. I am now needing to use a C program to do this same thing.

I have downloaded the pc-ble-driver, created a project in my C IDE, and copied the code from the heart rate collector example to be the project's source file. I got the project to build without issue, and following the instructions in the examples github page, have flashed the dongle with the correct firmware to allow the c program to connect to it. I am able to successfully connect to the dongle's COM port and scan for devices.

I did have to make some modifications to the source file. My product I want to connect to doesn't advertise its name, so I was unable to connect to it even when finding it. This product does, however, advertise the Manufacturer Specific Data field, and after some trial and error, I was able to modify the find_adv_name routine to instead check for Manufacturer Specific Data, and I was able to connect to the device this way.

After this, I get output strings that read: "Connection Established", "Discovering Primary Services", and "Received Service Discovery Response". However, I then get an error message saying "Service Discovery Failed. Error Code 0x10A". Stepping through the code, this error is getting set after the "on_connected" routine is finished, but before starting the on_service_discovery_response routine.

I have changed the value of BLE_UUID_HEART_RATE_SERVICE to match the UUID of my product's service, but there was no effect. I had also been told in the past to try changing the srvc_uuid.type from BLE_UUID_TYPE_BLE to BLE_UUID_TYPE_VENDOR_BEGIN, but when doing this, I get a failure returned from the function "sd_ble_gattc_primary_services_discover", with the error code 0x8005, which seemingly corresponds to NRF_ERROR_SD_RPC_NO_RESPONSE. 

Could anyone give me any pointers for where to look for what all to change in the source code in order to connect to my product rather than whatever heart rate monitor it is expecting? Thanks!

  • The product has the service UUID of 17C30001EB0747848BF33212453B0D32. It is not a heart rate monitor. I am using the heart rate collector example because it is the only example that exists in the pc-ble-driver package.

    According to the description of the struct definition, this struct "encapsulates both 16-bit and 128-bit UUIDs". For 128-bit UUIDs, I need to define the 'uuid' parameter of the struct as "octets 12-13 of 128-bit UUID", according to the description.

    It is worth noting that there is another struct type defined in this header file called "ble_uuid128_t", which only has a single parameter made up of an array of 8-bit values. However, the "sd_ble_gattc_primary_services_discover" is expecting to be passed a parameter of type "ble_uuid_t", not "ble_uuid128_t". And this function is defined in the pc-ble-driver libraries, so it's not as if I can simply modify it to take the other struct instead.

    Considering that the "ble_uuid_t" struct has a parameter for type, and this can be set to "BLE_UUID_TYPE_VENDOR_BEGIN", this seems to suggest to me that this struct should be usable for defining 128-bit UUID services. I am wondering, then, if there needs to be some other function call that sets the rest of the 128-bit UUID. If there is, though, I can't find it. The program calls "sd_ble_gattc_primary_services_discover" as its first function call on connection.

    Could you please let me know if there is either a function I need to use to set the rest of the UUID, or if there is a function I can use to pass a "ble_uuid128_t" struct instead of a "ble_uuid_t"? Thanks.

  • Here is the product when connected in nRF Connect.

  • Would you be able to let me know the functions I need to call in order to connect to this service using the pc-ble-driver C program? Thanks.

  • I did some more experimenting with different functions. I found a function called "sd_ble_uuid_vs_add", which is supposed to add a vendor specific UUID to the program. I defined a struct of type ble_uuid128_t, and assigned its 16-length array to be my device's full 128-bit UUID (in little endian format, ie, srvc_uuid128[0] = 0x32, srvc_uuid128[1] = 0x0D, etc).

    I assigned this function to return an error code and print a fail message if it isn't equal to NRF_SUCCESS, and I made it past this function with no errors. I am also now making it past the "sd_ble_gattc_primary_services_discover" function without error (using 0x0100 as my 16-bit UUID, based on the service).

    However, I am now receiving an error message at the "on_service_discovery_response" function. The very first thing checked is the "gatt_status" parameter of the "p_ble_gattc_evt" object. This is failing with an error code of 0x10A. I tried searching the header files for an 0x10A, with no results, and for an 0x100. The only result I found was an error code that corresponds to 0x100 + some constant, which is defined as 0x3000, so this clearly isn't my error message.

    So I am now at the point where I began, before trying to make changes to the UUID properties. Could you please help me to determine what this 0x10A error message means, and what to do about this? Thanks.

  • I believe I've found the error, I needed to search for 0x0100 instead of 0x100.

    It looks like this error message is called BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND. So there is some attribute not being found when the service is being discovered. Unfortunately, since this is not in response to any function call, I have no idea what is setting this variable. It is the "gatt_status" parameter of the ble_evt object's evt.gattc_evt parameter, which is passed to the "on_service_discovery_response" function by the event handler.

    Doing more studying with breakpoints, it looks like this "gatt_status" variable remains at 0 through the entire "on_connected" routine, even after finishing and ending the pass through the event handler's loop. But then, when the event handler enters its next pass (going to the case for BLE_GATTC_EVT_PRIM_SRVC_DISC_RESP), this value is now set to 0x10A.

    So whatever is changing the evt_id, I'm assuming, is responsible for changing the "gatt_status" parameter, and it's being set to this error code.

    Could you please help me figure out what attribute is not being found? Thanks.

Related