diff --git a/fhem/CHANGED b/fhem/CHANGED index 434461ea8..0293316a3 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,6 +1,8 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. - SVN + - change: integrated OWServer/OWDevice nonblocking and random start + time patches (justme1968 & Boris) - feature: Add new module Dashboard - feature: Add new module ONKYO_AVR - feature: SYSSTAT: allow (remote) monitoring via snmp, support diff --git a/fhem/FHEM/10_OWServer.pm b/fhem/FHEM/10_OWServer.pm index fe9b6e82d..7a9868595 100644 --- a/fhem/FHEM/10_OWServer.pm +++ b/fhem/FHEM/10_OWServer.pm @@ -251,6 +251,7 @@ OWServer_Read($@) if(AttrVal($hash->{NAME},"nonblocking",undef) && $init_done) { $hash->{".path"}= $path; pipe(READER,WRITER); + #READER->autoflush(1); WRITER->autoflush(1); my $pid= fork; @@ -259,7 +260,7 @@ OWServer_Read($@) return undef; } - InternalTimer(gettimeofday()+20, "OWServer_TimeoutChild", $pid, 0); + InternalTimer(gettimeofday()+10, "OWServer_TimeoutChild", $pid, 0); if($pid == 0) { close READER; $ret= OWNet::read($hash->{DEF},$path); @@ -277,8 +278,21 @@ OWServer_Read($@) Log3 $hash, 5, "OWServer child ID for reading '$path' is $pid"; close WRITER; - chomp($ret= ); + # http://forum.fhem.de/index.php/topic,16945.0/topicseen.html#msg110673 + my ($rout,$rin, $eout,$ein) = ('','', '',''); + vec($rin, fileno(READER), 1) = 1; + $ein = $rin; + my $nfound = select($rout=$rin, undef, $eout=$ein, 4); + if( $nfound ) { + chomp($ret= ); + RemoveInternalTimer($pid); + } else { + Log3 undef, 1, "OWServer: read timeout for child $pid"; + $hash->{READ_FAILED} = 0 if( !$hash->{READ_FAILED} ); + $hash->{READ_FAILED}++; + } close READER; + } else { $ret= $hash->{fhem}{owserver}->read($path); $ret =~ s/^\s+//g if(defined($ret)); diff --git a/fhem/FHEM/11_OWDevice.pm b/fhem/FHEM/11_OWDevice.pm index d7e37149f..3fef1116a 100644 --- a/fhem/FHEM/11_OWDevice.pm +++ b/fhem/FHEM/11_OWDevice.pm @@ -508,9 +508,10 @@ OWDevice_UpdateValues($) { readingsEndUpdate($hash,1); } RemoveInternalTimer($hash); - InternalTimer(int(gettimeofday())+$hash->{fhem}{interval}, "OWDevice_UpdateValues", $hash, 0) - if(defined($hash->{fhem}{interval})); - + # http://forum.fhem.de/index.php/topic,16945.0/topicseen.html#msg110673 + InternalTimer(int(gettimeofday())+$hash->{fhem}{rand}+$hash->{fhem}{interval}, + "OWDevice_UpdateValues", $hash, 0) if(defined($hash->{fhem}{interval})); + $hash->{fhem}{rand} = 0; } ################################### @@ -653,9 +654,13 @@ OWDevice_Define($$) Log3 $name, 5, "$name: alerting: $alerting"; if( $init_done ) { + $hash->{fhem}{rand} = 0; delete $modules{OWDevice}{NotifyFn}; OWDevice_InitValues($hash); OWDevice_UpdateValues($hash) if(defined($hash->{fhem}{interval})); + } else { + $hash->{fhem}{rand} = int(rand(20)); + Log3 $name, 5, "$name: initial delay: $hash->{fhem}{rand}"; } return undef;