esp32-cam publish image to mqtt
Posts: 4
Joined: Tue Aug 21, 2018 8:57 pm

esp32-cam publish image to mqtt

Postby » Fri Jan 03, 2020 8:48 pm

I want to publish image capture through ESP32-CAM to MQTT. Have following code in loop()

Code: Select all

#include "esp_camera.h"
#include "Arduino.h"
#include "soc/soc.h"           // Disable brownour problems
#include "soc/rtc_cntl_reg.h"  // Disable brownour problems
#include "driver/rtc_io.h"
#include <Base64.h>
#include <WiFi.h>
#include <PubSubClient.h>
void loop() {
  // Init Camera
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);

  camera_fb_t * fb = NULL;

  // Take Picture with Camera
  fb = esp_camera_fb_get();  
  if(!fb) {
    Serial.println("Camera capture failed");

  // Path where new picture will be saved in SD Card
  String path = "/picture.jpg";

  fs::FS &fs = SD_MMC; 
  Serial.printf("Picture file name: %s\n", path.c_str());

  //File file =, FILE_WRITE);
    Serial.println("Failed to open file in writing mode");
  else {
    file.write(fb->buf, fb->len); // payload (image), payload length


  // Turns off the ESP32-CAM white on-board LED (flash) connected to GPIO 4
  pinMode(4, OUTPUT);
  digitalWrite(4, LOW);

  Serial.println("Going to sleep now");
  Serial.println("This will never be printed");
But this one failing with

Code: Select all

Alternatives for avr/pgmspace.h: []/home/root/Arduino/libraries/Base64/src/Base64.cpp:11:26: fatal error: avr/pgmspace.h: No such file or directory

compilation terminated.
  -> candidates: []
Multiple libraries were found for "Base64.h"
 Used: /home/root/Arduino/libraries/Base64
Multiple libraries were found for "WiFi.h"
 Used: /home/root/.arduino15/packages/esp32/hardware/esp32/1.0.4/libraries/WiFi
 Not used: /opt/arduino-1.8.10/libraries/WiFi
Multiple libraries were found for "PubSubClient.h"
 Used: /home/root/Arduino/libraries/PubSubClient
Using library Base64 at version 0.0.1 in folder: /home/root/Arduino/libraries/Base64
Using library WiFi at version 1.0 in folder: /home/root/.arduino15/packages/esp32/hardware/esp32/1.0.4/libraries/WiFi
Using library PubSubClient at version 2.7 in folder: /home/root/Arduino/libraries/PubSubClient
exit status 1
Error compiling for board ESP32 Wrover Module.
which is because of Base64.h library. Is there any other way I can encode image to base64 to publish to MQTT

Who is online

Users browsing this forum: No registered users and 11 guests