Q: How can encoding float data being represented as scientific notation be stopped?
Created by: hemalchevli
Background:
I'm using esp8266(with arduino framework on platformIO) and mega2560. Sensors are connected to mega which collects data, and that data is stored in json and sent to esp via UART, eps decodes this json, and encodes a new one, with some added parameters and sends it a webserver.
The following issue is on esp8266.
Input json is:
{"DT":"28-05-2016 05:59:52","Meters":[3190.32,0.00,0.00,0.00,0.00,0.00,0.00,0.00],"BoxOpen":0}
Output json is:
{"DT":"28-05-2016 05:59:52","DeviceID":"Blk2","Meters":[3.19e3,0.00,0.00,0.00,0.00,0.00,0.00,0.00],"BoxOpen":0,"APIKey":"123456"}
The first element of input json array in Meters is 3190.32, which in output is shown as scientific notation, which should be show as is in the input json as my webserver does not understand scientific notation.
Below is the function that does decoding and encoding
String prepareJSON(String jsondata) {
const int BUFFER_SIZE = JSON_OBJECT_SIZE(12);
StaticJsonBuffer<300> jsonBuffer; //for encoding final json to be sent
StaticJsonBuffer<300> jsonBuf; //for decoding counters from mega
String json = "";
char counters[350];
jsondata.toCharArray(counters, 350);// convert to char string from String
//decoding
JsonObject& countTime = jsonBuf.parseObject(counters);
const char* dateTime = countTime["DT"];
int boxopen = countTime["BoxOpen"];
float c0 = countTime["Meters"][0];
float c1 = countTime["Meters"][1];
float c2 = countTime["Meters"][2];
float c3 = countTime["Meters"][3];
float c4 = countTime["Meters"][4];
float c5 = countTime["Meters"][5];
float c6 = countTime["Meters"][6];
float c7 = countTime["Meters"][7];
//encoding
JsonObject& root = jsonBuffer.createObject();
root["DT"] = dateTime;
root["DeviceID"] = DevID;
JsonArray& Meters = root.createNestedArray("Meters");
//Meters.add(double_with_n_digits(c0, 2));
Meters.add(c0,2);
Meters.add(c1,2);
Meters.add(c2,2);
Meters.add(c3,2);
Meters.add(c4,2);
Meters.add(c5,2);
Meters.add(c6,2);
Meters.add(c7,2);
root["BoxOpen"] = boxopen;
root["APIKey"] = Key;
root.printTo(json);
jsondata = "";
return json;
}
Can anyone please help me out here?