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