Which is the best way of sending the data read from a sensor?

Hi,

I need to read the data from an acceleration sensor. I tried with a custom program of mine to simulate some data, but it is delaying too much.

I tried reducing the notification interval, but sometimes it just jumps numbers so to say, it should show 1,2,3. But now it shows 1,3,5.

Am I missing something?

Thank you!

  • Hello,

    I need to read the data from an acceleration sensor. I tried with a custom program of mine to simulate some data, but it is delaying too much.

    Could you elaborate on what you are doing here, and which delay you are referring to here?
    Are you reading out the sensor data over I2C for instance, and then sending it over BLE, where the mentioned delay applies to the BLE communication?


    If you are just starting out with the nRF Connect SDK then I highly recommend taking a look through the nRF Connect SDK Fundemental course to quickly familiarize with the SDK! :) 


    Best regards,
    Karl

  • Hi Karl, 

    I am still not reading any sensor, for now it is just dummy values, and supposedly they should be increasing in 1 unit each time the loop comes. But sometimes it is being increased in more than one unit. 
    I think maybe sending each time the sensor is being "read" is not the best. Is it possible to send maybe an array? Or which is the best way to send the most amount of the "read" sensor?

    Thank you!

  • Hello,

    Adrian1504 said:
    I am still not reading any sensor, for now it is just dummy values, and supposedly they should be increasing in 1 unit each time the loop comes. But sometimes it is being increased in more than one unit. 
    I think maybe sending each time the sensor is being "read" is not the best. Is it possible to send maybe an array? Or which is the best way to send the most amount of the "read" sensor?

    Thank you for clarifying. I assume then that this means that you are sending the dummy data over your BLE link, and the main question is why some of the numbers in the sequence is missing.
    In essence, BLE is a lossless protocol - no data is ever lost in the link - since every packet is either acknowledged by the peer. If a packet it not acknowledged by the peer in its next packet it will be retransmitted until acknowledged, or until the link is terminated.
    Therefore, the data must be lost before it is queued for sending.
    Could you be that your call to queue the data for sending failed, for instance due to a full buffer?
    This could lead to some missing samples in the sequence.
    If you share your relevant 'loop' code then I can take a look.

    Adrian1504 said:
    I think maybe sending each time the sensor is being "read" is not the best. Is it possible to send maybe an array? Or which is the best way to send the most amount of the "read" sensor?

    You can send an array in a single packet, yes - it just depends on the size of the data and frequency.
    How often are you reading the sensor data, how large as the samples, and what latency requirements do you have for your application?

    Best regards,
    Karl

  • Dear Karl,

    Thank you for the answer.

     I saw that in fact I was getting all the data, but I am getting 3 int_8 per second. I would like to receive more often, I tried lowering the notify interval, which was set to 500. And I still get the same amount of numbers. 

    I need to read my sensor which throws 3 values per reading (x,y,z), the frequency of reading is still not defined, but I am thinking on doing it via I2C. 

    Should I do an array of 3 arrays for each of the values?

    I am not understanding how I can should send with the bt_gatt_notify(). Should it be: bt_gatt_nottify(NULL,<characteristic declaration index>, &<array>,sizeof(array)); ?

    Or should it be one gatt_notify() per each array that I have?

    Thank you!

  • Hello,

    Adrian1504 said:
    Thank you for the answer.

    No problem at all, I am happy to help! :) 

    Adrian1504 said:
    I would like to receive more often, I tried lowering the notify interval, which was set to 500. And I still get the same amount of numbers. 

    Which value did you change here exactly?
    Please note that the peripheral device may only have a preference for the connection parameters, it does not actually set it. It is the central that decides which connection parameters that will be used.

    Adrian1504 said:

    I am not understanding how I can should send with the bt_gatt_notify(). Should it be: bt_gatt_nottify(NULL,<characteristic declaration index>, &<array>,sizeof(array)); ?

    Or should it be one gatt_notify() per each array that I have?

    If you would like to see a good example of how you can regularly output your sensor data over the BLE link you can take a look at the Peripheral Nordic UART example, which forwards everything it receives over BLE out on its UART, and visa versa. In the ble_write_thread you can see how it checks the FIFO for new data, and then queues it for transfer over BLE is there is any.

    Best regards,
    Karl

Related