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

Sending a CSV File over ble Gatt connection

Hi,

I need to send data from a CSV file on the nordic board(Via fatfs library). I have presently gotten a Gatt service up and running.

I have a mobile application which, can see the gatt service and write to the characteristics. From a specific write command from the mobile device I want the nordic board to send the CSV file over.

I can presently read a single line of the CSV file formatted like this: (Time stamp, data1, data 2, data3, data 4, data 5).

What I need to implement is:

  • Reading the whole file but, one or multiple lines at a time due to the size of the CSV
  • Changing the read pointer of the SD card (So I know where to continue to read from)
  • Send this data to the characteristic
  • Read this characteristic data.

My code is based upon :  https://github.com/bjornspockeli/custom_ble_service_example

My CSV file size depends on the length of time I have been storing data from. It could be upto around 1-2mbytes. I beleive I need to set up some kind of notification service. Where I read a line(or several) of the SD card, set the GATT characteristic value to this. Then change the SD card pointer. Wait till the data is received by the mobile application. Then repeat until the file is read full.y

Note I am using SDK 16 NRF52840-dk PCA 10056 S140.

This post is similar and mentions using two characteristics one from commication from the mobile app and, one for receiving the data.

https://devzone.nordicsemi.com/f/nordic-q-a/53987/nrf52840-file-transfer-via-ble

  • Sorry for my late response.

    It does print out 51 bytes via the gatt (setting the characteristic value) However for me to read the data correctly via my NRF log it needs 51 bytes. But, when I inspect the data itself its 40 bytes long. So how can I chop off the excess?

    When I read this data on my mobile application I am developing it sees all the data and the stuff I dont want aka the full 51 I need a way of chopping this off. I am thinking of adding a termination character to the CSV file such as X as it wont be used in the CSV. Then when I see X it is the end of a new piece of data. Is this a good idea?

  • Do you mean if one line in the CSV file is shorter than 51 bytes? Doesn't that already have the linefeed termination on each line?

    You can find this before you send it as well. If each line is terminated by a linefeed you could say that each linefeed is the end, and set the length to that position, instead of 51. Another way is to just send all the data, 51 bytes at the time (or even more), and reassemble the file on the other side of the connection.

  • Ok I think I want to send a single line at a time which in memory is 40 bytes. How do I only send 40 bytes as opposed to the whole 51? I presume I need to index it similar to the app_uart example and if the characters \n or \r are found stop adding it to the new data to send. Something like that?

    Then send the next line of data.

  • Thomas said:
    I presume I need to index it similar to the app_uart example and if the characters \n or \r are found stop adding it to the new data to send. Something like that?

     Yes, indeed, and then set the p_length to a pointer to a uint16_t containing the length, just like in ble_app_uart.

  • Just a quick one: 

    I left my system running and got this,

    ERROR 1 [NRF_ERROR_SVC_HANDLER_MISSING] at D:\Segger projects\Segger Projects\SDKFOLDER\examples\ble_peripheral\gatt_issue\custom_files\Uart_comms.c:27
    00> PC at: 0x0003F671.

    This relates to this line of code:

    APP_ERROR_HANDLER(p_event->data.error_communication);

    Why does this error occur?

Related