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

values need float precision to reduce fraction overhead #26

Open MichielfromNL opened 2 months ago

MichielfromNL commented 2 months ago

An example record:

2133 ms: Sending 44 bytes: [{"i":-24,"v":22.60000038},{"i":5,"v":76}]

Note the 8 digit fraction for the temperature value. This is because toJson converts float records with SENML_MAX_DOUBLE_PRECISION . Which is 8 by default , and can be set as a compile time option. However That sets the precision for all float / double records.

With lora transmisison, every byte counts. So it would be a good practice to be able to set the precision for each specific float or double.

Hence this feature suggestion:
Add precision to the float / double record constructors with default SENML_MAX_DOUBLE_PRECISION

define MYPRECISION 2

SenMLFloatRecord temprec(THINGSML_TEMPERATURE, MYPRECISION);

I will try to make a branch