sd_ble_gattc_char_value_by_uuid_read maximun lenght of 253

When I do a sd_ble_gattc_char_value_by_uuid_read I can only get a maximum of 253 bytes. 

And when I read more I get a gatt_status of 

BLE_GATT_STATUS_ATTERR_INVALID                    0x0100  /**< ATT Error: Invalid Error Code. */
and the handler of the uuid characteristics is also incorrect/ not available. (so I can read on with sd_ble_gattc_read)
Is this a bug or can I adjust some parameters so I do not get the error?
In our project we need to read 255 bytes....
# context
 
In our project we want to read a characteristics of many devices as possible.
fist we did this with de discover datebase ble_db_discovery_start
but reading the characteristics was taking from 800ms to 1500ms.
so we disabled it and did the discovery our self.
we waited for the BLE_GAP_EVT_CONNECTED event. 
and after we get a BLE_GAP_EVT_DATA_LENGTH_UPDATE we did a sd_ble_gattc_primary_services_discover (i found this some ware in the forms)
after we got the BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP we did the sd_ble_gattc_char_value_by_uuid_read 
This works fine when reading 1 to 253 bytes. and this is why faster. I can read the characteristics in 350ms to 600ms
the ble_gatt_effective_mtu is 512 so I am also not at the maximum bytes.
# Update
I found by lowering the NRF_SDH_BLE_GATT_MAX_MTU_SIZE from 512 to 254. the sd_ble_gattc_char_value_by_uuid_read was successful but incomplete. but now I get the handle witch I can use for the sd_ble_gattc_read to read the rest.
it is not a elegant solution, and I think this takes 50ms more. but still I can get the characteristics now in 400 to 650 ms. 
Parents
  • Hi,

    Thank you for the additional information.

    We have found that there is acutally an upper limit of 253 bytes in the Bluetooth specification. Bluetooth Core specification 5.4, vol 3, part F, section 3.4.4.2 ATT_READ_BY_TYPE_RSP:

    The attribute handle-value pairs shall be set to the value of the attributes identified by the attribute type within the handle range within the request. If the attribute value is longer than (ATT_MTU - 4) or 253 octets, whichever is smaller, then the first (ATT_MTU - 4) or 253 octets shall be included in this response.

    This means your implemented workaround would be the correct way to read longer values.

    Regarding the BLE_GATT_STATUS_ATTERR_INVALID there might still be a bug in the SoftDevice, as it sounds a bit strange this error should pop up if trying to read longer values. If anything you should get (ATT_MTU - 4) or 253 octets back (whichever is smaller), if the value is longer than that.

    Regards,
    Terje

  • Tanks Terje,

    in de wireshark logs 512, I can not see any data that has been send. Is this also a bug in de nrf android app? or is this bug in de android ble stack?

  • Hi

    Sorry about the late reply here, but I think the maximum supported MTU size for BLE on Android devices is also 255 (or 252 in reality), so I assume that is why the Wireshark log reflects that the Android devices sees a unknown GATT (generic attribute).

    Best regards,

    Simon

Reply Children
No Data
Related