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

No BLE_GATT_HVX_NOTIFICATION under 20 bytes

In SDK 8 for the nrf51422, notifications are always being sent as 20 bytes, regardless of p_len. The BLE_EVT_TX_COMPLETE event stores the proper number in tx_length, but the packet over the air always contains 20 for its size field.

#define CHAR_TX_SIZE 20
uint8_t tx_buffer[CHAR_TX_SIZE];
static uint16_t tx_length;
static ble_gatts_hvx_params_t hvx_params;

tx_buffer[0] = 1;
tx_buffer[0] = 2;
tx_buffer[0] = 3;
tx_length = 3;

hvx_params.handle = rx_handles.value_handle;
hvx_params.offset = 0;
hvx_params.p_data = tx_buffer;
hvx_params.p_len  = &tx_length;
hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
result = sd_ble_gatts_hvx(m_conn_handle, &hvx_params);
Parents
  • I saw this on mBed the problem is that when you define a GattCharacteristic its constructor takes an initialLen and maxLen.

    github.com/.../GattCharacteristic.h

     *  @param[in]  initialLen
     *              The min length in bytes of this characteristic's value
    

    initialLen is used both as the actual minimum length... err WTF? So initialLen/minLen is used finally here:

    github.com/.../custom_helper.cpp

    attr_char_value.p_uuid    = p_uuid;
    attr_char_value.p_attr_md = &attr_md;
    attr_char_value.init_len  = min_length;
    attr_char_value.max_len   = max_length;
    attr_char_value.p_value   = p_data;
    
    ASSERT_STATUS ( sd_ble_gatts_characteristic_add(service_handle,
                                                    &char_md,
                                                    &attr_char_value,
                                                    p_char_handle));
    

    (Note this is when you call addService(); not when you create the GattCharacteristic as its documentation suggests.) So what does sd_ble_gatts_characteristic_add() do?

    Well it basically says it is the initial length, not the minimum length. I couldn't find any documentation that definitely says that it copies init_len bytes of p_data but I assume that is what it does.

    So what if you want a characteristic with initial length 20, max length 20, and variable length? You can't in mBed at the moment.

    You also can't have a read-only characteristic with 0 initial length, even though I'm pretty sure that is valid.

    But it is also used here:

    github.com/.../custom_helper.cpp

    attr_md.vlen = (min_length == max_length) ? 0 : 1;
    

    So if you want a variable length characteristic you must set initialLen != maxLen. But what if you want the initial length equal to the maximum length?

  • @Tim If the init_len equals to max_len, why the characteristics should have a variable length ? For instance, can you set init_len and max_len to 10 and send only 5 byte (with vlen = 1) ? I am not sure if this makes sense... What is your opinion ?

Reply Children
No Data
Related