Firebase Storage File Upload Error or Multiple Libraries Issue

rt2gaurav
Posts: 6
Joined: Tue Oct 19, 2021 3:59 pm

Firebase Storage File Upload Error or Multiple Libraries Issue

Postby rt2gaurav » Fri Jul 08, 2022 4:31 pm

Issue Description
I am using ESP32 Wroom 4MB and I am trying to upload a file to Firebase Storage from SD card. I am getting fcs callback error as "response payload read timed out due to network issue or too large data size" which looks similar to the issue #315 in Github Library https://github.com/mobizt/Firebase-ESP- ... ssions/315. I have two Firebase libraries ([Firebase-ESP-Client]https://github.com/mobizt/Firebase-ESP-Client & Firebase-ESP32 https://github.com/mobizt/Firebase-ESP32 which was installed using Arduino's Library Manager.

I am using hspi pins for reading and writing the files from my SD card. I am sharing the example code to upload a file to Firebase Storage with slightly modified code for my hspi pins which used to work earlier but after that I updated the arduino core and Firebase libraries but since then it stopped working. I was using SPI call function to access the SD files which used to work. In the sample code below I have commented the hspi part to use SdFat library https://github.com/greiman/SdFat but that also gives me same error. I am not sure if I have configured my FirebaseFS.h and SDHelper.h library. I have attached my FirebaseFS.h and SDHelper.txt library for your reference let me know if I need to modify anything else. I haven't modified anything in SdFat library.

I have tried using ESP core 2.0.1,2.0.3 & latest 2.0.4 versions. For Firebase library I have tried using 4.0.0 for both libraries. I have also tried Firebase ESP client with v3.3.3. Since I am using Firebase32 example for cloud storage upload I am not sure what version of Firebase32 library I should use as you have shared v3.3.3 of Firebase ESP Client to be working. Since there are two libraries it gets little bit more confusing and complicated for me as it might be causing conflicting issues due to different versions and I don't know what files are used during compilation of the code.


Questions

1. What version of library I should use for Firebase32, Firebase ESP Client, SdFat as well as ESP Core.
2. To be on safe side I update FirebaseFS and SdHelper files in both library location. Do I need to update anything else? Does my file configuration look good to use SdFat with hspi pins
3. What should I comment out in library and in my code below if I want to use HSPI calls from my code. Currently HSPI part of code is commented below
4. I have disabled OTA to get extra memory on my ESP32 and currently having 2MB for APP and 2MB for SPIFFS. Could this cause an issue?


IDE and its version:
- Arduino
- Version [1.8.19]

ESP32 Arduino Core SDK version
- Version [2.0.1, 2.0.3, 2.0.4]

esptool.py
- Version [3.1]

Firebase ESP client
- Version [3.3.3, 4.0.0]// I don't remember which version I was using earlier when my code used to work with hspi calls

Firebase32
- Version [4.0.0] // I don't remember which version I was using earlier when my code used to work with hspi calls

SdFat
- Version [2.2.0]



[Codebox]
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include "SdFat.h"
#include <Firebase_ESP_Client.h>
#include <FirebaseESP32.h>
// Provide the token generation process info.
#include <addons/TokenHelper.h>

// Provide the SD card interfaces setting and mounting
#include <addons/SDHelper.h>

/* 1. Define the WiFi credentials */
#define WIFI_SSID "abc"
#define WIFI_PASSWORD "abc"

/* 2. Define the API Key */
#define API_KEY ""

/* 3. Define the user Email and password that alreadey registerd or added in your project */
#define USER_EMAIL ""
#define USER_PASSWORD ""

/* 4. Define the Firebase storage bucket ID e.g bucket-name.appspot.com */
#define STORAGE_BUCKET_ID ""

// Define Firebase Data object
FirebaseData fbdo;

FirebaseAuth auth;
FirebaseConfig config;

bool taskCompleted = false;
char user_id[24] = "abc";
char workout_id[32] = "123";
const String Board_id = "LL02";
char FB_filename[30] = "";
char Ffilename[30] = "testgb";
String FB_url;
//#define HSPI_MISO 12
//#define HSPI_MOSI 13
//#define HSPI_SCLK 14
//#define HSPI_SS 15
//SPIClass hspi = SPIClass(HSPI);
//#include <Wire.h>
//#include <SPI.h>
//#include <string.h>
//#include "Arduino.h"
//#include <stdlib.h>
void setup()
{

Serial.begin(115200);
Serial.println();
Serial.println();

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();

Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);

