Send File via BLE to ESP32

Hello i just want to get an Idea how to send a file to ESP32 (Arduino)

All similar Topics said its not possible.

My Situation:
File is a Binary (Update.bin) for ESP32 Firmware update
File Size: ~700KBytes
And i want to transfer it via BLE (String?)

I did all that the other Way around: Sending Logfiles (Log.txt) as a String from ESP32 via BLE to APP
Files are arround 160KBytes and the Speed is 15KByte/Sec

But with ESP32 i can Split the Logfiles in 500Byte Buffer. With App i just save everything received to File.

This should work the other Way around.
But how can i read files and split them in 500Byte packets?
Is it possible with 700KByte Files?

Maybe some can give me some advise

Assuming you have enough RAM to hold the entire file on the ESP32 side, I imagine that it's possible although given the packet-based nature of BLE you'll probably want to include both an index as to what chunk you're sending as well as a checksum at the end so you can ensure that the firmware image didn't get corrupted. The real challenge I think you're going to have is that the built-in App Inventor File component really only handles files as text. There may be extensions that would allow you to read the file as binary and manipulate it as such for sending the data to the peripheral.

i did some test to read the .bin file and send it with BLE to ESP32

but...

  1. problem: i cant spilt the file text to BLE compatible packet size
    with segment text i cant spilt the text, but it counts in readable Chars. So split from 50 to 100 results in over 100 chars (50 readable and 50 unreadable) that are send with BLE

but this works....the right Bytes are send to ESP32. But i cant really produce correct buffers

  1. problem. i tried to convert the text to list and send the list via BLE. But i cant convert string to Number (write bytes) -> show error
    and with WriteString i just get 4 bytes

    blocks2

maybe i'am missing something?

i got it working (test with the first 200 Chars/Bytes),

But how can (should) i pause the BLE Packtes? The filesize is arround 700.000 bytes and i do not have enough RAM on ESP32.

i could save an RAM array of 10.000 Bytes easily and write 500 bytes packets to SD Card hoping that a 10.000 Byte RingBuffer is enough.

or i have to use a time (clock) to send the file steps -> would be the best but i think it will cause more BLE Traffic and less throuhput

So, i little update here....

the BLE Extension is very slow -> about 1sek for 500Bytes, so there is enough time for SD Write

But now the main Problem is that the File on ESP32 SD Card is different to the File in Assets

  1. there are some additional zeros ( i think after every BLE Paket) -> that could be solved
  2. the Encoding of both files is different. Original File is Encoded in ANSI and the transmitted File if UTF-8

Does anyone know where the enconding is changed?
FileRead?
Label Text?
BLE String send?

ESP32 has BLE and classic Bluetooth, this is my experience with classic Bluetooth HC-06:

Thank you Juan_Antonio,

i know your example, but i never found out why you are using the Base64 encoding?

i checked my files with a hex viewer and they are similar.
But there are some errors (i have to find why) and the calculated transmission time is 25min!

Thats too much. So i have to wait for a new Version of the BLE Extension which can send 512 Bytes with one BLE Packet.
From ESP32 to APP i can already send 512 BYtes and its much faster to transmit it the other direction

There are some strange things:

i wrote a binary file fron 0x00 to 0xff

app inventor reads the file an put every byte in the list and tells me List Lenght is 256 -> correct
on ESP32 i get these 256 Bytes

But just 0x00 to 0x7F are correct

Here the output:
0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15
16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B
2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41
42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57
58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D
6E 6F 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F EF BF BD EF
EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF
EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF
EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF
EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF
EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF
EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF BF BD EF

i did some research on Base64 and now i'am understanding why Juan use it and why my binary date is not transmitted correctly.
i will do some more tests.....but at the moment i will stop it because the BLE connection with 20 Bytes per Packet is much to slow. I have to wait for the supporting of MTU Size packet lenght.

hi F3John. I'm also trying to solve this problem right now. Have you made any progress?