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

how to get data length in bytes in notification only characteristics without enabling notification

hi,

i am working on generic ble central device which has nrf52832 as it's core.

my question is that i want to know the length of data in bytes which are being sent by notification only characteristic. without enabling notification.

so, for evaluation i am using pca10040 dev kit with sdk 14.2.0's blinkey central example with Nordic thingy 52 as peripheral device. i have modified it to connect with ble peripheral device according to device id entered via uart. after connection it will discover all the available service on peripheral and start allocation space in a register table (array of type uint16_t) to view by user via uart. so when it comes to read only, read/write, and write only characteristics i have no problem to get data length(for write only characteristics i don't have allocate memory space).but when it comes to notification i don't get data length until i enable notification and after that wait for that notification. that takes some time more time like thingy's button characteristic will only send notification when button is pressed. if button is never pressed my central device will always in wait to get notification from where it takes data length.

so is there any way to get data length in notification only characteristics without enabling notification. 

please reply.

thanks.

  • hi andy,

    thanks for reply. so the array will be used as spi register table by user and will be accessed by used via spi interface. and array index will be register address.

    i like your idea but problem is that *p_data pointer is pointing to received data from ble and will be changed if another characteristic will send data to central device. so what i will do is that i will make p_data as array of size 20 because my ble data has maximum length of 20 bytes and copy ble data to it.

  • No, each characteristic has its own p_data, so it doesn't matter if you receive data from another characteristic. And yes, essentially you should have an array(per characteristic) big enough to hold the maximum amount of data that you can receive from a characteristic. Those things should be documented somewhere in the peripheral's API. If you don't have access to that, making each array size 20 will be the safest bet. You are already using 512 bytes in your previous implementation, so I guess RAM is not a limitation for you.

Related