Rounding on large incrementing counter values

I have a counter that increment with each litre of water drawn through the meter. I am pushing the value of the counter using the JSON upload. The value of the counter is 352942600. This comes into emoncms as 352943000.

Subsequent operations to convert this to pulses then doesn't give correct results.

This post seems to describe the same issue

http://openenergymonitor.org/emon/node/5119

Any way to solve this? I don't particularly want to reset the counters.

Thanks.

CapnBry's picture

Re: Rounding on large incrementing counter values

Hi a234525, what storage engine are you using for your feed storage? If it is mysql then you'd need to convert your feed_XX table (where XX is the feed number) to use double precision as the value type. However, if you're using a more modern feed engine such as phpfina or phpfiwa then the feeds table itself might be the issue. The feeds themselves with these modern engines still store the values in single floats, however all the operations on the "last value" can still take place in double precision if the changes we're talking about in the kwh/day feed thread are made.

Note that 352942600 is 352942592 in single precision float so you'd think it would work, but mysql has their own rounding rules apparently so when running a local test to insert "352942600" into a float column guess what I get? 352943000!

It sounds to me like you might also benefit from the changes being discussed in that thread, as 352942600 inserted into a double precision feeds table still comes out as 352942600. In fact, it retains precision until over 3529426000000000 liters, at which point I am afraid you will have to reset your counter. However, I am not sure if your great great great great great great grandchildren will remember how to reset the counter after 3.5 quintillion liters of water use.

a234525's picture

Re: Rounding on large incrementing counter values

Hi CapnBry, thank you for the reply. I am using PHPFIWA and PHPTIMESERIES feeds.

 

I am using version 9.3 | 2015.12.30 on a Pi using local emoncms receiving data from 2 emonTXes, and soon my gas and water meters via JSON upload. I know I'm wearing out my SD card, but I use the backup script to copy to another SD card nightly.

 

I will want to convert the incrementing counters into "usage now" and "daily usage" feeds.

 

I just started reading about Redis in that other thread. I don't have it installed.

 

Can I alter the feeds I am using? How do I do that? Or will Redis help?

 

Thanks,

Al

 

Eric_AMANN's picture

Re: Rounding on large incrementing counter values

Hi.

This may help.

Eric

a234525's picture

Re: Rounding on large incrementing counter values

Thank you Eric. I think you are using mySQL. How do I change the data type on the PHPFIWA feeds?

 

thanks,

Al

Eric_AMANN's picture

Re: Rounding on large incrementing counter values

Hi,

No, I'm only using PHPIWA and PHPFINA feeds.

For all feeds (FIWA,FINA, PHPTIMESERIES, ...), the value of the input is first stored in the MySQL database. In my case, the value were rounded by MySQL at this stage. To solve this problem, I modified the type of the column "value" of the table input from FLOAT to DECIMAL.

Eric

 

 

pb66's picture

Re: Rounding on large incrementing counter values

There are at least 2 separate issues at play here, the calculations and the storage. "emoncms 9.2 - power to kwh feed stopped incrementing" discusses the calculations including keeping a running tally.

The php feed engines are all set to use a 4 byte float so as explained by the comments from CaptBry and the link from Eric there is a problem with storing values over a certain size. Using a double in the "feed" table will at least allow the value to increment but the persisted value will not increase until the next step of "the float" is reached.

The datatype should be changed in the "feed" table by editing /var/www/emoncms/Modules/feed/feed_schema.php from " 'value' => array('type' => 'float') " to " 'value' => array('type' => 'double') " and then use update databases in the admin menu.

The immediate solution to the storage could be to split the accumulating total into "fine" and "coarse" feeds so that that each roll over of the "fine" is recorded in the "coarse" feed, this is far from ideal and gives a good case for having other options for the php feeds eg double, as long as the "4" isn't hardcoded into emoncms's code and the meta file denotes double then hopefully it should be a case of just adding a "double" option ("float by default") to each engine so that they can be created as 8byte or 4byte versions.

Paul

a234525's picture

Re: Rounding on large incrementing counter values

For now I've just modified my JSON upload to send the 1st 6 digits from the right hand side. So I get 942600 which stores correctly. I hope this will be fixed in future release so I can upload the full number.

 

I am now trying to get "instantaneous" usage, and also a "daily" usage feed. This is water, and I also have a similar Gas counter feed to upload, so it seems wasteful to use th PHPFINA or PHPFIWA feeds which sample every 10s.

 

I am trying the following time series feeds on the input.

Log to Feed

Total Pulse Count to Pulse Increment

Log to Feed (this seems correct and gives me the number of pulses since the last time the counter value was sent)

Power to kWh

Power to kWh/d

 

I don't seem to get the correct numbers? Each pulse represents one litre, and I would like to get a Litres/minute instantaneous feed, and also a litres per day daily feed.

 

Any suggestions appreciated.

 

Thanks

 

I have 

pb66's picture

Re: Rounding on large incrementing counter values

Try adjusting the values put into the "power to" processes after establishing the increase since last update e.g.

Log to Feed (this seems correct and gives me the number of pulses since the last time the counter value was sent)

x 1000                    // to offset the "to kilo"  part of both the "power to" processes

Power to kWh/d    // Log the daily first as that reporting period is already correct

x 60                        // to adjust the "per hour" to "per minute" for the "power to kWh" process

Power to kWh       // Should now log litres per minute

Paul

 

a234525's picture

Re: Rounding on large incrementing counter values

Thank you Paul.

 

I can now get the daily total by using a wH accumulator after converting to pulses. Power to kWh/d gave incorrect values.

 

I would now like to get the instantaneous value. I have tried the following

Conversion to Pulse (Last value = 6)

x 60000

Power to kWh

The Power to kWh gives me incrementing values starting at 0 then 3.2 then incrementing from there)

In this example I am uploading values which give me 6 pulses roughly (but not exactly) every 30 seconds.

How do I convert pulses into "watts"?

 

a234525's picture

Re: Rounding on large incrementing counter values

Anyone any ideas?

Eric_AMANN's picture

Re: Rounding on large incrementing counter values

Hi,

Try this process list :

   1.Wh Accumulator

   2. kWh to Power

Eric

 

Comment viewing options

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