2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-01 01:09:47 +00:00

13_KS300.pm: better error check from Boris (Forum #54236)

git-svn-id: https://svn.fhem.de/fhem/trunk@11620 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2016-06-05 16:29:46 +00:00
parent 9735f035cc
commit 7c22d6c161

View File

@ -157,21 +157,21 @@ KS300_Parse($$)
# The code also handles counter resets after battery replacement # The code also handles counter resets after battery replacement
my $rain_raw_delta = $rain_raw - $rain_raw_prev; my $rain_raw_delta = $rain_raw - $rain_raw_prev;
if($tsecs != $tsecs_prev) { # avoids a rare but relevant condition my $deltatsecs= ($tsecs - $tsecs_prev); # we have observed two datagrams at the same second
my $thours_delta = ($tsecs - $tsecs_prev)/3600.0; # in hours $deltatsecs= 1 if($deltatsecs< 1);
my $rain_raw_per_hour = $rain_raw_delta/$thours_delta; my $thours_delta = ($tsecs - $tsecs_prev)/3600.0; # in hours
if(($rain_raw_delta<0) || ($rain_raw_per_hour> 200.0)) { my $rain_raw_per_hour = $rain_raw_delta/$thours_delta;
$rain_raw_ofs = $rain_raw_ofs_prev-$rain_raw_delta; if(($rain_raw_delta<0) || ($rain_raw_per_hour> 200.0)) {
$rain_raw_ofs = $rain_raw_ofs_prev-$rain_raw_delta;
# If the switch in the tick count occurs simultaneously with an # If the switch in the tick count occurs simultaneously with an
# increase due to rain, the tick is lost. We therefore assume that # increase due to rain, the tick is lost. We therefore assume that
# offsets between -5 and 0 are indeed rain. # offsets between -5 and 0 are indeed rain.
if(($rain_raw_ofs>=-5) && ($rain_raw_ofs<0)) { if(($rain_raw_ofs>=-5) && ($rain_raw_ofs<0)) {
$rain_raw_ofs= 0; $rain_raw_ofs= 0;
} }
readingsBulkUpdate($def, 'rain_raw_ofs', $rain_raw_ofs, 0); readingsBulkUpdate($def, 'rain_raw_ofs', $rain_raw_ofs, 0);
}
} }
$rain_raw_adj = $rain_raw + $rain_raw_ofs; $rain_raw_adj = $rain_raw + $rain_raw_ofs;