Skip to content

Commit

Permalink
Fix the RTDB session close handle crashed and others bugs fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Feb 21, 2021
1 parent 64556ba commit 704a295
Show file tree
Hide file tree
Showing 25 changed files with 251 additions and 152 deletions.
2 changes: 1 addition & 1 deletion 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 v 2.0.2
Google's Firebase Arduino Client Library for ESP8266 and ESP32 v 2.0.3


This library supports ESP8266 and ESP32 MCU from Espressif. The following are platforms in which the libraries are also available (RTDB only).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ void setup()
/** The user UID set to empty to sign in as admin */
auth.token.uid = "";

/** The scope of the OAuth2.0 authentication
* If you wan't this access token for others Google Cloud Services.
*/
//config.signer.tokens.scope = "Google Scope 1 Url, Google Scope 2 Url,..";

Firebase.reconnectWiFi(true);

/* Now we start to signin using access token */
Expand Down
2 changes: 1 addition & 1 deletion examples/Firestore/Import_Documents/Import_Documents.ino
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void setup()
Serial.println("------------------------------------");
Serial.println("Import documents from the Storage bucket...");

if (Firebase.Firestore.importDocuments(&fbdo, FIREBASE_PROJECT_ID, "" /* databaseId can be (default) or empty */, STORAGE_BUCKET_ID, "test_path" /* The path in the Firebase Storage bucket to store the data */, "" /* Which collection ids to export. Unspecified means all collections. */))
if (Firebase.Firestore.importDocuments(&fbdo, FIREBASE_PROJECT_ID, "" /* databaseId can be (default) or empty */, STORAGE_BUCKET_ID, "test_path" /* The path in the Firebase Storage bucket to store the data */, "" /* Which collection ids to import. Unspecified means all collections. */))
{
Serial.println("PASSED");
Serial.println("------------------------------------");
Expand Down
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Migrate from Firebase-ESP32 or Firebase-ESP8266 library to Firebase-ESP-Client library


This library includes the Firebase Storage fnctions and the Firebase Cloud Messageing upgrades.
This library includes the Firebase and Google Cloud Storage fnctions, Cloud Firestore, Cloud Functions and the Firebase Cloud Messageing upgrades.

The major changes from Firebase-ESP32 or Firebase-ESP8266 library are.

* All Firebase Realtime database functions moved from Firebase class to Firebase.RTDB class.
* All Firebase Realtime database functions moved from Firebase class to Firebase.RTDB member class.

* All parameters in RTDB functions are the pointer to the variables unless the String type value.

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.0.2",
"version": "2.0.3",
"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.0.2
version=2.0.3

author=Mobizt

Expand Down
4 changes: 2 additions & 2 deletions src/Firebase_ESP_Client.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h version 2.0.2
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h version 2.0.3
*
* This library supports Espressif ESP8266 and ESP32
*
* Created February 18, 2021
* Created February 21, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2020, 2021 K. Suwatchai (Mobizt)
Expand Down
4 changes: 2 additions & 2 deletions src/Firebase_ESP_Client.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h version 2.0.2
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h version 2.0.3
*
* This library supports Espressif ESP8266 and ESP32
*
* Created February 18, 2021
* Created February 21, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2020, 2021 K. Suwatchai (Mobizt)
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 v 2.0.2
Google's Firebase Arduino Client Library for ESP8266 and ESP32 v 2.0.3


## Global functions
Expand Down
18 changes: 15 additions & 3 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ enum fb_esp_method
m_set_priority,
};

enum fb_esp_http_connection_type
{
fb_esp_http_connection_type_undefined,
fb_esp_http_connection_type_keep_alive,
fb_esp_http_connection_type_close
};

