BLE characteristic update length issue.

Hello,

Please take a look at the below function. I am able to write/read the characteristic data from nRF App.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static uint32_t our_char_add(ble_os_t * p_our_service)
{
// OUR_JOB: Step 2.A, Add a custom characteristic UUID
uint32_t err_code;
ble_uuid_t char_uuid;
ble_uuid128_t base_uuid = BLE_UUID_OUR_BASE_UUID;
char_uuid.uuid = BLE_UUID_OUR_CHARACTERISTC_UUID;
ble_uuid128_t base_uuid1 = BLE_UUID_OUR_CHARACTERISTC_UUID1;
char_uuid.uuid = BLE_UUID_OUR_CHARACTERISTC_UUID;
err_code = sd_ble_uuid_vs_add(&base_uuid1, &char_uuid.type);
APP_ERROR_CHECK(err_code);
// OUR_JOB: Step 2.F Add read/write properties to our characteristic
ble_gatts_char_md_t char_md;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.char_props.write = 1;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Now here is my function to update the characteristic data.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void our_characteristic_update1( ble_os_t * p_our_service,int8_t *temperature_value)
{
// OUR_JOB: Step 3.E, Update characteristic value
uint16_t len = 2;
ble_gatts_hvx_params_t hvx_params;
memset(&hvx_params, 0, sizeof(hvx_params));
hvx_params.handle = p_our_service->char_handles.value_handle;
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
hvx_params.offset = 0;
hvx_params.p_len = &len;
hvx_params.p_data = temperature_value;
sd_ble_gatts_hvx(p_our_service->conn_handle, &hvx_params);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

But here my problem is in 1st code block if I am setting the attr_char_value.max_len or attr_char_value.init_len =2. Then in 2nd code block, I have to set uint16_t  len = 2 so similarly if I set 1st code block attr_char_value.max_len or attr_char_value.init_len =20 I have to set in 2nd code block, I have to set uint16_t  len = 20. If it is so, then If I need to write 20 bytes and I am expecting to have 5 bytes response then also I am getting those 5 bytes+ remaining last 15 bytes data in App.

For example, supporting I am writing "HELLO" in the data characteristic and then expecting a response in the update data characteristic is "HI". Then, current I am getting updated data characteristics as ""HILLO".

How can I set dynamic length while I am updating data characteristics?

Note: I am not using ble_nus.h library.

Is it possible to have the required length using sd_ble_gatts_hvx() function? or what is my mistake in above code?

Thanks and regards,

Neeraj Dhekale