2

I have an ESP32-based device connected to the Internet using WiFi. Sometimes it needs to download a "large" file (200-300 MB) but it does not need to store it. Instead, it needs to send it via SPI to another device. So, my idea is:

  1. Open a "stream" channel with the remote server
  2. Download the file in chunks
  3. When a chunk is downloaded send it over SPI
  4. Continue until the whole file is downloaded and transmitted
  5. Download and send the MD5 to the external device as well in order to check the integrity of the received file

I'm not expecting more than 10 devices downloading the same file at the same time. And no more than 30 devices downloading any file at the same time.

As a rough estimation, the SPI communication has a bandwith of less than 1 Mbit/s.

Ideally, it should also offer resume/progress features to easily restart from a specific byte if the connection drops.

Is there a ready-to-use protocol for this purpose or do I have to write a server application by myself? It will be a commercial device: I'm afraid SSL is mandatory here to provide enough protection, isnt'it?

Rohit Gupta
  • 507
  • 2
  • 3
  • 18
Mark
  • 747
  • 1
  • 4
  • 13

1 Answers1

5

You might like to consider using https. It would mean not having to open special ports, not having to invent a protocol, and being able to test at one end with any of the available simple servers and at the other end using curl or similar tools from a Linux pc etc. You probably already have code to do http or https for your ESP32.

The http protocol has an optional header Range to request a given set of bytes from the url. For example, as shown in the linked article, if you add option -H 'Range: bytes=100-199' to a curl command you will get 100 bytes back, starting from offset 100. You also get some http headers that you need to skip over until you see \r\n\r\n. Note that unlike a normal request the http code is not "200 OK" but "206 Partial Content".

$ curl -s -0 -H 'Range: bytes=100-199' -o /tmp/out https://i.imgur.com/z4d4kWk.jpg
$ ls -l /tmp/out
-rw-r--r-- 1 user group 100 Nov 20 18:36 /tmp/out
meuh
  • 176
  • 2