Receiving and Decoding HD Images From ESP32-CAM With Node-Red (and MQTTPubSubClient)
by tnowroz in Circuits > Microcontrollers
86 Views, 0 Favorites, 0 Comments
Receiving and Decoding HD Images From ESP32-CAM With Node-Red (and MQTTPubSubClient)
.png)
I've found many unsolved threads of people failing to transmit HD or large sized image files over MQTT. Passing the Framebuffer and buffer length just works for most resolutions until you select the HD ones and starts resetting due to exceeding memory budget.
In this writeup, I'll walk through how to transmit HD images from ESP32 CAM over MQTT using the MQTTPubSubClient library, by dividing it in multiple payloads/chunks. Then decode the image back again.
If you are someone experienced, start from step 4
Supplies
- ESP32-CAM module
- Node-Red
- Arduino Framework
Start by Configuring the Image Sensor With Highest Resolution
Start by creating a Arduino Sketch or code example of ESP32-CAM module for template.
Uncomment definitions to select the AI-Thinker ESP32 CAM module in needed.
Connect to WiFi and MQTT
Subscribe to Necessary Topics
Publish an Image
How does publishImageWithMarkers() Work?
- Get the FrameBuffer from the image sensor
- Calculates the image size
- Define Maximum Allowable payload size.
- Calculates how many payloads needed to transmit the image.
- Start Transmission by sending "start" signal.
- Compose and send payload of pieces of FrameBuffer/Image
- End Transmission by sending "end" signal.
Receive and Decode on Node-Red

Parts of FrameBuffer needs to be sent to same MQTT Topic.
Connect the incoming payload to a function. Once an entire image is sent, it will write it to a file with jpg format.
Function to receive, compile and decode to image -
- Initialization: Get value of Global Variable - imageData. Define it as Buffer in undefined.
- Edge Case: "START" signal received - empty buffer for new image reception.
- Edge Case: "End" signal received - compile Buffer to image, and send it to File Write Block.
- Otherwise, none of the edge cases are true - keep adding image pieces/chunks into the image buffer and return nothing.
I've connected it to a file write
Look at My Baby Yoda and Arduino Sticker :)


Picture 1: Image Decoded at Node-Red canvas using Image Preview block (node-red-contrib-image-output)
Picture 2: A saved JPG file from ESP32-CAM, Decoded by Node-Red
Check My GitHub for Full Project Files
Full Project files (including Node-Red Flow) can be found at my GitHub:
https://github.com/TNeutron/Publishing-High-Resolution-Images-from-ESP32-CAM-to-Node-Red