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

  • My code already has notifications available however, I just need to set them to the CSV data value.

Reply Children
  • Thomas said:
    Is there an example of this?

     No. But there are examples that use SD card readers, and examples that send notifications (which I understand you already have up and running).

    Now you just need to combine these.

    Have you tested the SD card example?

    It is found in 

    SDK\examples\peripheral\fatfs

    Are you able to read from and write to the sd card?

    If yes, then all that remains is to read from the sd card, and take the data that you read and send it as notifications over BLE in your application.

  • I have gotten notifications working via an example that increments a value once per second if notifications are selected. However, I can only see the notification working using the NRF connect notification feature and, not my own app or by writing to the characteristic value itself. So my question is how do I set characteristic notifications or is there an example. I am using android studio.

  • You need to enable notifications from your mobile app, if you develop your own application. I don't know how this is done from the phone side.

    Try to google how to do it, together with what IDE tools/libraries that you use for your mobile application. (Android/iOS, Javascript/other, ...).

    Best regards,

    Edvin

  • Ok I've sorted out how to do my notifications. I do however have another question. I am passing a command via a gatt connection to a custom service. It then passes the received data to a statemachine. From this certain actions take place. However they only work inside of the Gatt connection on_write statement and not in the main. I would like to run functionality from my main code by setting a global boolean value from my on_write method. But when I do this, nothing in the main loop runs.

    I have another question post with it here : https://devzone.nordicsemi.com/f/nordic-q-a/58666/issue-reading-sd-card-from-within-a-gatt-connection

    with the code as follows but it does not work.

    main()
    
    {
    
    ...
    
    for(;;)
    
    {
    
         if (m_rcvd_data_request) // Always checked after application interrupts
    
         {
    
                 m_rcvd_data_request = false;
    
                 //TODO: add calls to load data from SD and send over BLE
    
          }
    
          else if( <flag>)
    
         {}
    
          idle_state_handle(); // sleep while waiting for new events
    
    }

  • Hello,

    Are you able to propagate these events to main.c? See step 7 in the github that you linked to. It seems like this is pretty much what you are looking for, if you are not able to set the flags in main.

    EDIT: I just read your last post in the link to your other case. Remember to also set your main_test to "volatile", so if it is currently:

    bool main_test;

    Try set it to:

    volatile bool main_test;

    This means that the compiler will tell the application to always check this variable's value, and not assume it is the same as the last time you were in that function. But you still need to propagate your events to main.c, so do Step 7 as well.

Related