FirebaseExtended / firebase-arduino

Arduino samples for Firebase.
Apache License 2.0
943 stars 494 forks source link

Firebase.stream() cannot retrieved Big JSON file #430

Open jeszam2008 opened 5 years ago

jeszam2008 commented 5 years ago

Sorry for my bad English.

I have a problem.

Everytime I want to retrieve the object called "COINBOX_TRANSACTION_LOGS", it returns empty or "{}" output. Here's the picture below.

02

But when I delete some number of the child, it prints-out my expected output. Here's the picture below

03

Is there a limitation of retrieving data if the nth child of that parent object is beyond 5 (that's why I've observed)? Or I don't know...

I wish someone would help me for this problem.

Here's my code below:

int currentIndex = 0; void setup() { // some codes.... Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); }

void loop() { currentIndex = (currentIndex == 6) ? 0 : currentIndex; setFirebaseStream(); }

void setFirebaseStream() { String pathURL = currentIndex == 0 ? "/COIN" : ""; pathURL = currentIndex == 1 ? "/BILL" : pathURL; pathURL = currentIndex == 2 ? "/ADMIN" : pathURL; pathURL = currentIndex == 3 ? "/COINBOX_TRANSACTION_LOGS" : pathURL; pathURL = currentIndex == 4 ? "/PESO" : pathURL; pathURL = currentIndex == 5 ? "/SERVICE_CHARGE" : pathURL;

StaticJsonBuffer<1000> jsonBuffer; const char* json = getFirebaseJSONObject(pathURL);

if (!(json && !json[0])) { Serial.println(pathURL); JsonObject& root = jsonBuffer.parseObject(json); root.prettyPrintTo(Serial); // prints the object size int objectSize = root.size(); Serial.print("\nObject Size: "); Serial.println(objectSize); } }

char getFirebaseJSONObject(String thisURL) { String json = ""; const char pathURL = convertToCharPointer(thisURL); Firebase.stream(pathURL);

if (Firebase.available()) { FirebaseObject firebaseObject = Firebase.readEvent(); JsonVariant jsonVariant = firebaseObject.getJsonVariant("data"); JsonObject& object = jsonVariant.asObject(); object.prettyPrintTo(json); currentIndex++; }

char* jsonFormat = convertToCharPointer(json); return jsonFormat; }

char convertToCharPointer(String thisString) { int stringLength = thisString.length() + 1; char thisValue = new char[stringLength]; thisString.toCharArray(thisValue, stringLength); return thisValue; }