mobizt / Firebase-Arduino-WiFiNINA

Firebase Arduino Library for ARM/AVR WIFI Dev Boards based on WiFiNINA
MIT License
65 stars 12 forks source link

Pushing array of data to firebase #36

Closed chuanisawesome closed 2 years ago

chuanisawesome commented 2 years ago

Hi, I am trying to push sensor data to firebase from Arduino. I would like to push an array of data to firebase like about 100 sensor data per sec. Right now I am able to push data to firebase perfectly fine with this:

// compute the required size const size_t CAPACITY = JSON_ARRAY_SIZE(100); // allocate the memory for the document StaticJsonDocument doc; // create an empty array JsonArray array = doc.to(); JsonObject obj = doc.as(); // add some values array.add(a); array.add(b); array.add(c); String output; // serialize the array and send the result to Serial serializeJsonPretty(doc, output); if (Firebase.pushArray(fbdo, "/path2demo", output)) { Serial.println("push array ok"); }else{ Serial.println("push array failed"); Serial.println(fbdo.errorReason()); }

But I would like to increase the frequency of data that is being sent over to firebase preferably 10Hz since with the code above Im only getting about 2Hz I am trying to use this:`` String abc = "["1,","2,","3,"]"; if (Firebase.pushArray(fbdo, "/anumber", abc)) { Serial.println("ok"); } but I keep getting an error: expected ',' or ';' before numeric constant

And I am unsure how to move forward. Thank you in advance for the help!

mobizt commented 2 years ago

Your Json array string is not valid.

It should be something like "[1,2,3]" or "[\"1\",\"2\",\"3\"]".

Instead of create array from string literal as above, you should use JSON library and serialize the Array object to string before pass it to the Firebase function.

For the transfer speed, this library works as Firebase RTDB REST API client which use http request/response.

The data to transfer included the header and payload of the request and response then the time used for transfer is depending on the header and payload size which in this case the size of database secret.

In addition, this is the database application which database server may not response as fast as normal cloud server. It takes time for database access.

To send data as fast as possible, you should use other technology and services e.g. MQTT, web socket, TCP/UDP socket.