Hi everybody,
not receiving answers, I tried to do tests independently.
-
I tried to post-process one of the feeds that had gone to zero, creating a new feed: the script really does a good job and the data are fixed
-
I tried to replace the reset feed with the newly created feed:
– I stopped apache service
– I did redis FLUSHALL command
– I replaced the damaged phpfina/feed id.dat file with the new one
– I restarted apache
I verify the data before new registrations: the modified feed is correct, either by displaying as a graphic or as a CSV output, but in the feed list, as a last value, NULL appears.
Upon arrival of new input data, the feed in question returns to zero.
Turning the Raspberry off and on again, magically, the feed returns all fixed by itself.
I’m a programmer, but I’m not expert in PHP, even less in SQL/redis, I tried to take a look at the code, in the script emoncms/Modules/process/process_processlist.php - function power_to_kwh():
if it is not possible to retrieve the last data point of the feed, it assumes the last value is zero.
// Get last value
$last = $this->feed->get_timevalue($feedid);
if (!isset($last['value'])) $last['value'] = 0;
this value, if more than two hours have elapsed or the time interval is not valid (flush redis), is written in the feed, causing the reset:
//in the event that redis is flushed the last time will
//likely be> 7200s ago and so kwh inc is not calculated
//rather than enter 0 we enter the last value
$new_kwh = $last_kwh;
In the script emoncms/Modules/feed/feed_model.php - function get_timevalue():
the code to read the last feed data point, in case redis is used:
if ($this->redis)
{
if ($this->redis->hExists("feed: $id",'time')) {
$lastvalue = $this->redis->hmget("feed: $id", array('time', 'value'));
if (!isset ($lastvalue ['time']) || !is_numeric ($lastvalue['time']) || is_nan($lastvalue ['time'])) {
$lastvalue['time'] = null;
} else {
$lastvalue['time'] = (int) $lastvalue['time'];
}
if (!isset ($lastvalue['value']) || !is_numeric($lastvalue['value']) || is_nan ($lastvalue['value'])) {
$lastvalue['value'] = null;
} else {
$lastvalue['value'] = (float) $lastvalue['value'];
}
//CHAVEIRO comment: Can return NULL as a valid number or else the processlist logic will be broken
} else {
//if it does not, load it in to redis from the actual feed data
$lastvalue = $this->EngineClass($engine)->lastvalue($id);
$this->redis->hMset("feed: $id", array('time' => $lastvalue['time'], 'value' => $lastvalue['value']));
}
Here I imagine that redis->hmget() returns an invalid value and then $lastvalue[‘value’] = null, my question as ignorant is: instead of returning a null value, it would not be possible to try to make some attempts to read a point even slightly earlier, this could save the feed from reset, which, in the case of the power to kwh process, is a deleterious effect
sorry for my bad english
thank you all
Sergio