Creat and send a file over BLE

Hi,

I use NCS 2.4.2 and i want to save data sensor with a hight frequency in a nrf5340 device and send it over BLE to a nrf52840 dongle device. The nrf5340 is the peripheral.
The sensor data are at a ver hight frequency (more than 400Hz), that's why i need to save it in a file and send it by block.

I need help to find the right solution to perform this. I saw Throughput Service, Objet transfer service, NUS but i can't figure out what is the best solution.

I use coded phy also.

Regards,

Pierre-Yves

Parents
  • Hi Pierre-Yves,

    To efficiently send the data, I'd suggest keeping it in a RAM buffer until it is sent. I'm not sure how many bytes each measurement is, but the more you can fit into each notification packet, the better.

    I use coded phy also.

    This will greatly reduce the theoretical throughput of the connection. If possible, it would be better to increase the TX power using an external PA/LNA such as the nRF21540 and stay on 1M.

    Best regards,

    Vidar

  • Do you have example of this ? and what services do i need to use ?

    each mesurement is composed of 3 float for the 3 axes and i also need to have the time in milisecond hour per hour, it's a long uint i think. Then one mesurement should be around 20 bytes each 1ms or each 2ms .


    I use already a nrf21540 and i need to use phy coded because  i need long rang connexion

    I tried to use throughput but with the sample central and peripheral when i config in coded_s8 it's really too slow instead of when i use ble nus

    Regards,

    Pierre-Yves

  • I'm not aware of any standard Bluetooth profiles/services for this exact use case. I think your best bet will be to just create a custom service. The existing NUS (Nordic UART Service) can be a good starting point if you want to do this. Simply make a copy of the NUS source and header files, rename files and function names, change UUID declarations, etc., to customize the service. Then, include the service in your project by adding these files to your source directory.

    Piwy said:
    I tried to use throughput but with the sample central and peripheral when i config in coded_s8 it's really too slow instead of when i use ble nus

    You are trading speed for range when using the CODED PHY. Mainly because the effective bitrate is just 1/8th of the 1M PHY, but also because the controller limits the maximum packet size to 27 bytes with this PHY (longer packets = increased chance for packet loss). The BLE NUS sample can be optimized to send data as fast as the throughput sample, but it should not be possible to make it any faster as the throughput sample is already optimized for this. 

Reply
  • I'm not aware of any standard Bluetooth profiles/services for this exact use case. I think your best bet will be to just create a custom service. The existing NUS (Nordic UART Service) can be a good starting point if you want to do this. Simply make a copy of the NUS source and header files, rename files and function names, change UUID declarations, etc., to customize the service. Then, include the service in your project by adding these files to your source directory.

    Piwy said:
    I tried to use throughput but with the sample central and peripheral when i config in coded_s8 it's really too slow instead of when i use ble nus

    You are trading speed for range when using the CODED PHY. Mainly because the effective bitrate is just 1/8th of the 1M PHY, but also because the controller limits the maximum packet size to 27 bytes with this PHY (longer packets = increased chance for packet loss). The BLE NUS sample can be optimized to send data as fast as the throughput sample, but it should not be possible to make it any faster as the throughput sample is already optimized for this. 

