Rounding Error Sending data to Notehub?

Using note.add, I send data to the Notehub. Here is the debug text for the template used and the actual note.add.

{“req”:“note.template”,“file”:“sensor.qos”,“body”:{“temp”:12.1,“battery”:12.1,“CL1”:12.1,“CL2”:12.1,“CL3”:12.1,“CL4”:12.1,“CL5”:12.1,“CL6”:12.1,“CL7”:12.1,“CL8”:12.1,“CL9”:12.1,“timestamp”:18,“version”:“10”}}
{“bytes”:51}

{“req”:“note.add”,“file”:“sensor.qos”,“body”: “temp”:29.2,“battery”:43.5,“timestamp”:7,“CL1”:1130,“CL2”:772,“CL3”:23,“CL4”:4511,“CL5”:4210,“CL6”:65448,“CL7”:4513,“CL8”:4347,“CL9”:4145},“sync”:false,“version”:“1.1.2”}
{“template”:true}

The data in the Notehub is:
{
“CL1”: 1130,
“CL2”: 772,
“CL3”: 23,
“CL4”: 4512,
“CL5”: 4212,
“CL6”: 65440,
“CL7”: 4512,
“CL8”: 4348,
“CL9”: 4144,
“battery”: 43.5,
“temp”: 29.203125,
“timestamp”: 7
}

The values for CL4, CL5, CL6, CL7, CL8 and CL9 in Notehub are different by 1 or 2 (or 8 for CL6) from the values written.

Is this caused by specifying the fields as float in the template, and then rounding errors, or is this a bug of some sort?

Thanks

Hi @Karl_iWell,

The 12.1 data type in a templated Notefile refers to the use of IEEE-754 16-bit, which is very small and low accuracy. As a rule of thumb, the format can represent three digits, but with inaccuracy that is common to Real representation.

It looks by the nature of your data that you are sending integers, not real numbers, and that they are unsigned. As such, if you want 0-65535 accuracy, you might want to consider 22 which is 2-byte Unsigned Int (see all the data type values here).

Hope that helps!

Rob

Thanks Rob,

Makes perfect sense.

Karl