BlynkEdgent with Firebase_ESP_Client

I am running Blynk Lib v1.3.2 on ESP32 using the Arduino IDE. I am using Edgent, since I require dynamic provisioning and OTA. I would like to post ESP CAM images (and other data) to secure Google storage (either Storage or Firebase). There are many ESP32-CAM examples here, but I have not found a total solution for my requirements:

  • Uses BlynkEdgent
  • Secure upload/post to cloud image storage (not FTP)
  • Secure URL to feed the Blynk App or Web Dashboard Image Widget (requires API token, or some authentication to view)

I have attempted to follow the (non-Blynk) ESP32-CAM to Firebase example here:

Unfortunately, the Firebase_ESP_Client does not connect with Edgent. I suspect there is a conflict between BlynkEdgent and Firebase_ESP_Client, or I am not setting up Firebase_ESP_Client correctly since it expects using WiFi.h. When I enable Firebase_ESP_Client, Blynk is lost and Firebase_ESP_Client repeats errors.

If there is a better way that I have missed that meets the above requirements, I would be interested in hearing them. Thanks!

Here is my cut down code:

//-----------------------------------------------------------------------------
//-- DEFINES ------------------------------------------------------------------
//-----------------------------------------------------------------------------

//-- Blynk IoT ----------------------------------------------------------------
/* Fill in information from your Blynk Template here */
/* Read more: https://bit.ly/BlynkInject */
#define BLYNK_TEMPLATE_ID "<TEMP_ID>"
#define BLYNK_TEMPLATE_NAME "<TEMP_NAME>"

#define BLYNK_FIRMWARE_VERSION        "0.1.99"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

//-- Firebase -----------------------------------------------------------------
#define API_KEY "<FIRE_API_KEY>"

#define USER_EMAIL "<FIRE_EMAIL>"
#define USER_PASSWORD "<FIRE_PASS>"

// #define STORAGE_BUCKET_ID "mydemo-demo.appspot.com"

// // Photo File Name to save in LittleFS
// #define FILE_PHOTO_PATH "/photo.jpg"
// #define BUCKET_PHOTO "/data/photo.jpg"

//-----------------------------------------------------------------------------
//-- INCLUDES -----------------------------------------------------------------
//-----------------------------------------------------------------------------

// I2C Devices
#include <Wire.h>

// Blynk IoT Service
#include "BlynkEdgent.h"

// Google Firebase
#include <Firebase_ESP_Client.h>
// #include <LittleFS.h>
// #include <FS.h>
#include <addons/TokenHelper.h>   // Provide the token generation process info.


//-----------------------------------------------------------------------------
//-- GLOBALS- -----------------------------------------------------------------
//-----------------------------------------------------------------------------
BlynkTimer sensorTimer;
BlynkTimer cameraTimer;

// Define Firebase Data object
FirebaseData fbdo;
FirebaseAuth fireAuth;
FirebaseConfig fireConfig;

//-----------------------------------------------------------------------------
//-- Function Definitions -----------------------------------------------------
//-----------------------------------------------------------------------------


//-- Sensor Timer Callback -----------------------------------------------------------
void sensorTimerCallback()
{
  BLYNK_LOG("[APP] Timer Callback");
}

//-- Camera Timer Callback -----------------------------------------------------------
void cameraTimerCallback()
{
  BLYNK_LOG("[APP] Camera Callback");
}

