Skip to content

Commit

Permalink
Fix the SD check and RTDB get File issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed May 17, 2021
1 parent 3bed0e7 commit 4d2a7d9
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Firebase Arduino Client Library for ESP8266 and ESP32


Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.2.0
Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.2.1


This library supports ESP8266 and ESP32 MCU from Espressif. The following are platforms in which the libraries are also available (RTDB only).
Expand Down Expand Up @@ -184,7 +184,7 @@ fbdo.setResponseSize(1024); //minimum size is 1024 bytes

### Important Information

In ESP8266 Aruino Core SDK v3.x.x
In ESP8266 Arduino Core SDK v3.x.x

The free heap is significantly reduced as much as 5-6 kB from v2.7.4.

Expand Down
19 changes: 17 additions & 2 deletions examples/RTDB/File/File.ino
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ void setup()
fbdo.setResponseSize(1024);

//Mount SD card
if (!SD.begin(15))
#if defined(ESP32)
if (!Firebase.sdBegin(13, 14, 2, 15)) //SS, SCK,MISO, MOSI
#elif defined(ESP8266)
if (!Firebase.sdBegin(15)) //SS
#endif
{
Serial.println("SD Card mounted failed");
return;
Expand Down Expand Up @@ -122,7 +126,6 @@ void setup()
}

file.close();

}

void loop()
Expand Down Expand Up @@ -163,6 +166,12 @@ void loop()
Serial.println("PASSED");
Serial.println("DATA");

#if defined(ESP32)
Firebase.sdBegin(13, 14, 2, 15); //SS, SCK,MISO, MOSI
#elif defined(ESP8266)
Firebase.sdBegin(15); //SS
#endif

//Readout the downloaded file
file = SD.open("/file2.txt", FILE_READ);
int i = 0;
Expand Down Expand Up @@ -234,6 +243,12 @@ void loop()
Serial.println("PASSED");
Serial.println("DATA");

#if defined(ESP32)
Firebase.sdBegin(13, 14, 2, 15); //SS, SCK,MISO, MOSI
#elif defined(ESP8266)
Firebase.sdBegin(15); //SS
#endif

