Sending image data to ESP over HTTP - Advice on approach

Hey there!

I am currently working on a project using an ESP32. In this project, I am requesting image data from a server. The image itself is 480x800 pixels. Each pixel has one of three values (red, black, white).

When sending an HTTP request to the server, and getting the image data as a response, I noticed, that I need to use the available resources on the ESP in a smart way, since simply requesting the raw image data seemed to require more than the available resources on the ESP32 (I received a code 200 responses but empty response string). When shortening down the response string, for example using a compression algorithm, I manage to receive the full response string. However, I then noticed, that decompression seems to be slow to do on the ESP32. Below you can see an overview of the different approaches I used to modify the sent data:

  1. Using no compression
    • Deconstructing the base image (Red, black, white) into two images (red, white <-> black, white) as bytearray
    • Base64-Encoding of the two bytearrays
      Response-size: 125 KB
  2. Using LZMA compression algorithm
    • Deconstructing the base image (Red, black, white) into two images (red, white <-> black, white) as bytearray
    • LZMA compression of the two bytearrays
    • Base64-Encoding of the two compressed variables
      Response-size: 5,8 KB

While the compression is great and helps a lot to save space in the request, I didn't find any Arduino/ESP library, that implemented LZMA decompression while also seeming widely accepted/well maintained.

I can adjust the server code to implement any common compression method, or possibly also implement a custom-made one since there are only 3 possible values for each pixel. The server-side code is written in Python.

How would you go about setting up the general software on the ESP and on the server for requesting the image data?

One of my ESP32's does the image transfer thing using FTP.

Might or might be a solution that you can use.

1 Like

There is no need to use base64 encoding, you can send your image data as binary. a 480x800x2 image would be about 94kB

1 Like

Thanks for the suggestion, I will try that!

From your experience, would you say that it should be no problem to receive a 94KB large response with the ESP32?

I've never used an ESP32 so can't say...

What are you going to do with the image once you have it?

I do not see there being an issue receiving a 100K image file.

If the image file is to exceed 100K, then use a ESP32 WROVER and put the receive buffer into PSRAM. I get a little less then 4MB of download space under the Arduino IDE with PSRAM. If more PSRAM access is needed use the ESPRESSIFF IDF.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.