This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

error using the sd_ble_gatts_hvx()

I want to use the sd_ble_gatts_hvx() to send the notification with a packet, and the length of packet is 12 bytes, but the return value is "0x000C". I tested the length and I found the max_len is 4 bytes, when I set the length is 5, the error appears. For my understanding, the max_length of p.value is 20 bytes? Am I wrong?

uint32_t err_code = NRF_SUCCESS;
uint16_t len = 12;  // 4
ble_gatts_hvx_params_t params;

if (p_footsensor->conn_handle != BLE_CONN_HANDLE_INVALID)
{
    memset(&params, 0, sizeof(params));
    params.type     = BLE_GATT_HVX_NOTIFICATION;
    params.offset   = 0;
    params.handle   = p_footsensor->mpu6050_data_handles.value_handle;
    params.p_data   = packet->data;
    params.p_len    = &len;

    err_code = sd_ble_gatts_hvx(p_footsensor->conn_handle, &params);
}

return err_code;
Parents
  • Solved, the Attribute Configuration is wrong

  • This occurs because while creating characteristics the sample code sets max length of char value as sizeof(uint8_t). the services init code for adding chars should look like this: memset(&attr_char_value, 0, sizeof(attr_char_value));

    attr_char_value.p_uuid       = &ble_uuid;
    attr_char_value.p_attr_md    = &attr_md;
    attr_char_value.init_len     = 20;  // set the length here
    attr_char_value.init_offs    = 0;
    attr_char_value.max_len      = 20; // set the length here
    attr_char_value.p_value      = initial_char_values;
    
Reply
  • This occurs because while creating characteristics the sample code sets max length of char value as sizeof(uint8_t). the services init code for adding chars should look like this: memset(&attr_char_value, 0, sizeof(attr_char_value));

    attr_char_value.p_uuid       = &ble_uuid;
    attr_char_value.p_attr_md    = &attr_md;
    attr_char_value.init_len     = 20;  // set the length here
    attr_char_value.init_offs    = 0;
    attr_char_value.max_len      = 20; // set the length here
    attr_char_value.p_value      = initial_char_values;
    
Children
No Data
Related