Error calculating PowerToKwh

Hello, since last update of emoncms i noticed a strange error happening when calculating Kwh consumption of my feeds. At about 00.30 at night for all my feeds there is a big “step” in the total Kwh that i know where is originated. This happens on all of my feeds that calculate Kwh while the instant consumption is fine.
I’ve uploaded some screenshot to show the formulas and the graph with anomalies.

Thank you

Welcome back.

I am not an emonCMS expert, the maths for the calculation is in the file /var/www/emoncms/Modules/process/process_processlist.php (search the file for “public function power_to_kwh($feedid, $time_now, $value)” - is about 70% down the file). This might give some indication of where to look in the data.

My first thought is something is happening to make the $time_elapsed value wrong.

Thanks for your reply, i checked the function you spoke about and i logged to a txt file the values $time_now, $last_time and $time_elapsed… and sometimes these values goes really crazy (the first value is date/time returned from php function “date”):

Usually this is what i see (and this is ok):
real=01/23/2022 07:29:38 pm now=1642962577 last=1642962568 diff=9
real=01/23/2022 07:29:43 pm now=1642962582 last=1642962572 diff=10
real=01/23/2022 07:29:48 pm now=1642962587 last=1642962577 diff=10
real=01/23/2022 07:29:48 pm now=1642962587 last=1642962577 diff=10

but sometimes (i guess when the server load goes up but i’m not sure) this is what happens:
real=01/24/2022 02:09:52 am now=1642980794 last=1642980794 diff=0
real=01/24/2022 02:09:52 am now=1642980784 last=1642980794 diff=-10
real=01/24/2022 02:09:52 am now=1642980913 last=1642980794 diff=119
real=01/24/2022 02:09:58 am now=1642980695 last=1642980794 diff=-99
real=01/24/2022 02:09:58 am now=1642980952 last=1642981012 diff=-60
real=01/24/2022 02:09:58 am now=1642981101 last=1642980794 diff=307
real=01/24/2022 02:10:01 am now=1642980923 last=1642981012 diff=-89
real=01/24/2022 02:10:01 am now=1642980715 last=1642980794 diff=-79
real=01/24/2022 02:10:01 am now=1642980734 last=1642980705 diff=29
real=01/24/2022 02:10:01 am now=1642980715 last=1642980794 diff=-79
real=01/24/2022 02:10:01 am now=1642981012 last=1642980705 diff=307
real=01/24/2022 02:10:01 am now=1642980705 last=1642980794 diff=-89
real=01/24/2022 02:10:03 am now=1642980784 last=1642980715 diff=69
real=01/24/2022 02:10:03 am now=1642980794 last=1642980784 diff=10
real=01/24/2022 02:10:03 am now=1642980823 last=1642980913 diff=-90
real=01/24/2022 02:10:04 am now=1642980794 last=1642980715 diff=79
real=01/24/2022 02:10:04 am now=1642980784 last=1642980952 diff=-168
real=01/24/2022 02:10:04 am now=1642980794 last=1642980952 diff=-158
real=01/24/2022 02:10:04 am now=1642980764 last=1642981012 diff=-248
real=01/24/2022 02:10:04 am now=1642980754 last=1642980715 diff=39
real=01/24/2022 02:10:04 am now=1642980764 last=1642980715 diff=49

so both last_time and time_elapsed seems to be wrong!

Is something changing the time that the emonPi (I presume) is using?

Or could this be the first sign of an SD card failing? (Though why it happens at 00:30 - temperature falling overnight?)

Thanks for your reply, i think i need to explain my setup: actually i’ve a physical server running Ubuntu that receive the data from an emonPi and an emonTx. The feeds that shows anomalies are from the emonPi that is inside the house and the logging i attached was made on the physical server that store data on a phpfina feed on the local hard drive. The last_time and time_elapsed are provided by the emonPI (in that case the failing sd can be an option) or “calculated” from the server?

I don’t know - where does the Pi get its time from? last_time obviously comes from the database file, but how does it get there - it is of course $time_now when the last data was written, but was it a bad value got from somewhere (the Pi’s clock) or was it a good value that has been corrupted in writing and reading back from the SD card? It is hard to believe the Pi’s clock is jumping backwards and forwards, but I don’t discount the silliest suggestions until they’re proven wrong.

Interesting, good work debugging so far! are you using emonhub and the http interfacer to post data to the server? Might be worth looking at the emonhub.log at the same time periods that your seeing the strange negative time deltas in emoncms…

Could requests be queuing and going out of order somehow?

Could there be two emonPi devices posting to the same account?