kpn-iot / thingsml-c-library

C library for ThingsML on your device
https://kpn-iot.github.io/thingsml-c-library/
MIT License
6 stars 4 forks source link

float precision decimal places limited to 4 #21

Closed patvdleer closed 2 years ago

patvdleer commented 2 years ago

In trying to send lat/long I get a max of 4 places.

[{
  "bn":"urn:dev:IMEI:869951000000000:",
  "bt":1.600000000E9,
  "n":"latitude",
  "u":"lat",
  "v":50.0001
},
{
  "n":"longitude",
  "u":"lon",
  "v":5.0001
}]

now I've looked at the code, I'm assuming it's the toJson function,

int SenMLFloatRecord::fieldsToJson() {
    int res = SenMLRecord::fieldsToJson();
    if (this->asSum()) {
        res += printText(F(",\"s\":"), 5);
    } else {
        res += printText(F(",\"v\":"), 5);
    }
    res += printDouble(this->getAdjustedValue(), SENML_MAX_DOUBLE_PRECISION);
    return res;
}

so since the default value is 4 for SENML_MAX_DOUBLE_PRECISION I've tried to set it to 8 but that doesn't seem to fix it

#include <Arduino.h>
#include <WiFi.h>

// set a higher precision than 4 for lat/long
#define SENML_MAX_DOUBLE_PRECISION 8
#include <thingsml_http.h>
josephverburg commented 2 years ago

This has been fixed in v1.3.0 by increasing the precision to 8, thanks for the suggestion.

Please also note: when making changes to libraries in your Arduino folder you will need to flush build caches in /tmp | C:\Users\USER\AppData\Local\Temp (%temp%)