changks
September 12, 2016, 4:13pm
1
Dear all,
I’ve browsed some topics related to save 3G data transportation. I found that reduce precision in decimal place may be one of methods. I used “round” to obtain one digit precision for some variables!
Here is the example:
temperature = round(temperature*10)/10;
However, the data strings still show many zeros in decimal place.
{"data":"{ \"1\": \"21.100000\",\"2\": \"-8.700000\",\"3\": \"45.000000\",\"4\": \"22.000000\",\"5\": \"985.000000\",\"6\": \"61.000000\",\"7\": \"0.000000\",\"8\": \"4.018300\",\"k\": \"4IPZ2DSN1X2A9EVO\" }","ttl":"60","published_at":"2016-09-12T15:59:38.745Z","coreid":"3500500009513433234561234","name":"thingSpeakWrite_All"}
Do I miss something here?
Thanks.
@changks , are you using sprintf()
or String commands to create your json string?
changks
September 12, 2016, 4:18pm
3
I use the String command. Here is my code. Any comments? Thanks.
Particle.publish("thingSpeakWrite_All", "{ \"1\": \"" + String(Ta) + "\"," +
"\"2\": \"" + String(Ts) + "\"," +
"\"3\": \"" + String(Rh) + "\"," +
"\"4\": \"" + String(VWC) + "\"," +
"\"5\": \"" + String(Pa) + "\"," +
"\"6\": \"" + String(Lx) + "\"," +
"\"7\": \"" + String(UVindex) + "\"," +
"\"8\": \"" + String(Vol) + "\"," +
"\"k\": \"" + key + "\" }", 60, PRIVATE);
ScruffR
September 12, 2016, 4:26pm
4
I’d always recommend snprintf()
but you could also use String::format()
and in both cases %.1f
would be the format placeholder for one decimal place.
But I guess there might be an overload String(double, 1)
to do the same thing (less elegant tho’).
3 Likes
changks
September 12, 2016, 4:37pm
5
Thanks a lot. It works great.