Problems with floating point values.

Hi,

 

I am trying to log data to emoncms from my water meter using a pulse input.  I am running standard emonbase with no modifcations on a NanodeRF.  I'm running emontx on a Nanode  that has been modified for pulse counting.  One of my values is a floating point value, the other is a integer.  However when I receive the floating point on the emonbase it comes out as two separate values.  See below.

Data sent: /api/post.json?apikey=alkahjsdfkhadsfkjhasdlkjasdlkjhdsaflhjk&node=1&csv=31754,16902,2
 

 

Likewise on emoncms I get 3 values instead of 2.  This is what my struct looks like on the emontx.

 

typedef struct { float flowrate; int pulse;} PayloadTX;

 

Does anyone have any ideas why the floating point values is being interpreted in this manner?

 

 

mharizanov's picture

Re: Problems with floating point values.

The CSV method expects only int values, typically a float is converted to an int for transmission purposes by multiplying by 100 and then divided by 100 (by multiplying by 0.01) back at the receiving end. 

 

Exmple with temperatures

1) reading 21.34 degrees C

2) multiplied by 100 = 2134 int value

3) emoncms processing rule 2134*0.01 = 21.34

 

That of course may lose some precision in the flowt, depending on your needs

ieris's picture

Re: Problems with floating point values.

Hello,

  having different story about floating point values ...  this time about MySQL data type float (http://dev.mysql.com/doc/refman/5.5/en/problems-with-float.html)

Reading gas counter and sending readings as integers that's ok. Running on RFM12PI.

After receiving it and multiplying by 0.01 to get exact value performing accumulator function to keep gas counter exact value. And at this point problem comes up. When values are small they are stored ok in database (like, temp - 21.34, gas reading 0.03, etc.), but when values are big they are stored rounded in database.

Example: having gas counter at 19464,63 - in database feeds and feed_x table it is stored as 19464,6. After getting reading by example 0.03 it remains the same, because after adding reading to value and MySQL internal rounding it is again 19464.6.

Changed data type for involved columns to decimal(10,2) solved that problem for me. But this is only temporary solution. :(

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.