//Readout the downloaded file
file = SD.open("/file3.txt", FILE_READ);
int i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,16 @@ void loop()
{
taskCompleted = true;

#if defined(ESP32)
Firebase.sdBegin(13, 14, 2, 15); //SS, SCK,MISO, MOSI
#elif defined(ESP8266)
Firebase.sdBegin(15); //SS
#endif

Serial.println("------------------------------------");
Serial.println("Download file test...");
//The file systems for flash and SD/SDMMC can be changed in FirebaseFS.h.
if (Firebase.Storage.download(&fbdo, STORAGE_BUCKET_ID /* Firebase Storage bucket id */, "path/to/file/filename" /* path of remote file stored in the bucket */, "/path/to/save/filename" /* path to local file */, mem_storage_type_flash /* memory storage type, mem_storage_type_flash and mem_storage_type_sd */))
if (Firebase.Storage.download(&fbdo, STORAGE_BUCKET_ID /* Firebase Storage bucket id */, "path/to/file/filename" /* path of remote file stored in the bucket */, "/path/to/save/filename" /* path to local file */, mem_storage_type_sd /* memory storage type, mem_storage_type_flash and mem_storage_type_sd */))
{
Serial.println("PASSED");
Serial.println("------------------------------------");
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Firebase Arduino Client Library for ESP8266 and ESP32",
"version": "2.2.0",
"version": "2.2.1",
"keywords": "communication, REST, esp32, esp8266, arduino",
"description": "This client library provides the functions to work with Firebase Realtime database, Firestore, Storage and Cloud messaging.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=Firebase Arduino Client Library for ESP8266 and ESP32

version=2.2.0
version=2.2.1

author=Mobizt

Expand Down
2 changes: 1 addition & 1 deletion src/Firebase_ESP_Client.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h version 2.2.0
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h version 2.2.1
*
* This library supports Espressif ESP8266 and ESP32
*
Expand Down
2 changes: 1 addition & 1 deletion src/Firebase_ESP_Client.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h version 2.2.0
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h version 2.2.1
*
* This library supports Espressif ESP8266 and ESP32
*
Expand Down
2 changes: 1 addition & 1 deletion src/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Firebase Arduino Client Library for ESP8266 and ESP32


Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.2.0
Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.2.1


The default filessystem used in the library is flash and SD.
Expand Down
6 changes: 4 additions & 2 deletions src/Utils.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Firebase Util class, Utils.h version 1.0.11
* Google's Firebase Util class, Utils.h version 1.0.12
*
* This library supports Espressif ESP8266 and ESP32
*
* Created May 4, 2021
* Created May 17, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2021 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -1608,6 +1608,8 @@ class UtilsClass

std::string().swap(filepath);

config->_int.fb_sd_rdy = true;

return true;
}

Expand Down
21 changes: 17 additions & 4 deletions src/rtdb/FB_RTDB.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Firebase Realtime Database class, FB_RTDB.cpp version 1.0.15
* Google's Firebase Realtime Database class, FB_RTDB.cpp version 1.0.16
*
* This library supports Espressif ESP8266 and ESP32
*
* Created May 7, 2021
* Created May 17, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2021 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -3580,8 +3580,23 @@ bool FB_RTDB::processRequest(FirebaseData *fbdo, struct fb_esp_rtdb_request_info
fbdo->setQuery(req->data.query);
}
else if (req->data.type == d_file)
{
fbdo->_ss.rtdb.file_name = req->filename;

if (req->method == m_get)
{
if (req->storageType == mem_storage_type_flash && !Signer.getCfg()->_int.fb_flash_rdy)
ut->flashTest();
else if (req->storageType == mem_storage_type_sd && !Signer.getCfg()->_int.fb_sd_rdy)
ut->sdTest(Signer.getCfg()->_int.fb_file);

if (Signer.getCfg()->_int.fb_flash_rdy)
Signer.getCfg()->_int.fb_file = FLASH_FS.open(fbdo->_ss.rtdb.file_name.c_str(), "w");
else if (Signer.getCfg()->_int.fb_sd_rdy)
Signer.getCfg()->_int.fb_file = SD_FS.open(fbdo->_ss.rtdb.file_name.c_str(), FILE_WRITE);
}
}

fbdo->_ss.rtdb.queue_ID = 0;

uint8_t errCount = 0;
Expand Down Expand Up @@ -3732,7 +3747,6 @@ bool FB_RTDB::handleRequest(FirebaseData *fbdo, struct fb_esp_rtdb_request_info_
if (!fbdo->reconnect() || !fbdo->tokenReady() || !fbdo->validRequest(req->path))
return false;


if ((req->method == m_put || req->method == m_post || req->method == m_patch || req->method == m_patch_nocontent || req->method == m_set_rules) && req->payload.length() == 0 && req->data.type != d_string && req->data.type != d_blob && req->data.type != d_file)
{
fbdo->_ss.http_code = FIREBASE_ERROR_HTTP_CODE_BAD_REQUEST;
Expand Down Expand Up @@ -3778,7 +3792,6 @@ bool FB_RTDB::handleRequest(FirebaseData *fbdo, struct fb_esp_rtdb_request_info_
}
else if (req->method == m_download || (req->data.type == d_file && req->method == m_get))
{

if (!waitResponse(fbdo))
{
fbdo->closeSession();
Expand Down
4 changes: 2 additions & 2 deletions src/rtdb/FB_RTDB.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Firebase Realtime Database class, FB_RTDB.h version 1.0.15
* Google's Firebase Realtime Database class, FB_RTDB.h version 1.0.16
*
* This library supports Espressif ESP8266 and ESP32
*
* Created May 7, 2021
* Created May 17, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2021 K. Suwatchai (Mobizt)
Expand Down

0 comments on commit 4d2a7d9

Please sign in to comment.