3 Replies Latest reply on Apr 22, 2019 9:14 PM by GyanC_36

    File transfer over BLE

    user_1528391

      Hi,

       

      We are developing a mobile application based on custom BLE services. It will transfer a file (a hex file in this case but it's not important) to our custom BLE board which is based on CYBLE-012011. I wanted to ask you what is the best way to transfer a file over BLE. The file size will be 1 MB maximum.

       

      What I plan is to create a custom characteristic with a maximum payload length. As I know, we can set the MTU size to 512 bytes manually with a handshake, that's okay. After handshaking the MTU size, we are planning to write the file in chunks to this characteristic. It will write 512 bytes every time and wait for the device (BLE server custom board) to send an acknowledgement. After getting the ACK, it will write the next chunk. My questions are below:

       

      1: Are there any better ways to achieve this? Because there will be 2048 chunks to write a 1MB file. It will wait for an ACK every time from the device.

      2: How should I send the ACK from the device to the phone? I think we can do this with the WriteResponse. We can also create another Characteristic for the ACK and notify the phone(BLE central) when the device is ready to receive the new chunk.

      3: Where does the 512 byte MTU come from? I mean is this the maximum number of MTU that any BLE stack can allow according to the BLE SIG? Does this maximum number vary in different stacks? If yes, it can cause problems with different mobile phones. I want it to be generic and work in every phone model.

       

      Thanks,

      Abdullah.

        • 1. Re: File transfer over BLE
          GyanC_36

          Hi Abdullah,

           

          Please find answers below-      From your description , I understand that you are developing a Mobile Client App.

           

          1: Are there any better ways to achieve this? Because there will be 2048 chunks to write a 1MB file. It will wait for an ACK every time from the device.

          Ans: There are no better ways other than the one you mentioned. You need to create a Characteristics with length "MTU-3" and send the data.

           

          2: How should I send the ACK from the device to the phone? I think we can do this with the WriteResponse. We can also create another Characteristic for the ACK and notify the phone(BLE central) when the device is ready to receive the new chunk.

          Ans: WriteResponse is the better way because if you send a ACK from a different characteristics , it will add more latency.

           

          3: Where does the 512 byte MTU come from? I mean is this the maximum number of MTU that any BLE stack can allow according to the BLE SIG? Does this maximum number vary in different stacks? If yes, it can cause problems with different mobile phones. I want it to be generic and work in every phone model.

          Ans: Yes, it comes from the BLE SIG spec and standard over all the mobile phones.

           

          -Gyan

          2 of 2 people found this helpful
          • 2. Re: File transfer over BLE
            user_1528391

            Hello Gyan,

             

            Thank you for the answer!

             

            You are correct, we are trying to create a Mobile Client App. I have two final questions regarding yours:

             

            1: What we want with this file is to write it to an SD card. When we receive one chunk of the file (512 byte), we will write it to an SD card. So, I need to wait for this SPI write operation to finish and then send the WriteResponse to the the client (Mobile app). But this write operation may take longer than 100ms because there is a bridge between the Cypress and the sd card. I don't want to complicate things, this is not important actually. What I'm trying to ask is, would it be a problem if we send the WriteResponse to the client after 100ms? Can a client give a timeout error or something when the server wait a bit longer to send the WriteResponse?

             

            2: Do you know how does the Bluetooth Headsets transfer live sound data? Do they use 512 byte characteristics too? I was wondering if they somehow increase the MTU size and write bigger characteristics to lower the latency. Or do they use multiple characteristics with 512 byte size each?

             

            Thanks

            • 3. Re: File transfer over BLE
              GyanC_36

              Hi Abdullah,

               

                -> It is recommended that you send WriteResponse as soon as possible else client may give timeout error.

               

              -> Bluetooth headsets uses standard bluetooth profiles ( A2DP profile or Headsets Profile ) and not BLE profiles. Bluetooth communication is different than BLE communication.

               

              -> You may like to have a look at our Code Example " External Memory OTA Bootloader "  which uses the same concept of receiving an image over BLE and writing it to external memory.

               

              -Gyan

              1 of 1 people found this helpful