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

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

  • For the UART event handler, the suggestion that the error handler comes with (in this case NRF_ERROR_SVC_HANDLER_MISSING) is not correct. The err_code is 1. You must look at the event description. What sort of type is p_event->data.error_communication? See if you can find the declaration of the error_communication in a header file, and see if you can see what it means when this is set to 1.

    Hint: What type is p_event? Right click and click go to definition.

Reply
  • For the UART event handler, the suggestion that the error handler comes with (in this case NRF_ERROR_SVC_HANDLER_MISSING) is not correct. The err_code is 1. You must look at the event description. What sort of type is p_event->data.error_communication? See if you can find the declaration of the error_communication in a header file, and see if you can see what it means when this is set to 1.

    Hint: What type is p_event? Right click and click go to definition.

Children
Related