mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
10_SchellenbergHandle.pm: timer improved
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@22715 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
6e2427f9e4
commit
b217504287
@ -73,7 +73,10 @@ sub SchellenbergHandle_Define {
|
|||||||
|
|
||||||
sub SchellenbergHandle_Undef {
|
sub SchellenbergHandle_Undef {
|
||||||
my ($hash, $name) = @_;
|
my ($hash, $name) = @_;
|
||||||
# delete defptr
|
|
||||||
|
# remove watchdog
|
||||||
|
RemoveInternalTimer($hash, \&SchellenbergHandle_Watchdog);
|
||||||
|
# remove defptr
|
||||||
delete $modules{'SchellenbergHandle'}{'defptr'}{$hash->{'ID'}};
|
delete $modules{'SchellenbergHandle'}{'defptr'}{$hash->{'ID'}};
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@ -81,6 +84,10 @@ sub SchellenbergHandle_Undef {
|
|||||||
# modul, all readings and attribute are loaded
|
# modul, all readings and attribute are loaded
|
||||||
sub SchellenbergHandle_Run {
|
sub SchellenbergHandle_Run {
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
|
|
||||||
|
# enable watchdog
|
||||||
|
InternalTimer(Time::HiRes::time() + 86400, \&SchellenbergHandle_Watchdog, $hash);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -90,6 +97,17 @@ sub SchellenbergHandle_Set {
|
|||||||
return "Unknown argument $cmd, choose one of none" if ($cmd eq '?');
|
return "Unknown argument $cmd, choose one of none" if ($cmd eq '?');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sub SchellenbergHandle_Watchdog {
|
||||||
|
my ($hash) = @_;
|
||||||
|
|
||||||
|
readingsBeginUpdate($hash);
|
||||||
|
readingsBulkUpdateIfChanged($hash, 'state', 'dead');
|
||||||
|
readingsBulkUpdateIfChanged($hash, 'alive', 'dead');
|
||||||
|
readingsEndUpdate($hash, 1);
|
||||||
|
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
# not used atm, rolling-code is synchronized after each startup
|
# not used atm, rolling-code is synchronized after each startup
|
||||||
sub SchellenbergHandle_SetPersistentData {
|
sub SchellenbergHandle_SetPersistentData {
|
||||||
my ($hash, $mc, $close) = @_;
|
my ($hash, $mc, $close) = @_;
|
||||||
@ -141,13 +159,6 @@ sub SchellenbergHandle_ProcessMsg {
|
|||||||
return exists($table->{$fncode})?$table->{$fncode}:$fncode;
|
return exists($table->{$fncode})?$table->{$fncode}:$fncode;
|
||||||
};
|
};
|
||||||
|
|
||||||
my sub watchdog {
|
|
||||||
readingsBeginUpdate($hash);
|
|
||||||
readingsBulkUpdateIfChanged($hash, 'state', 'dead');
|
|
||||||
readingsBulkUpdateIfChanged($hash, 'alive', 'dead');
|
|
||||||
readingsEndUpdate($hash, 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
if ($mt eq '1') {
|
if ($mt eq '1') {
|
||||||
# message counter > last known ?
|
# message counter > last known ?
|
||||||
$mc = hex($mc);
|
$mc = hex($mc);
|
||||||
@ -179,7 +190,7 @@ sub SchellenbergHandle_ProcessMsg {
|
|||||||
} elsif ($mt eq '0') {
|
} elsif ($mt eq '0') {
|
||||||
my $f = hex($mc) >> 8;
|
my $f = hex($mc) >> 8;
|
||||||
if ($f == 0x84) {
|
if ($f == 0x84) {
|
||||||
RemoveInternalTimer($hash, \&watchdog);
|
RemoveInternalTimer($hash, \&SchellenbergHandle_Watchdog);
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
my $battery = sprintf('%.1f', (hex($mc) & 0xFF) / 10);
|
my $battery = sprintf('%.1f', (hex($mc) & 0xFF) / 10);
|
||||||
readingsBulkUpdateIfChanged($hash, 'state', 'alive') if ($hash->{'STATE'} eq 'dead');
|
readingsBulkUpdateIfChanged($hash, 'state', 'alive') if ($hash->{'STATE'} eq 'dead');
|
||||||
@ -188,7 +199,7 @@ sub SchellenbergHandle_ProcessMsg {
|
|||||||
readingsBulkUpdateIfChanged($hash, 'alive', 'ok');
|
readingsBulkUpdateIfChanged($hash, 'alive', 'ok');
|
||||||
readingsBulkUpdate($hash, 'rssi', $rssi);
|
readingsBulkUpdate($hash, 'rssi', $rssi);
|
||||||
readingsEndUpdate($hash, 1);
|
readingsEndUpdate($hash, 1);
|
||||||
InternalTimer(Time::HiRes::time() + 86400, \&watchdog, $hash);
|
InternalTimer(Time::HiRes::time() + 86400, \&SchellenbergHandle_Watchdog, $hash);
|
||||||
#InternalTimer(Time::HiRes::time() + 5, \&watchdog, $hash);
|
#InternalTimer(Time::HiRes::time() + 5, \&watchdog, $hash);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user