Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Issues
  • #288
Closed
Open
Issue created 9 years ago by Administrator@rootContributor
  • New related issue

  • Report abuse to administrator

  • New related issue

  • Report abuse to administrator

Q: How can encoding float data being represented as scientific notation be stopped?

Closed

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?

  1. Oh no!

    You are trying to upload something other than an image. Please upload a .png, .jpg, .jpeg, .gif, .bmp, .tiff or .ico.

    Incoming!

    Drop your designs to start your upload.
Tasks
0

No tasks are currently assigned. Use tasks to break down this issue into smaller parts.

Linked items
0

Link issues together to show that they're related. Learn more.

Activity


Please register or sign in to reply
0 Assignees
None
Assign to
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
Due date
None
None
None
Time tracking
No estimate or time spent
Confidentiality
Not confidential
Not confidential

You are going to turn on confidentiality. Only project members with at least the Reporter role, the author, and assignees can view or be notified about this issue.

Lock issue
Unlocked
1
1 participant
Administrator
Reference: bblanchon/ArduinoJson#288

Menu

Explore Projects Groups Snippets