enum fb_esp_settings_provider_type
{
auth_provider_type_login,
Expand Down Expand Up @@ -387,6 +394,7 @@ struct fb_esp_auth_token_info_t
std::string legacy_token;
std::string auth_type;
std::string jwt;
std::string scope;
unsigned long expires = 0;
fb_esp_auth_token_type token_type = token_type_undefined;
fb_esp_auth_token_status status = token_status_uninitialized;
Expand Down Expand Up @@ -551,7 +559,7 @@ struct fb_esp_fcs_file_list_item_t

typedef struct fb_esp_gcs_upload_status_info_t
{
size_t progress;
size_t progress = 0;
fb_esp_gcs_upload_status status = fb_esp_gcs_upload_status_unknown;
std::string localFileName = "";
std::string remoteFileName = "";
Expand Down Expand Up @@ -583,11 +591,12 @@ struct fb_esp_rtdb_info_t
bool stream_data_changed = false;
bool stream_path_changed = false;
bool data_available = false;
bool keep_alive = false;
fb_esp_http_connection_type http_req_conn_type = fb_esp_http_connection_type_undefined;
fb_esp_http_connection_type http_resp_conn_type = fb_esp_http_connection_type_undefined;
bool data_mismatch = false;
bool path_not_found = false;
bool pause = false;
bool stream_stop = false;
bool stream_stop = true;

uint8_t connection_status = 0;
uint32_t queue_ID = 0;
Expand Down Expand Up @@ -932,6 +941,9 @@ struct fb_esp_session_info_t
bool chunked_encoding = false;
bool connected = false;
bool classic_request = false;
std::string host = "";
unsigned long last_conn_ms = 0;
const uint32_t conn_timeout = 3 * 60 * 1000;

uint16_t resp_size = 2048;
int http_code = -1000;
Expand Down
13 changes: 9 additions & 4 deletions src/firestore/FB_Firestore.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Cloud Firestore class, Forestore.cpp version 1.0.2
* Google's Cloud Firestore class, Forestore.cpp version 1.0.3
*
* This library supports Espressif ESP8266 and ESP32
*
* Created February 18, 2021
* Created February 21, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2020, 2021 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -534,12 +534,15 @@ bool FB_Firestore::firestore_sendRequest(FirebaseData *fbdo, struct fb_esp_fires

if (ret == 0)
{
fbdo->_ss.connected = true;
if (handleResponse(fbdo))
{
Signer.getCfg()->_int.fb_processing = false;
return true;
}
}
else
fbdo->_ss.connected = false;

Signer.getCfg()->_int.fb_processing = false;

Expand All @@ -548,12 +551,14 @@ bool FB_Firestore::firestore_sendRequest(FirebaseData *fbdo, struct fb_esp_fires

void FB_Firestore::rescon(FirebaseData *fbdo, const char *host)
{
if (!fbdo->_ss.connected || fbdo->_ss.con_mode != fb_esp_con_mode_firestore || strcmp(host, _host.c_str()) != 0)
if (!fbdo->_ss.connected || millis() - fbdo->_ss.last_conn_ms > fbdo->_ss.conn_timeout || fbdo->_ss.con_mode != fb_esp_con_mode_firestore || strcmp(host, fbdo->_ss.host.c_str()) != 0)
{
fbdo->_ss.last_conn_ms = millis();
fbdo->closeSession();
fbdo->setSecure();
}
_host = host;

fbdo->_ss.host = host;
fbdo->_ss.con_mode = fb_esp_con_mode_firestore;
}

Expand Down
5 changes: 2 additions & 3 deletions src/firestore/FB_Firestore.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Cloud Firestore class, Forestore.h version 1.0.2
* Google's Cloud Firestore class, Forestore.h version 1.0.3
*
* This library supports Espressif ESP8266 and ESP32
*
* Created February 18, 2021
* Created February 21, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2020, 2021 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -247,7 +247,6 @@ class FB_Firestore

private:
UtilsClass *ut = nullptr;
std::string _host = "";
void begin(UtilsClass *u);
void rescon(FirebaseData *fbdo, const char *host);
bool connect(FirebaseData *fbdo);
Expand Down
14 changes: 9 additions & 5 deletions src/functions/FB_Functions.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Cloud Functions class, Functions.cpp version 1.0.1
* Google's Cloud Functions class, Functions.cpp version 1.0.2
*
* This library supports Espressif ESP8266 and ESP32
*
* Created February 18, 2021
* Created February 21, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2020, 2021 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -816,7 +816,7 @@ bool FB_Functions::functions_sendRequest(FirebaseData *fbdo, struct fb_esp_funct
}

ut->appendP(header, fb_esp_pgm_str_32);
ut->appendP(header, fb_esp_pgm_str_36);
ut->appendP(header, fb_esp_pgm_str_34);
ut->appendP(header, fb_esp_pgm_str_21);

fbdo->_ss.http_code = FIREBASE_ERROR_HTTPC_ERROR_NOT_CONNECTED;
Expand All @@ -829,6 +829,7 @@ bool FB_Functions::functions_sendRequest(FirebaseData *fbdo, struct fb_esp_funct

if (ret == 0)
{
fbdo->_ss.connected = true;
if (req->requestType == fb_esp_functions_request_type_upload)
{
int available = Signer.getCfg()->_int.fb_file.available();
Expand Down Expand Up @@ -875,19 +876,22 @@ bool FB_Functions::functions_sendRequest(FirebaseData *fbdo, struct fb_esp_funct
return true;
}
}
else
fbdo->_ss.connected = false;

Signer.getCfg()->_int.fb_processing = false;
return false;
}

void FB_Functions::rescon(FirebaseData *fbdo, const char *host)
{
if (!fbdo->_ss.connected || fbdo->_ss.con_mode != fb_esp_con_mode_functions || strcmp(host, _host.c_str()) != 0)
if (!fbdo->_ss.connected || millis() - fbdo->_ss.last_conn_ms > fbdo->_ss.conn_timeout || fbdo->_ss.con_mode != fb_esp_con_mode_functions || strcmp(host, fbdo->_ss.host.c_str()) != 0)
{
fbdo->_ss.last_conn_ms = millis();
fbdo->closeSession();
fbdo->setSecure();
}
_host = host;
fbdo->_ss.host = host;
fbdo->_ss.con_mode = fb_esp_con_mode_functions;
}

Expand Down
5 changes: 2 additions & 3 deletions src/functions/FB_Functions.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Cloud Functions class, Functions.h version 1.0.1
* Google's Cloud Functions class, Functions.h version 1.0.2
*
* This library supports Espressif ESP8266 and ESP32
*
* Created February 18, 2021
* Created February 21, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2020, 2021 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -262,7 +262,6 @@ class FB_Functions
bool listOperations(FirebaseData *fbdo, const char *filter, int pageSize, const char *pageToken);

private:
std::string _host = "";
fb_esp_functions_status _function_status = fb_esp_functions_status_CLOUD_FUNCTION_STATUS_UNSPECIFIED;
UtilsClass *ut = nullptr;
unsigned long _lasPollMs = 0;
Expand Down
Loading

0 comments on commit 704a295

Please sign in to comment.