What is a good practice to transfer image data through MQTT

zhaozhaozhao
Posts: 21
Joined: Tue Apr 13, 2021 8:43 am

What is a good practice to transfer image data through MQTT

Postby zhaozhaozhao » Sat Sep 25, 2021 6:34 pm

Hello all, again thanks for your time in advance.

I am using an ArduCAM Mini 2MP Plus camera module for my application. This camera module has an internal JPEG compressor and outputs compressed image binary. Now my idea is transfer the binary directly to an edge device (Nodered) through MQTT and render the image there. No local image decompression or processing is done inside the MCU.

I have tried encode the binary to base64. For a 320x240 Resolution image with format RGB565, the original binary size is around 4KB, and the encoded string has around 5KB. But for larger resolutions I am wondering whether it is a good idea to enlarge the buffer size? For a 2M pixel image the encode string would reaches 217KB, which definitely exceeds ESP32's internal RAM size.

I want to separate the binary into batches. I choose a buffer size of multiple times of 6 so that there will be no padding after each base64-encode message. For each batch I put the encoded string to a json attched with a batch number (that increases more overhead!). In the edge device I concatenate the messages by their batch numbers. However, the edge decice need to check if any of the batches is missing or not received, I feel that would be very complicated.

What's more, even if I set a large enough buffer and encode the image in one run, MQTT seems cannot transfer so much data. As mentioned before, currently each image takes 5KB in base64. And I let the MCU send out message as fast as possible, now I reaches 15 fps. So the data amout would be around 80K per second. And I already see some frames cannot be received properly and the fps drops. Could it be too much for a MQTT server? I run a mosquitto server on my RaspPi wirelessly.

Do you know any good practice to transfer image through MQTT, or should I use HTTP instead?

Best Regards
Zhao

Who is online

Users browsing this forum: Bing [Bot] and 168 guests