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

Guidance for selecting characteristic initial length and max length?

Hello, in my travels through Nordic development, somehow I am only now creating truly custom characteristics, and I realize I have no idea why there is both an initial and a maximum length specified parameters when you create it.  So my questions are:

1) why are these different?  do characteristics grow and shrink?

2) what is the maximum characteristic length?

3) is there a big drawback to making characteristics larger rather than smaller?

Thanks!

/**@brief Add characteristic parameters structure.
 * @details This structure contains the parameters needed to use the @ref characteristic_add function.
 */
typedef struct
{
    uint16_t                    uuid;                     /**< Characteristic UUID (16 bits UUIDs).*/
    uint8_t                     uuid_type;                /**< Base UUID. If 0, the Bluetooth SIG UUID will be used. Otherwise, this should be a value returned by @ref sd_ble_uuid_vs_add when adding the base UUID.*/
    uint16_t                    max_len;                  /**< Maximum length of the characteristic value.*/
    uint16_t                    init_len;                 /**< Initial length of the characteristic value.*/
    uint8_t *                   p_init_value;             /**< Initial encoded value of the characteristic.*/
    bool                        is_var_len;               /**< Indicates if the characteristic value has variable length.*/
    ble_gatt_char_props_t       char_props;               /**< Characteristic properties.*/
    ble_gatt_char_ext_props_t   char_ext_props;           /**< Characteristic extended properties.*/
    bool                        is_defered_read;          /**< Indicate if deferred read operations are supported.*/
    bool                        is_defered_write;         /**< Indicate if deferred write operations are supported.*/
    security_req_t              read_access;              /**< Security requirement for reading the characteristic value.*/
    security_req_t              write_access;             /**< Security requirement for writing the characteristic value.*/
    security_req_t              cccd_write_access;        /**< Security requirement for writing the characteristic's CCCD.*/
    bool                        is_value_user;            /**< Indicate if the content of the characteristic is to be stored in the application (user) or in the stack.*/
    ble_add_char_user_desc_t    *p_user_descr;            /**< Pointer to user descriptor if needed*/
    ble_gatts_char_pf_t         *p_presentation_format;   /**< Pointer to characteristic format if needed*/
} ble_add_char_params_t;

Parents
  • Hi!

    So, the maximum length is how much space is reserved and the initial length is the current size of the characteristic value. The maximum length can't be changed, but you can change the initial length on any and every update. 

     

    1) why are these different?  do characteristics grow and shrink?

     Yes, a lot of use-cases require variable characteristic value. For example, this ticket.

    2) what is the maximum characteristic length?

     The maximum length is decided by the BLE spec, and looks to be 512 octets, but what limits this in practice is what can be sent in one packet, which is by default 20 bytes (ATT_MTU - 3). It is possible, with some of our SoftDevices, to enable extended MTU. The downside for this would mainly be power consumption. 

    3) is there a big drawback to making characteristics larger rather than smaller?

    The main drawback is taking up more memory space for your characteristic value, and the power consumption of your application from sending more data. 

    Best regards,

    Heidi

Reply
  • Hi!

    So, the maximum length is how much space is reserved and the initial length is the current size of the characteristic value. The maximum length can't be changed, but you can change the initial length on any and every update. 

     

    1) why are these different?  do characteristics grow and shrink?

     Yes, a lot of use-cases require variable characteristic value. For example, this ticket.

    2) what is the maximum characteristic length?

     The maximum length is decided by the BLE spec, and looks to be 512 octets, but what limits this in practice is what can be sent in one packet, which is by default 20 bytes (ATT_MTU - 3). It is possible, with some of our SoftDevices, to enable extended MTU. The downside for this would mainly be power consumption. 

    3) is there a big drawback to making characteristics larger rather than smaller?

    The main drawback is taking up more memory space for your characteristic value, and the power consumption of your application from sending more data. 

    Best regards,

    Heidi

Children
Related