Has anyone here ever used a ESP32 CAM to send an image via MQTT? I'd like to know what are the parameters to initialize the camera with (resolution, jpeg quality, etc.), because once I receive the camera on the other side, it's highly compressed and to be frank really ugly.

I'm using FRAMESIZE_SVGA with jpeg quality of 12. I want the best of both worlds actually: I want a good quality image and I don't want to overload the MQTT packet as I want to be able to receive the image faster. If resolution is high, it usually takes a few minutes to receive anything.

Here's my camera's config:

void initCamera() 
  // https://github.com/botabotlab/ESP32CAM-MQTT/blob/master/ESP32_Cam_MQTT/ESP32_Cam_MQTT.ino (initCamera and capturePicture)
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer   = LEDC_TIMER_0;
  config.pin_d0       = 5;
  config.pin_d1       = 18;
  config.pin_d2       = 19;
  config.pin_d3       = 21;
  config.pin_d4       = 36;
  config.pin_d5       = 39;
  config.pin_d6       = 34;
  config.pin_d7       = 35;
  config.pin_xclk     = 0;
  config.pin_pclk     = 22;
  config.pin_vsync    = 25;
  config.pin_href     = 23;
  config.pin_sscb_sda = 26;
  config.pin_sscb_scl = 27;
  config.pin_pwdn     = 32;
  config.pin_reset    = -1;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;

  // Change resolution of image here
  config.frame_size = FRAMESIZE_SVGA;
  config.jpeg_quality = 10;   
  config.fb_count     = 1;

  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
  • This question is not really answerable without knowing what is an acceptable compression and resolution. This is really up to you and what you will be using the images for, the update frequency of the images and what bandwidth you have available. As an example, some of my ESP32 cameras are controlled with MQTT but upload via HTTPS at 1280x1024 with quality 8, at around 150KB per uploaded image. But YMMV.
    – StarCat
    Dec 2, 2021 at 7:44
  • @StarCat Thank you. When you say you upload your images via HTTPS and you send MQTT commands. Do you mean you have a webserver running on the esp32 that posts the image and the MQTT commands are to activate that post?
    – Johnny boy
    Dec 3, 2021 at 6:49
  • Good question. I’m using MQTT for controlling the camera (resolution, quality, brightness, contrast, timing of the images etc) and I run a HTTPS client on the ESP32 that uploads each image to my web server that runs a PHP script to receive, store and show the images.
    – StarCat
    Dec 3, 2021 at 7:06
  • Interesting! Thank you!
    – Johnny boy
    Dec 3, 2021 at 16:14


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.