/* Assign the api key (required) */
config.api_key = API_KEY;

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

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

#if defined(ESP8266)
// required for large file data, increase Tx size as needed.
fbdo.setBSSLBufferSize(1024 /* Rx buffer size in bytes from 512 - 16384 */, 1024 /* Tx buffer size in bytes from 512 - 16384 */);
#endif

Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);

/* 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.
config.fcs.upload_buffer_size = 512;

// hspi.begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS);
// delay(5000);
// if (!SD.begin(HSPI_SS, hspi, 16000000)) {
// Serial.println("Card Mount Failed");
// return;
// }
// if use SD card, mount it.
SD_Card_Mounting(); // See src/addons/SDHelper.h
Serial.println("assign_FB_filename()");
sprintf(FB_filename, "/%s.json", Ffilename);
}

// The Firebase Storage upload callback function
void fcsUploadCallback(FCS_UploadStatusInfo info)
{
if (info.status == fb_esp_fcs_upload_status_init)
{
Serial.printf("Uploading file %s (%d) to %s\n", info.localFileName.c_str(), info.fileSize, info.remoteFileName.c_str());
}
else if (info.status == fb_esp_fcs_upload_status_upload)
{
Serial.printf("Uploaded %d%s\n", (int)info.progress, "%");
}
else if (info.status == fb_esp_fcs_upload_status_complete)
{
Serial.println("Upload completed\n");
FileMetaInfo meta = fbdo.metaData();
Serial.printf("Name: %s\n", meta.name.c_str());
Serial.printf("Bucket: %s\n", meta.bucket.c_str());
Serial.printf("contentType: %s\n", meta.contentType.c_str());
Serial.printf("Size: %d\n", meta.size);
Serial.printf("Generation: %lu\n", meta.generation);
Serial.printf("Metageneration: %lu\n", meta.metageneration);
Serial.printf("ETag: %s\n", meta.etag.c_str());
Serial.printf("CRC32: %s\n", meta.crc32.c_str());
Serial.printf("Token: %s\n", meta.downloadTokens.c_str());
Serial.printf("Download URL: %s\n\n", fbdo.downloadURL().c_str());
}
else if (info.status == fb_esp_fcs_upload_status_error)
{
Serial.printf("Upload failed, %s\n", info.errorMsg.c_str());
}
}

void loop()
{

// Firebase.ready() should be called repeatedly to handle authentication tasks.

if (Firebase.ready() && !taskCompleted)
{
taskCompleted = true;
char FB_filelocation[192];
sprintf(FB_filelocation, "test/User/%s/%s/%s%s", user_id, Board_id, workout_id, FB_filename);
Serial.println("\nUpload file...\n");
//hspi.begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS);
// MIME type should be valid to avoid the download problem.
// The file systems for flash and SD/SDMMC can be changed in FirebaseFS.h.
if (Firebase.Storage.upload(&fbdo, STORAGE_BUCKET_ID /* Firebase Storage bucket id */, FB_filename /* path to local file */, mem_storage_type_sd /* memory storage type, mem_storage_type_flash and mem_storage_type_sd */, FB_filelocation /* path of remote file stored in the bucket */, "application/json" /* mime type */)) {
//Serial.printf("\nDownload URL: %s\n", fbdo.downloadURL().c_str());
FB_url = fbdo.downloadURL();
}
else {
Serial.println(fbdo.errorReason());
}
}
}
[/Codebox]
Attachments
FirebaseFS.h
(2.36 KiB) Downloaded 349 times
SDHelper.h
(2.2 KiB) Downloaded 343 times

Momin786
Posts: 13
Joined: Mon Jul 11, 2022 7:52 am
Contact:

Re: Firebase Storage File Upload Error or Multiple Libraries Issue

Postby Momin786 » Mon Jul 11, 2022 8:04 am

You can use any version of the Firebase library but it requires a specific version of the Json library. For me, it works with ArduinoJson library 5.13.3 for me. I followed this tutorial https://microcontrollerslab.com/google- ... duino-ide/and it worked.
I create ESP32 tutorials and Projects using ESP-IDF https://esp32tutorials.com/

Who is online

Users browsing this forum: No registered users and 65 guests