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

BLE HVX Notification Length not Working

Hello, 

I followed this tutorial and github example in order to make a custom service with the characteristics I need. However, I am running into an issue where the board sends all the bytes in the buffer (20 bytes) even though a value for length is specified. Attached is a screenshot of what the board sends and you can see all the trailing 0's from all the other values in the buffer.

Attached is an example of my implementation (specifically the pca10056, s140 part). Also in my specific application, I am trying to send a string as data through BLE and I am using strlen() to get the size of the string.

ble_app_our_service.zip

Parents
  • Hi, 

    Sorry for the delay. I think you used SDK 16.0 ble_app_uart example as the base. I spent a lot of time but still could not build your project to reproduce the problem.

    Could you provide the log of nRF connect?

    What happens if you change the attr_char_value.init_len to 20?

    Did you check the values of hvx_params.p_len and hvx_params.p_data as your expectations before providing them to the sd_ble_gatts_hvx() function?

    -Amanda H.

  • Hello, 

    Yes, The example is based off of ble_app_uart, but what kind of issue were you running into when building the project? I tried to build the application is a fresh SDK and it seemed to work fine. One thing to be mindful of though is when connecting to the board with NRF connect, you may need to erase and reflash the application to delete the bonding information to let you connect again. 

    As for the things you asked for/suggested:

    I tried looking around the forums and I couldn't figure out where to find the logs in nRF connect. Here are the logs on a different BLE debugging app called Lightblue though. In it you can see the characteristic receiving the real data <56 41 4c 3a 20 XX XX> where XX XX are a numerical value of count in main.c. 

    Heres what I see on the NRF connect app. The Unknown Characteristic with the value is the data I am referring to in the original post.

    I tried setting init_len to 20 and the same issue still happens and I also have checked the value of length that is being passed to sd_ble_gatts_hvx() and they are accurate and well below 20 (between 5-7 depending on the value of count) and also tried setting length to a static value and the same result still occurs.

    Thank you for taking your time to review my issue btw!

  • Hi, 

    After fixing the typo in main.c, I can use ble_app_template to rebuild your code and test with the nRF Connect mobile. I can read and write the 20 bytes to the characteristics without any issue. If I misunderstand the problem, please correct me and provide the log with nRF Connect. 

    -Amanda H.

