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.

  • apiKeySearchCh <API-Key>
  • A private API key from tel.search.ch to perform a reverse search via search.ch (see attribute reverse-search). Without an API key, no reverse search via search.ch is not possible

    - +
  • sendKeepAlives (none,5m,10m,15m,30m,1h)
  • + If activated, FB_CALLMONITOR sends a keep-alive on a regularly basis depending on the configured value. This ensures a working connection when the connected FritzBox is operating behind another NAT-based router (e.g. another FritzBox) so the connection will not be detected as "dead" and therefore blocked.

    + Possible values: none,5m,10m,15m,30m,1h
    + Default value: none (no keep-alives will be sent)
    +
    @@ -2387,6 +2439,10 @@ sub FB_CALLMONITOR_checkNumberForDeflection($$) Der Username für das Telnet-Interface, sofern das Telefonbuch direkt von der FritzBox geladen werden soll (siehe Attribut: fritzbox-remote-phonebook). Dieses Attribut ist nur notwendig, wenn mehrere Benutzer auf der FritzBox konfiguriert sind.

  • apiKeySearchCh <API-Key>
  • Der private API-Key von tel.search.ch um eine Rückwärtssuche via search.ch durchzuführen (siehe Attribut reverse-search). Ohne einen solchen API-Key ist eine Rückwärtssuche via search.ch nicht möglich

    +
  • sendKeepAlives (none,5m,10m,15m,30m,1h)
  • + Wenn dieses Attribut gesetzt ist, wird ein zyklisches Keep-Alive im konfigurierten Zeitabstand an die FritzBox gesendet um die Verbindung aktiv zu halten. Dadurch bleibt die Verbindung bestehen, insbesondere wenn die verbundene FritzBox sich hinter einem weiteren NAT-Router befindet (z.B. einer weiteren FritzBox). Dadurch wird die Verbindung in so einem Fall nicht fälschlicherweise als "tot" erkannt und geblockt.

    + Mögliche Werte: none,5m,10m,15m,30m,1h
    + Standardwert ist "none" (es werden keine Keep-Alives gesendet)