Skip to content

Commit

Permalink
FirebaseJson update
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Oct 26, 2019
1 parent 8b4fe51 commit b855a61
Show file tree
Hide file tree
Showing 7 changed files with 480 additions and 673 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Firebase Realtime Database Arduino Library for ESP8266


Google's Firebase Realtime Database Arduino Library for ESP8266 v 2.6.2
Google's Firebase Realtime Database Arduino Library for ESP8266 v 2.6.3


This library supports ESP8266 MCU from Espressif. The following are platforms which library are also available.
Expand Down Expand Up @@ -48,7 +48,7 @@ This library supports ESP8266 MCU from Espressif. The following are platforms wh

## Changes from earlier version

For library v 2.6.2 (comes with FirebaseJson v 2.2.2) or later, FirebaseJson object will be used to handle JSON data instead of JSON string which, the following functions are affected:
For library v 2.6.3 (comes with FirebaseJson v 2.2.3) or later, FirebaseJson object will be used to handle JSON data instead of JSON string which, the following functions are affected:

getJson, setJson, pushJson, updateNode and updateNodeSilent.

Expand Down Expand Up @@ -1022,7 +1022,7 @@ Serial.println(jsonStr);
The result of above code
{
"name": "Living Room",
"name": "Living Room",
"temp1": [
47,
34,
Expand All @@ -1047,7 +1047,7 @@ json.get(jsonData, "unit/temp2");

if (jsonData.success)
{
//Print tType of parsed data e.g string, int, double, bool, object, array, null and undefined
//Print type of parsed data e.g string, int, double, bool, object, array, null and undefined
Serial.println(jsonData.type);
//Print its content e.g.string, int, double, bool whereas object, array and null also can access as string
Serial.println(jsonData.stringValue);
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 ESP8266 Client

version=2.6.2
version=2.6.3

author=Mobizt

Expand Down
73 changes: 46 additions & 27 deletions src/FirebaseESP8266.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
/*
* Google's Firebase Realtime Database Arduino Library for ESP8266, version 2.6.2
* Google's Firebase Realtime Database Arduino Library for ESP8266, version 2.6.3
*
* October 25, 2019
* October 26, 2019
*
* Feature Added:
* - New none recursive FirebaseJson parser and builder.
* - Add support Json Array object and data type.
* - Generic function name for set, push and get.
* - FirebaseJson optimized for flash string usage.
*
* Feature Fixed:
* - Fixed multi-stream data object.
* - Corrupted Firebase rules data.
* - Invalid data type parse from payload with white-spaces.
* - Remove recursive stream operation that may lead to stack overflow
* - Fixed some flash string bugs in ESP8266 core v 2.5.2 that leads to wdt reset.
* - WiFi client unhandle access.
*
*
* This library provides ESP8266 to perform REST API by GET PUT, POST, PATCH, DELETE data from/to with Google's Firebase database using get, set, update
Expand Down Expand Up @@ -2580,6 +2574,26 @@ bool FirebaseESP8266::sendRequest(FirebaseData &dataObj, uint8_t storageType, co
return flag;
}

bool FirebaseESP8266::clientAvailable(FirebaseData &dataObj, bool available)
{
if (!reconnect(dataObj))
{
dataObj._httpCode = HTTPC_ERROR_CONNECTION_LOST;
return false;
}

if (!dataObj._net._client)
{
dataObj._httpCode = HTTPC_ERROR_CONNECTION_LOST;
return false;
}

if (available)
return dataObj._net._client->connected() && dataObj._net._client->available();
else
return dataObj._net._client->connected() && !dataObj._net._client->available();
}

bool FirebaseESP8266::getServerResponse(FirebaseData &dataObj)
{

Expand Down Expand Up @@ -2640,30 +2654,30 @@ bool FirebaseESP8266::getServerResponse(FirebaseData &dataObj)
int res = 0;

if (!dataObj._isStream)
while (dataObj._net._client->connected() && !dataObj._net._client->available() && millis() - dataTime < dataObj._net.timeout)
while (clientAvailable(dataObj, false) && millis() - dataTime < dataObj._net.timeout)
{
if (!apConnected(dataObj))
{
dataObj._httpCode = HTTPC_ERROR_CONNECTION_LOST;
return false;
}
delay(1);
}

dataTime = millis();

if (dataObj._net._client->connected() && !dataObj._net._client->available() && !dataObj._isStream)
if (clientAvailable(dataObj, false) && !dataObj._isStream)
dataObj._httpCode = HTTPC_ERROR_READ_TIMEOUT;

if (dataObj._net._client->connected() && dataObj._net._client->available())
if (clientAvailable(dataObj, true))
{
while (dataObj._net._client->available())
while (clientAvailable(dataObj, true))
{
if (dataObj._interruptRequest)
return cancelCurrentResponse(dataObj);

if (!apConnected(dataObj))
if (!reconnect(dataObj))
{
dataObj._httpCode = HTTPC_ERROR_CONNECTION_LOST;
return false;
}

res = dataObj._net._client->read();

Expand Down Expand Up @@ -2918,7 +2932,6 @@ bool FirebaseESP8266::getServerResponse(FirebaseData &dataObj)
p1 = strpos(lineBuf, fstr, 0);
if (p1 != -1)
memset(lineBuf, 0, FIREBASE_RESPONSE_SIZE);

}

//JSON stream data?
Expand Down Expand Up @@ -3248,24 +3261,27 @@ bool FirebaseESP8266::getDownloadResponse(FirebaseData &dataObj)

unsigned long dataTime = millis();

while (dataObj._net._client->connected() && !dataObj._net._client->available() && millis() - dataTime < tmo)
while (clientAvailable(dataObj, false) && millis() - dataTime < tmo)
{
if (!apConnected(dataObj))
return false;
delay(1);
}

dataTime = millis();
if (dataObj._net._client->connected() && dataObj._net._client->available())
if (clientAvailable(dataObj, true))
{

while (dataObj._net._client->available() || count > 0)
while (clientAvailable(dataObj, true) || count > 0)
{
if (dataObj._interruptRequest)
return cancelCurrentResponse(dataObj);

if (!apConnected(dataObj))
if (!reconnect(dataObj))
{
dataObj._httpCode = HTTPC_ERROR_CONNECTION_LOST;
return false;
}

if (!beginPayload)
{
Expand Down Expand Up @@ -3510,7 +3526,7 @@ bool FirebaseESP8266::getUploadResponse(FirebaseData &dataObj)
unsigned long dataTime = millis();

if (!dataObj._isStream)
while (dataObj._net._client->connected() && !dataObj._net._client->available() && millis() - dataTime < tmo)
while (clientAvailable(dataObj, false) && millis() - dataTime < tmo)
{
if (!apConnected(dataObj))
return false;
Expand All @@ -3519,16 +3535,19 @@ bool FirebaseESP8266::getUploadResponse(FirebaseData &dataObj)

dataTime = millis();

if (dataObj._net._client->connected() && dataObj._net._client->available())
if (clientAvailable(dataObj, true))
{

while (dataObj._net._client->available())
while (clientAvailable(dataObj, true))
{
if (dataObj._interruptRequest)
return cancelCurrentResponse(dataObj);

if (!apConnected(dataObj))
if (!reconnect(dataObj))
{
dataObj._httpCode = HTTPC_ERROR_CONNECTION_LOST;
return false;
}

res = dataObj._net._client->read();

Expand Down
15 changes: 5 additions & 10 deletions src/FirebaseESP8266.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
/*
* Google's Firebase Realtime Database Arduino Library for ESP8266, version 2.6.2
* Google's Firebase Realtime Database Arduino Library for ESP8266, version 2.6.3
*
* October 25, 2019
* October 26, 2019
*
* Feature Added:
* - New none recursive FirebaseJson parser and builder.
* - Add support Json Array object and data type.
* - Generic function name for set, push and get.
* - FirebaseJson optimized for flash string usage.
*
* Feature Fixed:
* - Fixed multi-stream data object.
* - Corrupted Firebase rules data.
* - Invalid data type parse from payload with white-spaces.
* - Remove recursive stream operation that may lead to stack overflow
* - Fixed some flash string bugs in ESP8266 core v 2.5.2 that leads to wdt reset.
* - WiFi client unhandle access.
*
*
* This library provides ESP8266 to perform REST API by GET PUT, POST, PATCH, DELETE data from/to with Google's Firebase database using get, set, update
Expand Down Expand Up @@ -2441,6 +2435,7 @@ class FirebaseESP8266
bool getServerResponse(FirebaseData &dataObj);
bool getDownloadResponse(FirebaseData &dataObj);
bool getUploadResponse(FirebaseData &dataObj);
bool clientAvailable(FirebaseData &dataObj, bool available);

void sendHeader(FirebaseData &dataObj, const char *host, uint8_t _method, const char *path, const char *auth, size_t payloadLength);
void resetFirebasedataFlag(FirebaseData &dataObj);
Expand Down
Loading

0 comments on commit b855a61

Please sign in to comment.