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

Reduce the number of characters transmitted through a notification.

So I run SDK 15.0. I have a notification channel, and I want to transmit some data on it.

I run this code

    hvx_params.handle = gatt_notify_handlers[index].gatt_handle;
    hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
    hvx_params.offset = 0;
    hvx_params.p_len  = &datalength;
    hvx_params.p_data = data;

    err_code=sd_ble_gatts_hvx(generic_ble_conn_handle, &hvx_params);


hvx_parmas.p_len is set to 3, which corresponds correctly to the value inside datalength.

The notification channel was initialised to a 19 character buffer that I use for my data handle.

I then use the nRF connect app to receive the notification, and I reliably receive all 19 characters in my buffer on my notification request.

However, that's not really what I wanted. I wanted to transmit only the 3 first characters. Is this not possible or is this just not the way to do it?
  • Hi

    I think you should have a look at the add_char_params.max_len function found in amongst others the ble_nus.c file in our SDK. Changing the max char length to the desired amount of characters you want transmitted should solve your problem.

    Best regards,

    Simon

  • ble_nus.c doesn't seem to have any references to add_char_params in SDK 15.0. I found some other service files, but unless I'm reading them wrong, they are using add_char_params to limit the max length of the transmission as I create the characteristic. Surely I'm not meant to remove my characteristic and creating it again between every notification if I wish to vary the notification length? Am I misunderstanding what you're saying?

  • Hi

    Please disregard my last reply, as I clearly misunderstood what you are trying to accomplish. Sorry about that.

    How are you confirming that you are receiving all 19 characters. Where are you reading the 19 characters? 

    This should be the way to obtain 3 characters on the receiving end, but can you try to set the data length in your receiving application as max 3 as well?

    Best regards,

    Simon

Related