Children
  • What sample can i take as a starting point for ble NUS solution?

    If i customize it, i can't take the same UUID ? I tied peripheral uart bluetooth and i succed to send many data on it, i don't know what is the maximal possible. But the sample not permit to change UUID or customize the services. Is there another sample or example to do it ?

    I find 4 possible solution : Ble NUS, Object transfer service ( i don't find any help about his implementation...), throughput, and eventually use smp to tranfer fiole as i do to upload a new image.

    I need to find out what can be the best solution beetween them.

    For the throughput, is it possible to maximize the throughput speed in coded, to be faster by increasing the maximum packet size ? I can have a part of lost packet it won't be an issue.

    Also in the throughput it send a file, the img.file. I think that a good way can be to save a file with all the data in my external memory mx25r64 and send it, but i don't find how to create a file in it and save my data on it, do you have a sample for try this solution ? or example ? 

    For the Object transfer service, i have difficulty to find how to create the object correctly.

    For the smp transfer i also need to find how can i create a file in the external memory with all the data on it.

    I also check machine learning and edge impulse, they use ble nus but just at 100Hz, and the example code is really complicated.

    If you have any recomandations about all theses points, i am open to any help !

    Regards,

    Pierre-Yves


  • Piwy said:
    each mesurement is composed of 3 float for the 3 axes and i also need to have the time in milisecond hour per hour, it's a long uint i think. Then one mesurement should be around 20 bytes each 1ms or each 2ms .

    So if I understand this correctly, the connection will need a stable throughput of around 160 kbps to keep up with the sensor readings in your case (20 * 8 bits) / (1/1000)? This is impossible to achieve with the CODED s=8 bitrate.

    Piwy said:
    If i customize it, i can't take the same UUID ? I tied peripheral uart bluetooth and i succed to send many data on it, i don't know what is the maximal possible. But the sample not permit to change UUID or customize the services. Is there another sample or example to do it ?

    The sample uses the NUS service implemented here: https://github.com/nrfconnect/sdk-nrf/blob/main/subsys/bluetooth/services/nus.c . You can modify this file directly if you wish to make changes to it, or you can make a copy of the source file and integrate it with your project before modifying it as mentioned earlier.

    Piwy said:
    I find 4 possible solution : Ble NUS, Object transfer service ( i don't find any help about his implementation...), throughput, and eventually use smp to tranfer fiole as i do to upload a new image.

    The max. transfer speed you can achieve should be the same for the  BLE NUS and the Throughput service. OTS if for setting up bulk transfers an requires a custom mobile app to test (is not supported by nRF connect). I don't think SMP fits into this.

    Piwy said:
    Also in the throughput it send a file, the img.file. I think that a good way can be to save a file with all the data in my external memory mx25r64 and send it, but i don't find how to create a file in it and save my data on it, do you have a sample for try this solution ? or example ? 

    What is the purpose of storing the sensor measurements the QSPI flash?  Either way, if I were to do this,  I would consider just storing the raw data to the flash without using any filesystem as demonstrated by the SPI NOR sample

  • Is OTS can have a fastest transfer ? i can implement it with peripheral OTS and central OTC .

    I wanted to use QSPI flash because there is a lot of data to store and because i already use the flash to save other data. Also because i want to use th e OTS service and i thought that it was easier with the data in file as object to send.

    Also when i receive the data in the central device, how can i send directely the data in a file on the pc ?

    The central device is conencted in serial with a linux pc.

  • In theory, you can get a slightly better transfer rate if you set up a  CoC with OTS as discussed in this post:  L2CAP Connection-Oriented Channel (CoC) - how is it different then HVX? . However, it will not be sufficient to transmit all the sensor data with CODED phy. Remember that the bitrate is only 125 kbit/s with the s=8 encoding. 

    Piwy said:
    I wanted to use QSPI flash because there is a lot of data to store and because i already use the flash to save other data. Also because i want to use th e OTS service and i thought that it was easier with the data in file as object to send.

    I don't see any reason for storing the data to flash if the goal is to immediately relay the data to the connected client. This would make more sense if you want to store sensor data while the device is "offline".

    Piwy said:
    Also when i receive the data in the central device, how can i send directely the data in a file on the pc ?

    It should be trivial to store it to any file you want once you have figured out how to receive the data on the PC side.

  • I don't see any reason for storing the data to flash if the goal is to immediately relay the data to the connected client. This would make more sense if you want to store sensor data while the device is "offline".

    => it's because i can sometimes lose connexion beetween my devices, my peripheral is in motion
    And i could use this file as a black box also, do you know how to do this ?

    i succed to use ots object with both sample in coded and i succed to read the object from the peripheral, but the data that i read i want to save them directly with my device in my pc, do you know if it's possible and how to do it ?

Related