//-----------------------------------------------------------------------------
//-- SETUP --------------------------------------------------------------------
//-----------------------------------------------------------------------------
void setup()
{
  //-- Init I2C Bus -----------------------------------------------------------
  Wire.begin();

  //-- Init Debug Serial Port -------------------------------------------------
  Serial.begin(115200);
  delay(100);
  BLYNK_LOG("[APP] LOG Serial UP");

  //-- Blynk.io ---------------------------------------------------------------
  BlynkEdgent.begin();

  //-- Data Polling sensorTimer ------------------------------------------------
  sensorTimer.setInterval(5000L, sensorTimerCallback);    // 5 sec
  cameraTimer.setInterval(60000L, cameraTimerCallback);   // 60 sec

  //-- Firebase ---------------------------------------------------------------
  BLYNK_LOG("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);
  /* Assign the api key (required) */
  fireConfig.api_key = API_KEY;

  /* Assign the user sign in credentials */
  fireAuth.user.email = USER_EMAIL;
  fireAuth.user.password = USER_PASSWORD;

  /* Assign the callback function for the long running token generation task */
  fireConfig.token_status_callback = tokenStatusCallback; // see addons/TokenHelper.h

  // Comment or pass false value when WiFi reconnection will control by your code or third party library e.g. WiFiManager
  //Firebase.reconnectNetwork(true);

  // Since v4.4.x, BearSSL engine was used, the SSL buffer need to be set.
  // Large data transmission may require larger RX buffer, otherwise connection issue or data read time out can be occurred.
  //fbdo.setBSSLBufferSize(4096 /* Rx buffer size in bytes from 512 - 16384 */, 1024 /* Tx buffer size in bytes from 512 - 16384 */);

  BLYNK_LOG("[APP] Firebase Begin");
  Firebase.begin(&fireConfig, &fireAuth);

  /* Assign upload buffer size in byte */
  // Data to be uploaded will send as multiple chunks with this size, to compromise between speed and memory used for buffering.
  // The memory from external SRAM/PSRAM will not use in the TCP client internal tx buffer.
  //fireConfig.fcs.upload_buffer_size = 512;

}


//-----------------------------------------------------------------------------
//-- MAIN LOOP ----------------------------------------------------------------
//-----------------------------------------------------------------------------
void loop() 
{ 
  //-- Blynk.io Handler -------------------------------------------------------
  BlynkEdgent.run();
  sensorTimer.run(); // Initiates Blynktimer
  cameraTimer.run();
}

Here is the Console output:

rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13260
load:0x40080400,len:3028
entry 0x400805e4
[146] [APP] LOG Serial UP
[276] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.3.2 on ESP32

 #StandWithUkraine    https://bit.ly/swua


----------------------------------------------------
 Device:    Blynk GrowLight01-7WFD
 Firmware:  0.1.20 (build Feb 19 2024 15:01:13)
 Token:     OuB9 - •••• - •••• - ••••
 Platform:  ESP32 @ 240MHz
 Chip rev:  3
 SDK:       v4.4.5
 Flash:     16384K
 Free mem:  198104
----------------------------------------------------

>[301] Firebase Client v4.4.11


[301] [APP] Firebase Begin
Token info: type = id token (GITKit token), status = on request
Token info: type = id token (GITKit token), status = error
Token error: code: -4, message: connection lost
Token info: type = id token (GITKit token), status = on request
Token info: type = id token (GITKit token), status = error
Token error: code: -4, message: connection lost

The thing about the video that’s displayed in the app widget is that it can come from any source that generates suitable video content and places it in a publicly resolvable location.

For example, I use a Reolink CCTV camera to generate a video stream that is viewable in the Blynk video streaming widget of the app.

So, your ESP32 CAM doesn’t need to be running any Blynk software at all, it simply needs to generate suitable content and post it to a suitable location.

Of course, if you somehow want to control the ESP32 CAM from Blynk, as well as displaying the video stream - triggering a still image snapshot, controlling lights or a PTZ system, releasing a door/gate lock if the person is identified etc then you would need the device to connect to Blynk. But, your existing code doesn’t seem to include any of this functionality.

If you want to do WiFi provisioning and OTA updates of your ESP32 CAM module then there are solutions to handle those without Blynk, but it depends on the exact functionality you’re looking for.

Have you tried using the Firebase example you found to generate a video steam and see if you can view that in Blynk?

Pete.

Pete,
Thanks for the reply. I already have a BlynkEdgent application running a on the ESP32 with a number of sensors and control functions. I am working to add secure image capture and display, and cut down the code shown to the bare minimum to show the issue.

Also, note that I am not streaming video. The goal is to capture the occasional time-based image and post it to a server for the Blynk app/dash to pull the image from. I am already grabbing images successfully from the camera.

I think I’d use two devices, one for video and one for everything else.

Pete.