From d3da167d85ae526bb22a801877b4757e7a47d3c0 Mon Sep 17 00:00:00 2001 From: tpoitzsch Date: Sat, 3 Jan 2015 12:00:51 +0000 Subject: [PATCH] FRITZBOX: set dect on|off git-svn-id: https://svn.fhem.de/fhem/trunk@7416 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/72_FRITZBOX.pm | 282 ++++++++++++++++++++++++++++----------- 1 file changed, 201 insertions(+), 81 deletions(-) diff --git a/fhem/FHEM/72_FRITZBOX.pm b/fhem/FHEM/72_FRITZBOX.pm index ea89738ec..4dd269dfc 100644 --- a/fhem/FHEM/72_FRITZBOX.pm +++ b/fhem/FHEM/72_FRITZBOX.pm @@ -49,6 +49,7 @@ sub FRITZBOX_Exec($$); sub FRITZBOX_SendMail($@); sub FRITZBOX_SetMOH($@); sub FRITZBOX_StartRadio($@); +sub FRITZBOX_Wlan_Run($); our $telnet; @@ -275,6 +276,7 @@ FRITZBOX_Set($$@) my $list = "alarm" . " createPwdFile" . " customerRingTone" + . " dect:on,off" . " diversity" . " guestWlan:on,off" . " moh" @@ -332,6 +334,18 @@ FRITZBOX_Set($$@) return FRITZBOX_SetCustomerRingTone $hash, @val; } + } elsif ( lc $cmd eq 'dect') { + if (int @val == 1 && $val[0] =~ /^(on|off)$/) + { + Log3 $name, 3, "FRITZBOX: set $name $cmd ".join(" ", @val); + my $state = $val[0]; + $state =~ s/on/1/; + $state =~ s/off/0/; + FRITZBOX_Exec( $hash, "ctlmgr_ctl w dect settings/enabled $state"); + readingsSingleUpdate($hash,"box_dect",$val[0], 1); + return undef; + } + } elsif ( lc $cmd eq 'diversity') { if ( int @val == 2 && defined( $hash->{READINGS}{"diversity".$val[0]} ) && $val[1] =~ /^(on|off)$/ ) { @@ -381,8 +395,7 @@ FRITZBOX_Set($$@) { Log3 $name, 3, "FRITZBOX: set $name $cmd ".join(" ", @val); push @cmdBuffer, "ring ".join(" ", @val); - FRITZBOX_Cmd_Start $hash->{helper}{TimerCmd}; - return undef; + return FRITZBOX_Cmd_Start $hash->{helper}{TimerCmd}; } } elsif ( lc $cmd eq 'sendmail') @@ -425,15 +438,8 @@ FRITZBOX_Set($$@) if (int @val == 1 && $val[0] =~ /^(on|off)$/) { Log3 $name, 3, "FRITZBOX: set $name $cmd ".join(" ", @val); - my $state = $val[0]; - $state =~ s/on/1/; - $state =~ s/off/0/; - FRITZBOX_Exec( $hash, "ctlmgr_ctl w wlan settings/wlan_enable $state"); - - $hash->{fhem}{LOCAL}=2; #2 = short update without new trigger - FRITZBOX_Readout_Start($hash->{helper}{TimerReadout}); - $hash->{fhem}{LOCAL}=0; - return undef; + push @cmdBuffer, "wlan ".join(" ", @val); + return FRITZBOX_Cmd_Start $hash->{helper}{TimerCmd}; } } @@ -497,8 +503,8 @@ FRITZBOX_Readout_Start($) } # end FRITZBOX_Readout_Start # Starts the data capturing and sets the new timer -sub ########################################## -FRITZBOX_Readout_Run($) +########################################## +sub FRITZBOX_Readout_Run($) { my ($name) = @_; my $hash = $defs{$name}; @@ -734,9 +740,11 @@ FRITZBOX_Readout_Run($) # Gäste WLAN push @readoutArray, [ "box_guestWlan", "ctlmgr_ctl r wlan settings/guest_ap_enabled", "onoff" ]; push @readoutArray, [ "box_guestWlanRemain", "ctlmgr_ctl r wlan settings/guest_time_remain", ]; -#Music on Hold +# Dect + push @readoutArray, [ "box_dect", "ctlmgr_ctl r dect settings/enabled", "onoff" ]; +# Music on Hold push @readoutArray, [ "box_moh", "ctlmgr_ctl r telcfg settings/MOHType", "mohtype" ]; -#Power Rate +# Power Rate push @readoutArray, [ "box_powerRate", "ctlmgr_ctl r power status/rate_sumact"]; # Alarm clock @@ -768,8 +776,8 @@ FRITZBOX_Readout_Run($) } # End FRITZBOX_Readout_Run -sub ########################################## -FRITZBOX_Readout_Done($) +########################################## +sub FRITZBOX_Readout_Done($) { my ($string) = @_; unless (defined $string) @@ -777,13 +785,30 @@ FRITZBOX_Readout_Done($) Log3 "FRITZBOX_Readout_Done", 1, "Fatal Error: no parameter handed over"; return; } - + + my ($name) = split("\\|", $string); + my $hash = $defs{$name}; + +# delete the marker for RUNNING_PID process + delete($hash->{helper}{READOUT_RUNNING_PID}); + + FRITZBOX_Readout_Process $string; + +} + +########################################## +sub FRITZBOX_Readout_Process($) +{ + my ($string) = @_; + unless (defined $string) + { + Log3 "FRITZBOX_Readout_Process", 1, "Fatal Error: no parameter handed over"; + return; + } + my ($name, %values) = split("\\|", $string); my $hash = $defs{$name}; - # delete the marker for RUNNING_PID process - delete($hash->{helper}{READOUT_RUNNING_PID}); - FRITZBOX_Log $hash, 5, "Processing ". keys(%values)." readouts."; readingsBeginUpdate($hash); @@ -820,12 +845,16 @@ FRITZBOX_Readout_Done($) if ($rValue ne "") { readingsBulkUpdate( $hash, $rName, $rValue ); - FRITZBOX_Log $hash, 5, "$rName = '$rValue'"; + FRITZBOX_Log $hash, 5, "SET $rName = '$rValue'"; } elsif ( exists( $hash->{READINGS}{$rName} ) ) { delete $hash->{READINGS}{$rName}; - FRITZBOX_Log $hash, 5, "Delete '$rName'."; + FRITZBOX_Log $hash, 5, "Delete reading $rName."; + } + else + { + FRITZBOX_Log $hash, 5, "Ignore reading $rName."; } } } @@ -833,22 +862,25 @@ FRITZBOX_Readout_Done($) my $msg = keys( %values )." values captured in ".$values{readoutTime}." s"; readingsBulkUpdate( $hash, "lastReadout", $msg ); FRITZBOX_Log $hash, 4, $msg; - my $newState = "WLAN: "; - if ( $values{"box_wlan_2.4GHz"} eq "on" ) { - $newState .= "on"; - } elsif ( defined $values{box_wlan_5GHz} ) { - if ( $values{box_wlan_5GHz} eq "on") { + if ( defined $values{box_wlan_5GHz} && defined $values{"box_wlan_2.4GHz"} && defined $values{box_guestWLan} ) + { + my $newState = "WLAN: "; + if ( $values{"box_wlan_2.4GHz"} eq "on" ) { $newState .= "on"; + } elsif ( defined $values{box_wlan_5GHz} ) { + if ( $values{box_wlan_5GHz} eq "on") { + $newState .= "on"; + } else { + $newState .= "off"; + } } else { $newState .= "off"; } - } else { - $newState .= "off"; + $newState .=" gWLAN: ".$values{box_guestWlan} ; + $newState .=" (Remain: ".$values{box_guestWlanRemain}." min)" + if $values{box_guestWlan} eq "on" && $values{box_guestWlanRemain} != 0; + readingsBulkUpdate( $hash, "state", $newState); } - $newState .=" gWLAN: ".$values{box_guestWlan} ; - $newState .=" (Remain: ".$values{box_guestWlanRemain}." min)" - if $values{box_guestWlan} eq "on" && $values{box_guestWlanRemain} != 0; - readingsBulkUpdate( $hash, "state", $newState); } readingsEndUpdate( $hash, 1 ); @@ -992,6 +1024,9 @@ sub FRITZBOX_Cmd_Start($) my $func = substr $timerpara, $index + 1, length($timerpara); # function extrahieren my $name = substr $timerpara, 0, $index; # name extrahieren my $hash = $defs{$name}; + my $cmdFunction; + my $timeout; + my $handover; return unless int @cmdBuffer; @@ -1017,26 +1052,89 @@ sub FRITZBOX_Cmd_Start($) my @val = split / /, $cmdBuffer[0]; +# Preparing SET RING if ($val[0] eq "ring") { shift @val; - - my $timeout = 5; + $timeout = 5; $timeout = $val[1] if $val[1] =~/^\d+$/; $timeout += 60; $cmdBufferTimeout = time() + $timeout; - - my $handover = $name . "|" . join( "|", @val ); - $hash->{helper}{CMD_RUNNING_PID} = BlockingCall("FRITZBOX_Ring_Run", $handover, - "FRITZBOX_Cmd_Done", $timeout, - "FRITZBOX_Cmd_Aborted", $hash) - unless exists $hash->{helper}{CMD_RUNNING_PID}; + $handover = $name . "|" . join( "|", @val ); + $cmdFunction = "FRITZBOX_Ring_Run"; } +# Preparing SET WLAN + elsif ($val[0] eq "wlan") + { + shift @val; + $timeout = 10; + $cmdBufferTimeout = time() + $timeout; + $handover = $name . "|" . join( "|", @val ); + $cmdFunction = "FRITZBOX_Wlan_Run"; + } +# No valid set operation + else + { + my $msg = "Unknown command '".join( " ", @val )."'"; + FRITZBOX_Log $hash, 1, $msg; + return $msg; + } + +# Starting new command + $hash->{helper}{CMD_RUNNING_PID} = BlockingCall($cmdFunction, $handover, + "FRITZBOX_Cmd_Done", $timeout, + "FRITZBOX_Cmd_Aborted", $hash); + return undef; } # end FRITZBOX_Cmd_Start -sub ########################################## -FRITZBOX_Ring_Run($) +########################################## +sub FRITZBOX_Wlan_Run($) +{ + my ($string) = @_; + my ($name, @val) = split "\\|", $string; + my $hash = $defs{$name}; + my $result; + my @readoutArray; + my @readoutReadings; + my $startTime = time(); + + my $state = $val[0]; + $state =~ s/on/1/; + $state =~ s/off/0/; + + $result = FRITZBOX_Open_Connection( $hash ); + return "$name|0|$result" + if $result; + + my $returnStr = "$name|2|"; + +# Set WLAN + push @readoutArray, [ "", "ctlmgr_ctl w wlan settings/wlan_enable $state"]; +# Read WLAN + push @readoutArray, [ "box_wlan_2.4GHz", "ctlmgr_ctl r wlan settings/ap_enabled", "onoff" ]; +# Read 2nd WLAN + push @readoutArray, [ "box_wlan_5GHz", "ctlmgr_ctl r wlan settings/ap_enabled_scnd", "onoff" ]; +# Read Gäste WLAN + push @readoutArray, [ "box_guestWlan", "ctlmgr_ctl r wlan settings/guest_ap_enabled", "onoff" ]; + push @readoutArray, [ "box_guestWlanRemain", "ctlmgr_ctl r wlan settings/guest_time_remain", ]; + +# Execute commands + FRITZBOX_Readout_Query( $hash, \@readoutArray, \@readoutReadings); + + $returnStr .= join('|', @readoutReadings ); + $returnStr .= "|readoutTime|"; + $returnStr .= sprintf "%.2f", time()-$startTime; + + FRITZBOX_Close_Connection ( $hash ); + + FRITZBOX_Log $hash, 5, "Handover: ".$returnStr; + return $returnStr + +} # end FRITZBOX_Wlan_Run + +########################################## +sub FRITZBOX_Ring_Run($) { my ($string) = @_; my ($name, @val) = split "\\|", $string; @@ -1230,20 +1328,24 @@ FRITZBOX_Cmd_Done($) my ($string) = @_; return unless defined $string; - my ($name, $success, $result) = split("\\|", $string); + my ($name, $success, $result) = split("\\|", $string,3); my $hash = $defs{$name}; shift (@cmdBuffer); delete($hash->{helper}{CMD_RUNNING_PID}); - if ($success != 1) + if ( $success !~ /1|2/ ) { FRITZBOX_Log $hash, 1, $result; } - else + elsif ( $success == 1 ) { FRITZBOX_Log $hash, 4, $result; } + elsif ($success == 2 ) + { + FRITZBOX_Readout_Process ( $name."|".$result ); + } } ########################################## @@ -1891,8 +1993,37 @@ sub FRITZBOX_fritztris($) return $returnStr; } + ##################################### + #
  • set <name> convertRingTone <fullFilePath> + #
    + # Converts the mp3-file fullFilePath to the G722 format and puts it in the same path. + #
    + # The file has to be placed on the file system of the Fritz!Box. + #

  • + + #
  • set <name> convertMusicOnHold <fullFilePath> + #
    + # Not implemented yet. Converts the mp3-file fullFilePath to a format that can be used for "Music on Hold". + #
    + # The file has to be placed on the file system of the fritzbox. + #

  • + + #
  • set <name> convertRingTone <fullFilePath> + #
    + # Konvertiert die mp3-Datei fullFilePath in das G722-Format und legt es im selben Pfad ab. + #
    + # Die Datei muss im Dateisystem der Fritz!Box liegen. + #

  • + + #
  • set <name> convertMusicOnHold <fullFilePath> + #
    + # Not implemented yet. Converts the mp3-file fullFilePath to a format that can be used for "Music on Hold". + #
    + # The file has to be placed on the file system of the fritzbox. + #

  • + 1; =pod @@ -1938,20 +2069,6 @@ sub FRITZBOX_fritztris($) Switches the alarm number (1, 2 or 3) on or off.
    -
  • set <name> convertRingTone <fullFilePath> -
    - Converts the mp3-file fullFilePath to the G722 format and puts it in the same path. -
    - The file has to be placed on the file system of the Fritz!Box. -

  • - -
  • set <name> convertMusicOnHold <fullFilePath> -
    - Not implemented yet. Converts the mp3-file fullFilePath to a format that can be used for "Music on Hold". -
    - The file has to be placed on the file system of the fritzbox. -

  • -
  • set <name> createPwdFile <password>
    Creates a file that contains the telnet password. The file name corresponds to the one used for remote telnet access. @@ -1966,6 +2083,11 @@ sub FRITZBOX_fritztris($) The upload takes about one minute before the tone is available.

  • +
  • set <name> dect <on|off> +
    + Switches the DECT base of the box on or off. +

  • +
  • set <name> diversity <number> <on|off>
    Switches the call diversity number (1, 2 ...) on or off. @@ -1989,7 +2111,7 @@ sub FRITZBOX_fritztris($)

  • -
  • set <name> ring <internalNumbers> [duration [ringTone]] [show:Text] [say:Text] +
  • set <name> ring <intNumbers> [duration [ringTone]] [show:Text] [say:Text]
    Example:
    @@ -2095,7 +2217,7 @@ sub FRITZBOX_fritztris($) To ring a fon a caller must always be specified. Default of this modul is 50 "ISDN:Wählhilfe".
    To show a message (default: "FHEM") during a ring the internal phone numbers 1-3 can be specified here. - The concerned analog phone socket must exist. + The concerned analog phone socket must exist.

  • telnetTimeOut <seconds> @@ -2116,6 +2238,7 @@ sub FRITZBOX_fritztris($)
  • alarm1_time - Alarm time of the alarm clock 1
  • alarm1_wdays - Weekdays of the alarm clock 1
  • +
  • box_dect - Current state of the DECT base
  • box_fwVersion - Firmware version of the box, if outdated then '(old)' is appended
  • box_guestWlan - Current state of the guest WLAN
  • box_guestWlanRemain - Remaining time until the guest WLAN is switched off
  • @@ -2201,20 +2324,6 @@ sub FRITZBOX_fritztris($) Schaltet den Weckruf Nummer 1, 2 oder 3 an oder aus.
    -
  • set <name> convertRingTone <fullFilePath> -
    - Konvertiert die mp3-Datei fullFilePath in das G722-Format und legt es im selben Pfad ab. -
    - Die Datei muss im Dateisystem der Fritz!Box liegen. -

  • - -
  • set <name> convertMusicOnHold <fullFilePath> -
    - Not implemented yet. Converts the mp3-file fullFilePath to a format that can be used for "Music on Hold". -
    - The file has to be placed on the file system of the fritzbox. -

  • -
  • set <name> createPwdFile <password>
    Erzeugt eine Datei welche das Telnet-Passwort enthält. Der Dateiname entspricht demjenigen, der für den Telnetzugriff genutzt wird. @@ -2224,12 +2333,18 @@ sub FRITZBOX_fritztris($)
    Lädt die MP3-Datei als Klingelton auf das angegebene Telefon. Die Datei muss im Dateisystem der Fritzbox liegen.
    - Das Hochladen dauert etwa eine Minute bis der Klingelton verfü,gbar ist. + Das Hochladen dauert etwa eine Minute bis der Klingelton verfügbar ist. +

  • + +
  • set <name> dect <on|off> +
    + Schaltet die DECT-Basis der Box an oder aus.

  • set <name> diversity <number> <on|off>
    Schaltet die Rufumleitung (Nummer 1, 2 ...) an oder aus. +
    Die Rufumleitung muss zuvor auf der Fritz!Box eingerichtet werden.
    Achtung! Die Fritz!Box ermöglicht auch eine Weiterleitung in Abhängigkeit von der anrufenden Nummer. Diese Art der Weiterleitung kann hiermit nicht geschaltet werden. @@ -2251,8 +2366,12 @@ sub FRITZBOX_fritztris($)

  • -
  • set <name> ring <interneNummern> [Dauer [Klingelton]] [show:Nachricht] - Beispiel: set fritzbox ring 611,612 5 Budapest show:Es regnet +
  • set <name> ring <intNummern> [Dauer [Klingelton]] [show:Text] [say:Text] + Beispiel: +
    + set fritzbox ring 611,612 5 Budapest show:Es regnet +
    + set fritzbox ring 610 say:Es regnet
    Lässt die internen Nummern für "Dauer" Sekunden und (auf Fritz!Fons) mit dem angegebenen "Klingelton" klingeln. Mehrere interne Nummern müssen durch ein Komma (ohne Leerzeichen) getrennt werden. @@ -2265,7 +2384,7 @@ sub FRITZBOX_fritztris($)
    Auf Fritz!Fons wird der Text hinter dem Parameter 'say:' direkt angesagt (gefolgt vom dem Standard Klingelton). Dieses Feature erzeugt die Internetradiostation 39 'fhemTTS' und nutzt translate.google.com.
    - Wenn der Anruf angenommen wird, hört der Angerufene die Wartemusik (music on hold), welche zur Nachrichtenübermittlung genutzt werden kann. + Wenn der Anruf angenommen wird, hört der Angerufene die Wartemusik (music on hold), welche ebenfalls zur Nachrichtenübermittlung genutzt werden kann.

  • set <name> sendMail [to:<Address>] [subject:<Subject>] [body:<Text>] @@ -2368,6 +2487,7 @@ sub FRITZBOX_fritztris($)
  • alarm1_time - Weckzeit des Weckrufs 1
  • alarm1_wdays - Wochentage des Weckrufs 1
  • +
  • box_dect - Aktueller Status des DECT-Basis
  • box_fwVersion - Firmware-Version der Box, wenn veraltet dann wird '(old)' angehangen
  • box_guestWlan - Aktueller Status des Gäste-WLAN
  • box_guestWlanRemain - Verbleibende Zeit bis zum Ausschalten des Gäste-WLAN