Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

root.printTo( buff, sizeof(buff)) introduces : at random times #324

Closed
jescarri opened this issue Jul 20, 2016 · 3 comments
Closed

root.printTo( buff, sizeof(buff)) introduces : at random times #324

jescarri opened this issue Jul 20, 2016 · 3 comments
Labels
bug v5 ArduinoJson 5

Comments

@jescarri
Copy link

jescarri commented Jul 20, 2016

It also seems that the float conversion is not working. It changes the values
as you can see the temperature reported is different from what is resulting in the conversion

Hardware: NodeMCU v1.0

Humidity at json conv 44.00
Temp at json conv 27.40
HIC at json conv 27.40
{"node_id":"S1","sensor_list":["DHT","BMP"],"satus":"ok","vcc":2770,"dht_failures":1,"temp":27.3:,"humidity":44.00,"hic":27.40,"pressure":1.00e3}

code:

char *build_json( boolean dht_read_ok, float t, float h, float hic, double pressure, int dht_failures){
  char buff[JBUFF];
  char p_buff[15];
  StaticJsonBuffer<200> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root["node_id"] = "S1";
  JsonArray& data = root.createNestedArray("sensor_list");
  data.add("DHT");
  #if defined (BMPPRESENT)
    data.add("BMP");
  #endif
  if ( dht_read_ok == true ){
    root["satus"] = "ok";
    root["vcc"] = ESP.getVcc();
    root["dht_failures"] = dht_failures;
    root["temp"] = t;
    root["humidity"] = h;
    Serial.print("Humidity at json conv ");
    Serial.println(h);
    Serial.print("Temp at json conv ");
    Serial.println(t);
    Serial.print("HIC at json conv ");
    Serial.println(hic);
    root["hic"] = hic;
    #if defined (BMPPRESENT)
       root["pressure"] = atof(deblank(dtostrf(pressure,11,3,p_buff)));
    #endif
    root.printTo(buff, sizeof(buff));
  }else{
    root["satus"] = "error";
    root["dht_failures"] = dht_failures;
    root.printTo( buff, sizeof(buff));
  }
  return buff;
}

Latest Arduino Json Library

Output:

.......
WiFi connected
IP address: 
192.168.1.39
18:FE:34:CF:7D:0F
SeaLevel Comp pressure 
1004.64
nan
nan
Failed to read from DHT sensor!
44.00
27.40
 Reconecting
Attempting MQTT connection...connected
Humidity at json conv 44.00
Temp at json conv 27.40
HIC at json conv 27.40
{"node_id":"S1","sensor_list":["DHT","BMP"],"satus":"ok","vcc":2770,"dht_failures":1,"temp":27.3:,"humidity":44.00,"hic":27.40,"pressure":1.00e3}
Entering deep sleep mode for 1 secs 

Notice the : at the humidity reading

a good json output:

...........
WiFi connected
IP address: 
192.168.1.39
18:FE:34:CF:7D:0F
SeaLevel Comp pressure 
1004.67
nan
nan
Failed to read from DHT sensor!
44.00
27.50
 Reconecting
Attempting MQTT connection...connected
Humidity at json conv 44.00
Temp at json conv 27.50
HIC at json conv 27.49
{"node_id":"S1","sensor_list":["DHT","BMP"],"satus":"ok","vcc":2770,"dht_failures":1,"temp":27.50,"humidity":44.00,"hic":27.49,"pressure":1.00e3}
Entering deep sleep mode for 1 secs 
@jescarri
Copy link
Author

Parse errors:

795: unexpected token at '{"node_id":"S1","sensor_list":["DHT","BMP"],"satus":"ok","vcc":2769,"dht_failures":1,"temp":27.3:,"humidity":44.40,"hic":27.43,"pressure":1.00e3}'
795: unexpected token at '{"node_id":"S1","sensor_list":["DHT","BMP"],"satus":"ok","vcc":2767,"dht_failures":1,"temp":27.3:,"humidity":44.2:,"hic":27.42,"pressure":1.00e3}'
795: unexpected token at '{"node_id":"S1","sensor_list":["DHT","BMP"],"satus":"ok","vcc":2770,"dht_failures":1,"temp":27.3:,"humidity":44.2:,"hic":27.42,"pressure":1.00e3}'

It looks that is something regarding the float conversion

@bblanchon bblanchon added the bug label Jul 20, 2016
bblanchon added a commit that referenced this issue Jul 20, 2016
bblanchon added a commit that referenced this issue Jul 20, 2016
@bblanchon
Copy link
Owner

This bug is fixed in version 5.6.4.

@jescarri Thank you very much for reporting this issue 👍

@jescarri
Copy link
Author

Thanks for the quick turnaround!!!
Appreciate it!.

Repository owner locked and limited conversation to collaborators Sep 21, 2018
@bblanchon bblanchon added the v5 ArduinoJson 5 label Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug v5 ArduinoJson 5
Projects
None yet
Development

No branches or pull requests

2 participants