Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to know if a characteristic requires a long read or not?

Hi,

I'm developing a central application and I want my central to read the device name characteristic from 3rd-party peripherals. I do not know the length of the data in the characteristic beforehand.

If the first time I call sd_ble_gattc_read() with offset 0, how can I know whether there is more data to be read?

When I receive the BLE_GATTC_EVT_READ_RSP event I have access to a "len" and an "offset" variable. The documentation states the following:

/**@brief Event structure for @ref BLE_GATTC_EVT_READ_RSP. */
typedef struct
{
  uint16_t            handle;         /**< Attribute Handle. */
  uint16_t            offset;         /**< Offset of the attribute data. */
  uint16_t            len;            /**< Attribute data length. */
  uint8_t             data[1];        /**< Attribute data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
                                           See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */
} ble_gattc_evt_read_rsp_t;

Does len return the complete length of the attribute? Or is it just the length of the data read? If len is indeed the complete length of the attribute, how can I know the length of the data array?

Thanks for your help.

Related