2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

58_RPI_1Wire: Improved behaviour when changing pollingInterval

git-svn-id: https://svn.fhem.de/fhem/trunk@25174 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Adimarantis 2021-11-03 13:55:55 +00:00
parent 2a4b628db9
commit 95bcff4dc6
2 changed files with 16 additions and 15 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- bugfix: 58_RPI_1Wire: Improved behaviour when changing pollingInterval
- change: 93_RFHEM: Moved to deprecated (use FHEM2FHEM) - change: 93_RFHEM: Moved to deprecated (use FHEM2FHEM)
- bugfix: 93_DbRep: fix SQL statement if devspec can't be resolved, - bugfix: 93_DbRep: fix SQL statement if devspec can't be resolved,
Forum:#/topic,53584.msg1184155.html#msg1184155 Forum:#/topic,53584.msg1184155.html#msg1184155

View File

@ -12,7 +12,6 @@ use warnings;
#use Data::Dumper; #use Data::Dumper;
use Time::HiRes qw ( gettimeofday tv_interval ); use Time::HiRes qw ( gettimeofday tv_interval );
use Scalar::Util qw(looks_like_number); use Scalar::Util qw(looks_like_number);
#use vars qw{%attr %defs};
eval "use RPi::DHT;1" or my $DHT_missing = "yes"; eval "use RPi::DHT;1" or my $DHT_missing = "yes";
sub RPI_1Wire_Initialize { sub RPI_1Wire_Initialize {
@ -56,18 +55,20 @@ my %RPI_1Wire_Devices =
); );
sub RPI_1Wire_Notify { sub RPI_1Wire_Notify {
my ($own_hash, $dev_hash) = @_; my ($hash, $dev_hash) = @_;
my $ownName = $own_hash->{NAME}; # own name / hash my $ownName = $hash->{NAME}; # own name / hash
return "" if(IsDisabled($ownName)); # Return without any further action if the module is disabled return "" if(IsDisabled($ownName)); # Return without any further action if the module is disabled
my $devName = $dev_hash->{NAME}; # Device that created the events my $devName = $dev_hash->{NAME}; # Device that created the events
# Log3 $ownName, 1, $ownName." Notify from $devName";
my $events = deviceEvents($dev_hash,1); my $events = deviceEvents($dev_hash,1);
if ($devName eq "global" and grep(m/^INITIALIZED|REREADCFG$/, @{$events})) { if ($devName eq "global" and grep(m/^INITIALIZED|REREADCFG$/, @{$events})) {
my $def=$own_hash->{DEF}; my $def=$hash->{DEF};
$def="" if (!defined $def); $def="" if (!defined $def);
#GetDevices is triggering the autocreate calls, but this is not yet working (autocreate not ready?) so delay this by 10 seconds #GetDevices is triggering the autocreate calls, but this is not yet working (autocreate not ready?) so delay this by 10 seconds
RPI_1Wire_Init($own_hash,$def,0); RPI_1Wire_Init($hash,$def,0);
InternalTimer(gettimeofday()+10, "RPI_1Wire_GetDevices", $own_hash, 0) if $own_hash->{DEF} =~ /BUSMASTER/; InternalTimer(gettimeofday()+10, "RPI_1Wire_GetDevices", $hash, 0) if $hash->{DEF} =~ /BUSMASTER/;
} elsif ($devName eq "global" and grep(/^(DELETEATTR|ATTR).$ownName.pollingInterval/, @{$events})) {
#Restart timer with new pollingInterval
RPI_1Wire_DeviceUpdate($hash);
} }
} }
@ -147,11 +148,11 @@ sub RPI_1Wire_Init { #
} else { } else {
if (!(-w "$w1_path/$arg/conv_time")) { if (!(-w "$w1_path/$arg/conv_time")) {
delete($hash->{setList}{conv_time}); delete($hash->{setList}{conv_time});
$hash->{helper}{write}.="conv_time "; $hash->{helper}{write}.="conv_time " if (-e "$w1_path/$arg/conv_time");
} }
if (!(-w "$w1_path/$arg/resolution")) { if (!(-w "$w1_path/$arg/resolution")) {
delete($hash->{setList}{precision}); delete($hash->{setList}{precision});
$hash->{helper}{write}.="resolution "; $hash->{helper}{write}.="resolution " if (-e "$w1_path/$arg/resolution") ;
} }
} }
#remove set commands that make no sense #remove set commands that make no sense
@ -222,7 +223,6 @@ sub RPI_1Wire_DeviceUpdate {
return RPI_1Wire_Init($hash,$hash->{DEF},0); return RPI_1Wire_Init($hash,$hash->{DEF},0);
} }
my $pollingInterval = AttrVal($name,"pollingInterval",60); my $pollingInterval = AttrVal($name,"pollingInterval",60);
return if $pollingInterval<1;
Log3 $name, 4 , $name.": DeviceUpdate($hash->{NAME}), pollingInterval:$pollingInterval"; Log3 $name, 4 , $name.": DeviceUpdate($hash->{NAME}), pollingInterval:$pollingInterval";
my $mode=AttrVal($name,"mode","nonblocking"); my $mode=AttrVal($name,"mode","nonblocking");
@ -246,14 +246,14 @@ sub RPI_1Wire_DeviceUpdate {
#RPI_1Wire_FinishFn($ret); First result can be ignored #RPI_1Wire_FinishFn($ret); First result can be ignored
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
#Table of reasonable conv_times? #Table of reasonable conv_times?
InternalTimer(gettimeofday()+1.5, "RPI_1Wire_FromTimer", $hash, 0); InternalTimer(gettimeofday()+1.5, "RPI_1Wire_FromTimer", $hash, 0) if $pollingInterval>0;
return; return;
} elsif ($mode eq "bulk_read") { } elsif ($mode eq "bulk_read") {
$hash->{helper}{RUNNING_PID} = BlockingCall("RPI_1Wire_TriggerBulk", $hash,undef); $hash->{helper}{RUNNING_PID} = BlockingCall("RPI_1Wire_TriggerBulk", $hash,undef);
Log3 $hash->{NAME}, 3, $hash->{NAME}.": Triggered bulk read"; Log3 $hash->{NAME}, 3, $hash->{NAME}.": Triggered bulk read";
} }
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
InternalTimer(gettimeofday()+$pollingInterval, "RPI_1Wire_DeviceUpdate", $hash, 0); InternalTimer(gettimeofday()+$pollingInterval, "RPI_1Wire_DeviceUpdate", $hash, 0) if $pollingInterval>0;
return; return;
} }
@ -274,7 +274,7 @@ sub RPI_1Wire_FromTimer {
RPI_1Wire_FinishFn($ret); RPI_1Wire_FinishFn($ret);
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
my $pollingInterval = AttrVal($name,"pollingInterval",60); my $pollingInterval = AttrVal($name,"pollingInterval",60);
InternalTimer(gettimeofday()+$pollingInterval, "RPI_1Wire_DeviceUpdate", $hash, 0); InternalTimer(gettimeofday()+$pollingInterval, "RPI_1Wire_DeviceUpdate", $hash, 0) if $pollingInterval>0;
} }
sub RPI_1Wire_SetPrecision { sub RPI_1Wire_SetPrecision {
@ -617,8 +617,7 @@ sub RPI_1Wire_Attr { #
if (!looks_like_number($val) || $val < 0) { if (!looks_like_number($val) || $val < 0) {
return "pollingInterval has to be a positive number or zero"; return "pollingInterval has to be a positive number or zero";
} }
#Restart Timer #RPI_1Wire_DeviceUpdate($hash); moved to NOTIFY, after the change has been done
RPI_1Wire_DeviceUpdate($hash);
} elsif ($attr eq "mode") { } elsif ($attr eq "mode") {
if ($val ne "blocking" && $val ne "nonblocking" && $val ne "timer") { if ($val ne "blocking" && $val ne "nonblocking" && $val ne "timer") {
return "Unknown mode $val"; return "Unknown mode $val";
@ -749,6 +748,7 @@ For German documentation see <a href="https://wiki.fhem.de/wiki/RPI_1Wire">Wiki<
<li><b>pollingInterval</b><br> <li><b>pollingInterval</b><br>
<a id="RPI_1Wire-attr-pollingInterval"></a> <a id="RPI_1Wire-attr-pollingInterval"></a>
Defines how often the device is updated in seconds.<br> Defines how often the device is updated in seconds.<br>
Setting the pollingInterval to 0 disables the automatic updates.<br>
Default: 60, valid values: integers<br> Default: 60, valid values: integers<br>
</li> </li>
<li><b>tempOffset</b><br> <li><b>tempOffset</b><br>