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

Send packets of data from my beacon

Hi! I want to send the temperature data that I get from the beacon sensor not one by one but in packets for example of 100 samples. I have followed this tutorial devzone.nordicsemi.com/.../ to create the service and everything else that is needed to send the data. Can someone help me to modify that code in order to send data in packets? Thanks in advance.

  • If you want to send more than 4 bytes, you need to modify the maximum length of the characteristic value, Step 2.H, Set characteristic length. If you want yo to send the data in notifications, this can be set up to 20 bytes.

    Then you just collect samples and call our_termperature_characteristic_update()/sd_ble_gatts_hvx() when you have the number of samples you want, max 20 bytes.

  • So if my data are 1 byte long, I cannot send more than 20 samples in a single packet? Because my problem is this: if i sample with the ADC (like in the temperature characteristic as said before) at a higher frequency than in the example (that is 1 Hz), let's say 1 kHz, with the minumum connection interval (that is 7.5 ms) i can't manage to get a sample every 1 ms and send it, because the maximum transmission frequency is 1/(7.5*10^-3); so i have to fill packets and transmit them with lower frequency than the sample frequency! So if i can fill a packet of let's say 100 samples, i can reach higher sampling frequencies and send by notification the packets. Is this correct? If so, this operation is limited by a maximum of 20 bytes packet? Thanks in advance!

    And also, when you say "collect samples" you mean to fill an array of values and then send it in the notification structure?

  • You are correct. You may also be able to send multiple packets (of 20 bytes) in each connection interval (7.5 ms) to achieve a higher data rate. How many packets you can send in a connection interval depends on the central device you are connecting to.

  • Can you please detail a little more about this? let's suppose that in the example of the temperature characteristic i want to read the temp every 100 ms, then fill two packet of 20 bytes and send them via notification once they are filled. How can i do this? Can you provide an example/extraction of code? Thanks!

  • What kind of details do you want? If you have followed the tutorial you already have implemented the timer and the function to send the notification.

Related