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

Sending up to 20 bytes of data during a notify event.

In a previous post Related post it was mentioned that the below posted code would allow for a transmission of 20 bytes. However when I try to run this code I see a reported value of 20, even if i change the length of the data array down to 5 (data[5] = {1,2,3,4,5,})

the characteristic keeps reporting garbage data instead of what I expect to see defined within the contents of data

What did I do wrong?

ble_gatts_hvx_params_t hvx_params;
memset(&hvx_params, 0, sizeof(hvx_params));
uint16_t len = 20;
uint8_t data[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; // 20 bytes of data

hvx_params.handle = value_handle;
hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
hvx_params.offset = 0;
hvx_params.p_len  = &len; // remember that this is also a pointer!
hvx_params.p_data = data;

err_code = sd_ble_gatts_hvx(conn_handle, &hvx_params);

When I run this code, I expect to see the pre-defined 20 bytes within data but that doesn't happen. I have attached the following screen shot of what I receive.

nRF master Control Panel

-- ANSWER: within characteristic definition attr_char_value.max_len needs to be set to the number of bytes to be sent.

However I still see garbage data. There is something else I'm not doing right.

Related