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

Parents
  • Hello,

    So you want to send a CSV file rom the SD card to the connected mobile phone, right?

    If I were you, I would start with the ble_app_uart example, and use ble_nus_data_send() to send your notifications. You can probably do it in the application you have started developing now. Just send the data using notifications.

    I didn't really see any questions in your post. Have you attempted this? Did you get stuck somewhere?

    Best regards,

    Edvin

  • Yes I want to send a CSV file from the SD card on the nordic board to a mobile phone. 

    Is there an example of this?

    I have not used the ble_app_uart example for this. However I do have my own custom service and Gatt connection working. My question is

    • How do I change the pointer location for the SD card?
    • How do I setup the notifications? As in how do I get them to work and change the value to be sent via this notification to the value of the CSV data?

    Also does with ble_app_uart example have a custom service? As I will need to move alot of my functionality too it.

    Also how does ble_nus_data_send work?

    Is there some guidance for how to setup notifications?

    Thanks

  • Thanks Edvin, I have just tested your code changes and it did output 51 bytes. But, I do not know what the issue was. I will now try re-add my code back in to restore my functionality and test with the changes that you have made.

    When you state I have included my headers wrong. Where was this?

  • I have merged my code back together and I seem to have the same problem it is reading 51 bytes now however. 

    In order to get my SD card line to read the line for the csv I need to read 51 bytes otherwise:

     D1: 1584969092,1881,1843,1862,1862,-0.010000 

    Does not output the right length of data.

    But when I output this via my gatt connection it only takes 30 bytes.

    Why could this be?

  • Thomas said:
    When you state I have included my headers wrong. Where was this?

     It seems you have included the header files like you included your .c files. You must include header files by adding their location to this list:

     

    Thomas said:
    I have merged my code back together and I seem to have the same problem it is reading 51 bytes now however.

     What problem would that be?

     

    Thomas said:

    In order to get my SD card line to read the line for the csv I need to read 51 bytes otherwise:

     D1: 1584969092,1881,1843,1862,1862,-0.010000 

    Does not output the right length of data.

     Ok.

     

    Thomas said:
    But when I output this via my gatt connection it only takes 30 bytes.

     What do you mean by "output this via my gatt"?

  • 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.

Reply
  • 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.

Children
Related