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

Read BLE characteristic with nRF52840-DK and pc-ble-driver

For my project in development I need to read characteristics from BLE devices using pc-ble-driver library.

I am using a C program, not python bindings.

The method I am using is sd_ble_gattc_read passing the characteristic's handle_value got from sd_ble_gattc_characteristics_discover .

The problem is that I obtain in p_ble_gattc_evt->params.read_rsp.data always different data from a read to another one.

Obviously no write or other changes on the device is done. reading same characteristic on the same device with other tool works fine.

Someone can help me giving me advice on here I am wrong reading characteristic value?

  • I send in total three sd_ble_gattc_read() , first time with offset 0 and i get the first 22 bytes, then I send a second sd_ble_gattc_read() with offset 22 (length of the result I got) and I get the last 10 bytes. Then I send a thid sd_ble_gattc_read() with offset 32, I get a result with length 0, so I stop the process.

  • Hi, 

    What you described about your process to read blob is correct. But please clarify when do you receive corrupted data ? 
    If the ATT_MTU is 23 bytes it's about right that the first packet you can only receive 22 bytes. 
    If you want to read with longer data in one read request,  you need to request longer ATT_MTU. We support up to 247. 

  • I receive corrupted data in ble_gattc_evt_read_rsp_t.data.

    I am not complaining about the length of the data. I can retrieve all 32 bytes of the characteristic value in one way or another, but the bytes are always wrong and different by read to read.

    However, how can I change the default ATT_MTU value?

    One more detail: if I read the characteristic with sd_ble_gattc_char_value_by_uuid_read() in the value field of handle/value struct I obtain only 19 bytes, but always CORRECT as the first 19 bytes of expected value. An explaination on how get the remaining bytes with that method should be fine. Tried to call again sd_ble_gattc_char_value_by_uuid_read() with the handle_range augmented by 1 but I obtain ATTR_NOT_FOUND error.

  • Solved my issue.

    If you look at my code above, I use a result variable of convenience to store the result of the event.

    If I access the data without that variable, I get the right values.

    Can you please explain that?

    In any case, treat this ticket as solved.

Related