Closed sarkrui closed 5 years ago
You need to print (v5) or serialize (v6) ArduinoJson object (classs) as Arduino string object or C or C++ string. And pass that string to Firebase function.
Thanks @mobizt ! It works!
//generated by arduinojson.org/v6/assistant/
const size_t capacity = JSON_OBJECT_SIZE(3);
DynamicJsonDocument objectData(capacity);
objectData["dBValue"] = 45.0;
objectData["time"] = "2019-05-15T15:00:25";
objectData["buttonState"] = 0;
String logData;
serializeJson(objectData, logData);
Firebase.pushJSON(firebaseData, data_log + device_id, logData);
I did manage to pass int
float
variables into a JSONObject, however, only ints and floats were synchronized, why is that?
//generated by arduinojson.org/v6/assistant/
const size_t capacity = JSON_OBJECT_SIZE(3);
DynamicJsonDocument objectData(capacity);
objectData["dBValue"] = dBValue; //global variable, float
objectData["buttonState"] = buttonState; //global variable, int
objectData["time"] = formattedDate; //global variable String
String logData;
serializeJson(objectData, logData);
Firebase.pushJSON(firebaseData, data_log + device_id, logData);
What do you mean synchronized?
Print or serialize your created ArduinoJson object to string and check it on serial print, if something wrong with ArduinoJson please open issue at ArduinoJson Github.
Thanks @mobizt ! I switched to ArduinoJSONV5 and problem solved.
not synchronized
, I meant only int
and float
were passed, whereas String
wasn't.
void baselinePushV5() {
const size_t capacity = JSON_OBJECT_SIZE(3);
DynamicJsonBuffer jsonBuffer(capacity);
JsonObject& root = jsonBuffer.createObject();
root["dBValue"] = 56;
root["buttonState"] = 2;
root["timeStamp"] = formattedDate;
root.printTo(serialjson);
Serial.println(serialjson);
delay(1000);
}
{"dBValue":56,"buttonState":2,"timeStamp":"2019-05-21T12:10:53"}
Failed to pass String (variable) to JSONObject https://github.com/bblanchon/ArduinoJson/issues/1002
Thanks @mobizt ! I switched to ArduinoJSONV5 and problem solved.
not synchronized
, I meant onlyint
andfloat
were passed, whereasString
wasn't.void baselinePushV5() { const size_t capacity = JSON_OBJECT_SIZE(3); DynamicJsonBuffer jsonBuffer(capacity); JsonObject& root = jsonBuffer.createObject(); root["dBValue"] = 56; root["buttonState"] = 2; root["timeStamp"] = formattedDate; root.printTo(serialjson); Serial.println(serialjson); delay(1000); }
Serial Outputs
{"dBValue":56,"buttonState":2,"timeStamp":"2019-05-21T12:10:53"}
Failed to pass String (variable) to JSONObject bblanchon/ArduinoJson#1002
How did you pass the root data into Firebase.pushJSON? I did the same thing but still can't pass those data.
You can't use ArduinoJson with this library to handle JSON.
The library has built-in JSON parser and builder called FirebaseJson and you should use it instead.
See the example for the usages.
@Proxcentaur Check this out, usage of FirebaseJSON.
Thank you so much, I have read this.
Best regards, Septia Dini R Instrumentation Technology Department of Electrical and Informatics Engineering Universitas Gadjah Mada
Pada tanggal Kam, 14 Mei 2020 pukul 00.37 mobizt notifications@github.com menulis:
@Proxcentaur https://github.com/Proxcentaur Did you read this https://github.com/mobizt/Firebase-ESP8266/issues/2#issuecomment-628094708 ?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mobizt/Firebase-ESP32/issues/23#issuecomment-628140347, or unsubscribe https://github.com/notifications/unsubscribe-auth/AILRL6D54DSG5KRQRV6JT2DRRLLEZANCNFSM4HOGA6VQ .
name: Help and how to firebase.pushJSON with non-hardcoded JSON data?
const int BUFFER_SIZE = JSON_OBJECT_SIZE(3);
StaticJsonBuffer<BUFFER_SIZE> jsonBuffer;
JsonObject& logData = jsonBuffer.createObject();
logData["dBValue"] = 45.0;
logData["time"] = "2019-05-15T15:00:25";
logData["buttonState"] = 0;
Firebase.pushJSON(firebaseData, data_log + device_id, logData);
With the above codes, I had such an error.
I have tried using ArduinoJSON v5/v6, but JSONObject isn't supported by firebase.pushJSON. I wonder how other dudes include variables in the jsonData. From the example, the data is hardcoded though.
String jsonData = "{\"parent_001\":\"parent 001 text\", \"parent 002\":{\"child_of_002\":123.456}}";