esp32-cam publish image to mqtt

rp346@njit.edu
Posts: 5
Joined: Tue Aug 21, 2018 8:57 pm

esp32-cam publish image to mqtt

Postby rp346@njit.edu » 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);
    return;
  }

  camera_fb_t * fb = NULL;

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

  // 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 = fs.open(path.c_str(), FILE_WRITE);
  if(!file){
    Serial.println("Failed to open file in writing mode");
  } 
  else {
    file.write(fb->buf, fb->len); // payload (image), payload length

  }
  //file.close();
  esp_camera_fb_return(fb); 

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

  delay(2000);
  Serial.println("Going to sleep now");
  delay(2000);
  esp_deep_sleep_start();
  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.
ResolveLibrary(avr/pgmspace.h)
  -> 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: lbernstone and 24 guests