Reply Children
  • Hello,

    The issue is that you should not be seeing 20 bytes when receiving the notifications, instead you are suppose to be seeing about 7 bytes instead.

    Attached are the logs.

    An example of the issue I am facing can be seen in the first received value.

    I	11:03:31.869	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-34-37-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:31.869	"(0x) 56-41-4C-3A-20-31-34-37-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received

    In this example, the bytes I am trying to send are only "56-41-4C-3A-20-31-34-37" (Where this is "VAL: 147" in ascii) and I specify the length of this string as 7 with strlen().

    However if you notice, 13 more extra bytes end up being sent with them as well even though the length parameter give to sd_ble_gatts_hvx() should be 7. (If you're curious, these extra 13 bytes come from bytes in memory after the location of the 7th byte in the memory)

    So the main issue I am facing is that even though this length parameter is specified, I am unsure why it is sending all these extra bytes from memory (until it reaches the cap of 20 bytes as specified in the characteristics setting) 

    Thank you again for taking time to review my issue btw!

    nRF Connect, 2020-05-13
    OurCharacteristic (EF:59:E7:58:8A:26)
    I	11:01:02.846	[Server] Server started
    V	11:01:02.857	Heart Rate (0x180D)
    - Heart Rate Measurement [N] (0x2A37)
       Client Characteristic Configuration (0x2902)
    - Body Sensor Location [R] (0x2A38)
    - Heart Rate Control Point [W] (0x2A39)
    Unknown Service (0000aaa0-0000-1000-8000-aabbccddeeff)
    - Unknown Characteristic [N R] (0000aaa1-0000-1000-8000-aabbccddeeff)
       Client Characteristic Configuration (0x2902)
       Unknown Descriptor (0000aab0-0000-1000-8000-aabbccddeeff)
       Characteristic User Description (0x2901)
       Characteristic Presentation Format (0x2904)
    - Unknown Characteristic [I W WNR] (0000aaa2-0000-1000-8000-aabbccddeeff)
       Client Characteristic Configuration (0x2902)
    User Data (0x181C)
    - First Name [R W] (0x2A8A)
    - Last Name [R W] (0x2A90)
    - Gender [R W] (0x2A8C)
    V	11:01:03.122	Connecting to EF:59:E7:58:8A:26...
    D	11:01:03.122	gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)
    D	11:01:03.689	[Server callback] Connection state changed with status: 0 and new state: CONNECTED (2)
    I	11:01:03.689	[Server] Device with address EF:59:E7:58:8A:26 connected
    I	11:01:03.696	[Server] MTU changed to 247
    D	11:01:03.734	[Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
    D	11:01:03.734	[Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
    I	11:01:03.746	Connected to EF:59:E7:58:8A:26
    V	11:01:03.762	Discovering services...
    D	11:01:03.762	gatt.discoverServices()
    I	11:01:04.470	Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
    D	11:01:04.603	[Callback] Services discovered with status: 0
    I	11:01:04.603	Services discovered
    V	11:01:04.619	Generic Access (0x1800)
    - Device Name [R W] (0x2A00)
    - Appearance [R] (0x2A01)
    - Peripheral Preferred Connection Parameters [R] (0x2A04)
    - Central Address Resolution [R] (0x2AA6)
    Generic Attribute (0x1801)
    - Service Changed [I] (0x2A05)
       Client Characteristic Configuration (0x2902)
    Unknown Service (0000f00d-1212-efde-1523-785fef13d123)
    - Unknown Characteristic [N R W] (0000bee0-1212-efde-1523-785fef13d123)
       Client Characteristic Configuration (0x2902)
    - Unknown Characteristic [N R W] (0000bee1-1212-efde-1523-785fef13d123)
       Client Characteristic Configuration (0x2902)
    D	11:01:04.619	gatt.setCharacteristicNotification(00002a05-0000-1000-8000-00805f9b34fb, true)
    D	11:01:04.623	gatt.setCharacteristicNotification(0000bee0-1212-efde-1523-785fef13d123, true)
    D	11:01:04.627	gatt.setCharacteristicNotification(0000bee1-1212-efde-1523-785fef13d123, true)
    I	11:01:04.711	Connection parameters updated (interval: 48.75ms, latency: 0, timeout: 5000ms)
    I	11:01:09.109	Connection parameters updated (interval: 195.0ms, latency: 0, timeout: 4000ms)
    V	11:03:30.696	Enabling notifications for 0000bee0-1212-efde-1523-785fef13d123
    D	11:03:30.696	gatt.setCharacteristicNotification(0000bee0-1212-efde-1523-785fef13d123, true)
    D	11:03:30.707	gatt.writeDescriptor(00002902-0000-1000-8000-00805f9b34fb, value=0x0100)
    I	11:03:31.068	Data written to descr. 00002902-0000-1000-8000-00805f9b34fb, value: (0x) 01-00
    A	11:03:31.069	"Notifications enabled" sent
    V	11:03:31.095	Notifications enabled for 0000bee0-1212-efde-1523-785fef13d123
    I	11:03:31.869	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-34-37-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:31.869	"(0x) 56-41-4C-3A-20-31-34-37-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:32.815	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-34-38-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:32.815	"(0x) 56-41-4C-3A-20-31-34-38-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:33.805	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-34-39-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:33.806	"(0x) 56-41-4C-3A-20-31-34-39-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:34.763	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-35-30-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:34.764	"(0x) 56-41-4C-3A-20-31-35-30-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:35.746	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-35-31-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:35.746	"(0x) 56-41-4C-3A-20-31-35-31-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:36.718	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-35-32-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:36.718	"(0x) 56-41-4C-3A-20-31-35-32-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:37.696	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-35-33-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:37.696	"(0x) 56-41-4C-3A-20-31-35-33-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:38.676	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-35-34-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:38.677	"(0x) 56-41-4C-3A-20-31-35-34-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:39.860	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-35-35-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:39.860	"(0x) 56-41-4C-3A-20-31-35-35-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:40.808	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-35-36-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:40.808	"(0x) 56-41-4C-3A-20-31-35-36-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:41.800	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-35-37-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:41.800	"(0x) 56-41-4C-3A-20-31-35-37-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:42.758	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-35-38-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:42.758	"(0x) 56-41-4C-3A-20-31-35-38-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:43.743	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-35-39-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:43.743	"(0x) 56-41-4C-3A-20-31-35-39-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:44.708	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-36-30-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:44.708	"(0x) 56-41-4C-3A-20-31-36-30-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:45.684	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-36-31-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:45.684	"(0x) 56-41-4C-3A-20-31-36-31-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:46.658	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-36-32-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:46.658	"(0x) 56-41-4C-3A-20-31-36-32-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:47.829	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-36-33-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:47.829	"(0x) 56-41-4C-3A-20-31-36-33-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:48.803	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-36-34-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:48.803	"(0x) 56-41-4C-3A-20-31-36-34-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:49.785	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-36-35-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:49.785	"(0x) 56-41-4C-3A-20-31-36-35-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:50.754	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-36-36-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:50.754	"(0x) 56-41-4C-3A-20-31-36-36-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:51.738	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-36-37-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:51.739	"(0x) 56-41-4C-3A-20-31-36-37-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:52.705	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-36-38-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:52.705	"(0x) 56-41-4C-3A-20-31-36-38-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:53.691	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-36-39-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:53.692	"(0x) 56-41-4C-3A-20-31-36-39-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:54.655	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-37-30-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:54.655	"(0x) 56-41-4C-3A-20-31-37-30-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:55.838	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-37-31-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:55.838	"(0x) 56-41-4C-3A-20-31-37-31-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:56.812	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-37-32-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:56.813	"(0x) 56-41-4C-3A-20-31-37-32-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:57.778	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-37-33-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:57.778	"(0x) 56-41-4C-3A-20-31-37-33-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:58.749	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-37-34-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:58.749	"(0x) 56-41-4C-3A-20-31-37-34-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:03:59.725	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-37-35-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:03:59.725	"(0x) 56-41-4C-3A-20-31-37-35-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:04:00.700	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-37-36-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:04:00.701	"(0x) 56-41-4C-3A-20-31-37-36-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:04:01.685	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-37-37-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:04:01.686	"(0x) 56-41-4C-3A-20-31-37-37-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:04:02.650	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-37-38-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:04:02.650	"(0x) 56-41-4C-3A-20-31-37-38-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:04:03.817	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-37-39-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:04:03.818	"(0x) 56-41-4C-3A-20-31-37-39-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:04:04.811	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-38-30-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:04:04.811	"(0x) 56-41-4C-3A-20-31-38-30-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:04:05.767	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-38-31-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:04:05.767	"(0x) 56-41-4C-3A-20-31-38-31-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:04:06.755	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-38-32-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:04:06.756	"(0x) 56-41-4C-3A-20-31-38-32-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:04:07.720	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-38-33-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:04:07.721	"(0x) 56-41-4C-3A-20-31-38-33-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    I	11:04:08.693	Notification received from 0000bee0-1212-efde-1523-785fef13d123, value: (0x) 56-41-4C-3A-20-31-38-34-00-00-00-00-54-3A-30-C0-F1-77-E5-82
    A	11:04:08.693	"(0x) 56-41-4C-3A-20-31-38-34-00-00-00-00-54-3A-30-C0-F1-77-E5-82" received
    

  • Hi, 

    Please see this post. The characteristic has to be defined as having a variable length with vlen as 1. Please try to add like this

    //Attribute metadata
    ble_gatts_attr_md_t attr_md;
    memset(&attr_md, 0, sizeof(attr_md));
    attr_md.vlen = 1; 


    -Amanda H.

Related