From 9e25a78327f9eca0e9ada3e3a4a2820b1b3984c3 Mon Sep 17 00:00:00 2001
From: markusbloch <>
Date: Wed, 11 Apr 2018 21:23:36 +0000
Subject: [PATCH] FB_CALLMONITOR: new attribute "sendKeepAlives" to send cyclic
keep-alive data (Forum: #86590)
git-svn-id: https://svn.fhem.de/fhem/trunk@16591 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/CHANGED | 3 ++
fhem/FHEM/72_FB_CALLMONITOR.pm | 72 ++++++++++++++++++++++++++++++----
2 files changed, 67 insertions(+), 8 deletions(-)
diff --git a/fhem/CHANGED b/fhem/CHANGED
index 34c26b4bf..92f7711bd 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,5 +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.
+ - feature: 72_FB_CALLMONITOR: new attribute "sendKeepAlive" to send cyclic
+ keep-alives when connected FritzBox for example
+ is located behind another NAT router
- bugfix: 72_FB_CALLMONITOR: fix log message on every reverse search:
"unknown reverse search method ,"
- bugfix: 93_DbLog: V3.10.4, fix addLog if no valueFn is used
diff --git a/fhem/FHEM/72_FB_CALLMONITOR.pm b/fhem/FHEM/72_FB_CALLMONITOR.pm
index b794626a9..74474b5d9 100755
--- a/fhem/FHEM/72_FB_CALLMONITOR.pm
+++ b/fhem/FHEM/72_FB_CALLMONITOR.pm
@@ -75,6 +75,7 @@ FB_CALLMONITOR_Initialize($)
"fritzbox-remote-timeout ".
"fritzbox-user ".
"apiKeySearchCh ".
+ "sendKeepAlives:none,5m,10m,15m,30m,1h ".
$readingFnAttributes;
}
@@ -113,7 +114,8 @@ sub
FB_CALLMONITOR_Undef($$)
{
my ($hash, $arg) = @_;
-
+
+ RemoveInternalTimer($hash, "FB_CALLMONITOR_sendKeepAlive");
DevIo_CloseDev($hash);
return undef;
@@ -606,22 +608,27 @@ FB_CALLMONITOR_Attr($@)
{
DevIo_OpenDev($hash, 0, undef, \&FB_CALLMONITOR_DevIoCallback);
}
+
+ if($attrib eq "sendKeepAlives" and $value !~ /^none|(?:5|10|15|30)m|1h$/)
+ {
+ return "invalid value $value for $attrib. Allowed values are: none,5m,10m,15m,30m,1h";
+ }
}
elsif($cmd eq "del")
{
if($attrib eq "reverse-search" or $attrib eq "reverse-search-phonebook-file")
{
- delete($hash->{helper}{PHONEBOOK}) if(defined($hash->{helper}{PHONEBOOK}));
+ delete($hash->{helper}{PHONEBOOK});
}
if($attrib eq "reverse-search-cache")
{
- delete($hash->{helper}{CACHE}) if(defined($hash->{helper}{CACHE}));
+ delete($hash->{helper}{CACHE});
}
if($attrib eq "reverse-search-text-file")
{
- delete($hash->{helper}{TEXTFILE}) if(defined($hash->{helper}{TEXTFILE}));
+ delete($hash->{helper}{TEXTFILE});
}
if($attrib eq "disable")
@@ -639,15 +646,19 @@ FB_CALLMONITOR_Attr($@)
sub
FB_CALLMONITOR_Notify($$)
{
- my ($hash,$device) = @_;
-
+ my ($hash, $device) = @_;
+ my $name = $hash->{NAME};
+
my $events = deviceEvents($device, undef);
return if($device->{NAME} ne "global");
+
+ FB_CALLMONITOR_sendKeepAlive($hash) if(grep(m/(?:DELETE)?ATTR $name sendKeepAlives/, @{$events}));
+
return if(!grep(m/^INITIALIZED|REREADCFG$/, @{$events}));
FB_CALLMONITOR_readPhonebook($hash);
-
+
return undef;
}
@@ -2082,6 +2093,43 @@ sub FB_CALLMONITOR_checkNumberForDeflection($$)
Log3 $name, 4, "FB_CALLMONITOR ($name) - found matching deflection. call will be ignored" if($ret);
return $ret;
}
+
+sub FB_CALLMONITOR_sendKeepAlive($)
+{
+ my ($hash) = @_;
+ my $name = $hash->{NAME};
+ my $sendKeepAlives = AttrVal($name, "sendKeepAlives", "none");
+ my $values = {
+ "5m" => 300,
+ "10m" => 600,
+ "15m" => 900,
+ "30m" => 1800,
+ "1h" => 3600
+ };
+
+ if($sendKeepAlives ne "none" and DevIo_IsOpen($hash))
+ {
+ Log3 $name, 5, "FB_CALLMONITOR ($name) - sending keep-alive";
+ DevIo_SimpleWrite($hash, "\n", 2);
+
+ if($values->{$sendKeepAlives})
+ {
+ InternalTimer(gettimeofday()+$values->{$sendKeepAlives}, "FB_CALLMONITOR_sendKeepAlive", $hash);
+ }
+ else
+ {
+ Log3 $name, 3, "FB_CALLMONITOR ($name) - unsupported value for attribute sendKeepAlives: $sendKeepAlives. discard sending keep-alive";
+ }
+ }
+ else
+ {
+ RemoveInternalTimer($hash, "FB_CALLMONITOR_sendKeepAlive");
+ }
+
+ return undef;
+}
+
+
1;
=pod
@@ -2223,7 +2271,11 @@ sub FB_CALLMONITOR_checkNumberForDeflection($$)
Use the given user for remote connect to obtain the phonebook (see fritzbox-remote-phonebook). This attribute is only needed, if you use multiple users on your FritzBox.