spectraphilic / wasp_sketches

Waspmote sketches develoded by our group
1 stars 0 forks source link

SDI-12 losing precision #9

Open jdavid opened 6 years ago

jdavid commented 6 years ago

Example, a 0.06 becomes 0.0599

947033174.016 DEBUG sdi-12 sendCommand(1D0!): '1+0.06+207+23.3-0.06-0.03+0.09'
Sensor 208 (DS-2): 0.0599
johnhulth commented 5 years ago

Looks like this applies to BME, etc.. as well.

jdavid commented 5 years ago

This has been fixed for SDI-12 devices. The solution is to avoid floats in the mote, we have to use fixed precision numbers, defining the number of decimals we want to keep.

For example if we want to keep 1 decimal, we multiply by ten in the mote, send an integer to the Pi/Server, and then divide by 10 in the Pi/Server. For example the number 23.3 become 233 in the mote.

So we've to decide how many decimals we want to keep for every field. I've created a documentation for that purpose, see https://github.com/spectraphilic/wasp_sketches/blob/master/docs/sensors.md

Please review that documentation and fix-it/tell-me if there're mistakes. Before the new version of the sketch is deployed.

For SDI-12 sensors the error was obvious, because there was a difference between the string read from the sensor, e.g. from the 1+0.06+207+23.3-0.06-0.03+0.09 we get the value 0.0599.

But for I2C sensors I don't see how you have found any error, could you explain?

In I2C sensors there's also a conversion from integer to float, where errors may be introduced, but this conversion is internal to the libraries we use, so they're not obvious to see. And also much harder to fix.