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

  • p_length is a pointer. Press the arrow to the left to see the content of p_length.

  • Thanks. It is 51.

    Therefore, I am not sure what the issue is.

  • What step should I take next to fix this issue? I have tried changing the data i send from a char to uint8_t. That made no difference. 

    Could it be some sdk setting thats incorrect or something not working correctly about sd_ble_gatts_hvx?

    Or is my init incorrect. I am missing add_char_params.is_var_len  = true;

    But, I don't use add_char_params.is_var_len as I dont have add_char_params in my code.

  • Can you zip the project folder and upload it here so that I can try to replicate the behavior that you are seeing? If possible, please try to strip away the CSV file part. Just a project that can send a 51 byte long array that replicates the behavior that you are seeing.

  • Hi Edvin,

    Cheers for offering to have a look. I've taken my project and removed a bunch of code to make it simpler for you to test still having the same issue. I have just tested it on a NRF52840-dk board with nothing connected to the GPIOs and the issue still persists.

    To get the code to work and show you the bug please do the following steps. Place inside the ble_peripheral folder. Then the includes should not need changing. Also I use Jlink rtt for my terminal.

    Then build and run. To show the bug:

    • Open nrf connect
    • Should see a device with data 0x0003E804.....
    • Press connect
    • On the unknown service request notifications from the second characteristic should have the 3 arrows(UUID with 1402)
    • Then write to the other characteristic 2 values
    • 10(Uint32) this is my start command
    • 60 (uint32) this is my read command. It will then show the data to the nrf connect app with the bug
    • 20(uint32) stop command

    Hopefully you will see the same result thanks,

    gatt_issue.zip

    Below is what I expect you will see from the nrf connect application.:

Reply
  • Hi Edvin,

    Cheers for offering to have a look. I've taken my project and removed a bunch of code to make it simpler for you to test still having the same issue. I have just tested it on a NRF52840-dk board with nothing connected to the GPIOs and the issue still persists.

    To get the code to work and show you the bug please do the following steps. Place inside the ble_peripheral folder. Then the includes should not need changing. Also I use Jlink rtt for my terminal.

    Then build and run. To show the bug:

    • Open nrf connect
    • Should see a device with data 0x0003E804.....
    • Press connect
    • On the unknown service request notifications from the second characteristic should have the 3 arrows(UUID with 1402)
    • Then write to the other characteristic 2 values
    • 10(Uint32) this is my start command
    • 60 (uint32) this is my read command. It will then show the data to the nrf connect app with the bug
    • 20(uint32) stop command

    Hopefully you will see the same result thanks,

    gatt_issue.zip

    Below is what I expect you will see from the nrf connect application.:

Children
  • Ok, a couple of general hints:

    Don't include header files the way that you have done. These should only be included in the project settings' preprocessor setting: "Include directories".

    I see that you have added the files nrf_nvic.c and nrf_soc.c with some modified options, including some header files that are not intended for use when you use the softdevice. I couldn't compile the project before removing these.

    Then there was a warning, which you should always check. NB: When you compile a file but you haven't done any changes, SES will ignore the previous warnings for these files. You didn't include app_fifo.h in your main.c (or Setup.h). When I did, I saw that you had the wrong input parameters (none) on app_fifo_flush(); so I removed that call.

    I didn't manage to trigger the notification by your command sets. I just added the SEND_CSV function on a button press (button 4).

    Then I sent one notification, and that would send one packet of 51 bytes.

    I don't know what the issue was, but I did a bit of cleaning in your project.

    Can you try the attached modified project, and see if you get more than 51 bytes if you press button 4 after enabling notifications?

    gatt_issue.zip

    Best regards,

    Edvin

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

Related