Closed arneetsinghkalra closed 4 years ago
You should use float instead of double.
The library does not provide the floating point number resolution settings.
If you want to do so, you can change the number of decimal places in FirebaseESP32.cpp at line number 5022
from
dtostrf(value, 7, 6, buf);
to
dtostrf(value, 7, 3, buf); //if 3 decimal places required
**Don't modify this for double because this will be affected to all many functions and may cause the problems because we use the resolution to identify the float and double values.
I would use floats but I keep getting this error whenever I try putting a float inside a JSON object to be sent to the database: "undefined reference to bool FirebaseJson::set<float>(String const&, float)' sketch/ESP32_Logic_W_Intervals.ino.cpp.o: In function
sendToFirebase(String)':" and undefined reference to `bool FirebaseJson::set
You can update the library which now float was supported for JSON.
I tried that. When I update line 5022, it only updates the decimal points for data that is stored only as a float in the database. Any floats stored inside a JSON object are still around 7 decimal places. Any work around for that?
I have tried that. It's weird, it's still not working.
I can't see anything wrong and nothing behind.
I also test it.
Make sure you edit the right line of code.
Make sure you pass the float variable to the JSON object instead of number to ensure that the compiler will treat that value as float instead of double.
I am getting input data from an HX-711 load sensor. I am pushing data to the Firebase Realtime Database as a json object containing a double of the load sensor, alongside the time and another distance sensor (int data). How do I only push 3 decimal places to the Firebase Database? Thanks!
sorry,how about this float foo = 12.34567; int bar = (int) foo * 1000.0; // bar now = 12345 foo = (float) bar / 1000.0; // foo now = 12.345
I don't get that. What is the problem now?
I see that you push the JSON of Distance, Time and Weight children, then I recommend you to use float variable when you set or add float value to FirebaseJson object.
Example:
FirebaseJson json;
float myWeight = 123.456789f; //or get from load cell sensor
json.add("Weight",myWeight);
Firebase.push(firebaseData, "Path", json);
If you edit the right place in file FirebaseJson.cpp at line number 322, it will limit the number of decimal places for you.
From dtostrf(value, 7, 6, buf); to dtostrf(value, 7, 3, buf);
I am getting input data from an HX-711 load sensor. I am pushing data to the Firebase Realtime Database as a json object containing a double of the load sensor, alongside the time and another distance sensor (int data). How do I only push 3 decimal places to the Firebase Database? Thanks!