diff --git a/fhem/FHEM/72_FRITZBOX.pm b/fhem/FHEM/72_FRITZBOX.pm index fd35b0c4c..c2832027a 100644 --- a/fhem/FHEM/72_FRITZBOX.pm +++ b/fhem/FHEM/72_FRITZBOX.pm @@ -41,7 +41,7 @@ use warnings; use Blocking; use HttpUtils; -my $ModulVersion = "07.50.5"; +my $ModulVersion = "07.50.6"; my $missingModul = ""; my $missingModulTelnet = ""; my $missingModulWeb = ""; @@ -220,6 +220,7 @@ sub FRITZBOX_Initialize($) ."enableVPNShares:0,1 " ."enableUserInfo:0,1 " ."enableAlarmInfo:0,1 " + ."enableWanInfo:0,1 " ."disableDectInfo:0,1 " ."disableFonInfo:0,1 " ."enableSIP:0,1 " @@ -404,6 +405,14 @@ sub FRITZBOX_Attr($@) } } + if ($aName eq "enableWanInfo") { + if ($cmd eq "del" || $aVal == 0) { + foreach (keys %{ $hash->{READINGS} }) { + readingsDelete($hash, $_) if $_ =~ /^wan_.*/ && defined $hash->{READINGS}{$_}{VAL}; + } + } + } + if ($aName eq "disableDectInfo") { if ($cmd eq "del" || $aVal == 1) { foreach (keys %{ $hash->{READINGS} }) { @@ -1126,6 +1135,8 @@ sub FRITZBOX_Get($@) $returnStr = FRITZBOX_Kid_Profiles_List($hash); } elsif ( $val[0] eq "userInfos") { $returnStr = FRITZBOX_User_Info_List($hash); + } elsif ( $val[0] eq "wlanEnvironment") { + $returnStr = FRITZBOX_WLAN_Environment($hash); } return $returnStr; @@ -1186,7 +1197,7 @@ sub FRITZBOX_Get($@) $list .= "luaQuery" if AttrVal( $name, "allowTR064Command", 0 ); $list .= " luaData" if AttrVal( $name, "allowTR064Command", 0 ); $list .= " luaFunction" if AttrVal( $name, "allowTR064Command", 0 ); - $list .= " luaInfo:lanDevices,vpnShares,kidProfiles,userInfos" if AttrVal( $name, "allowTR064Command", 0 ); + $list .= " luaInfo:lanDevices,vpnShares,kidProfiles,userInfos,wlanEnvironment" if AttrVal( $name, "allowTR064Command", 0 ); $list .= " lanDeviceInfo" if AttrVal( $name, "allowTR064Command", 0 ); @@ -2562,14 +2573,75 @@ sub FRITZBOX_Readout_Run_Web($) FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_guestWlan", $result->{box_guestWlan}, "onoff"; FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_guestWlanRemain", $result->{box_guestWlanRemain}; FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_macFilter_active", $result->{box_macFilter_active}, "onoff"; + +# WANs + + # "xhr 1 lang de page chan xhrId environment; + + if (AttrVal( $name, "enableWanInfo", "0")) { + my %oldWanDevice; + #collect current mac-readings (to delete the ones that are inactive or disappeared) + foreach (keys %{ $hash->{READINGS} }) { + $oldWanDevice{$_} = $hash->{READINGS}{$_}{VAL} if $_ =~ /^wan_/ && defined $hash->{READINGS}{$_}{VAL}; + } + + my @webCmdArray; + push @webCmdArray, "xhr" => "1"; + push @webCmdArray, "lang" => "de"; + push @webCmdArray, "page" => "chan"; + push @webCmdArray, "xhrId" => "environment"; + + my $result = FRITZBOX_Lua_Data( $hash, \@webCmdArray) ; + my $tmp; + + if(defined $result->{Error}) { + $tmp = FRITZBOX_ERR_Result($hash, $result); + } else { + + FRITZBOX_Log $hash, 5, "DEBUG: \n" . Dumper ($result->{data}->{scanlist}); + + my $views = $result->{data}->{scanlist}; + my $nbViews = scalar @$views; + + eval { + for(my $i = 0; $i <= $nbViews - 1; $i++) { + my $dName = $result->{data}->{scanlist}->[$i]->{ssid}; + $dName .= " (Kanal: " . $result->{data}->{scanlist}->[$i]->{channel}; + $dName .= ", Band: " . $result->{data}->{scanlist}->[$i]->{bandId} . ")"; + + $rName = $result->{data}->{scanlist}->[$i]->{mac}; + $rName =~ s/:/_/g; + $rName = "wan_" . $rName; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, $rName, $dName; + delete $oldWanDevice{$rName} if exists $oldWanDevice{$rName}; + } + }; + } + # Remove inactive or non existing wan-readings in two steps + foreach ( keys %oldWanDevice ) { + # set the wan readings to 'inactive' and delete at next readout + if ( $oldWanDevice{$_} ne "inactive" ) { + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, $_, "inactive"; + } + else { + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, $_, ""; + } + } + + } + # Dect FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_dect", $result->{box_dect}, "onoff"; + # Music on Hold FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_moh", $result->{box_moh}, "mohtype"; + # Power Rate FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_powerRate", $result->{box_powerRate}; + # Box Features FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->is_double_wlan", $result->{is_double_wlan}, "01"; + # Box model, firmware and uptimes # Informationen über DSL Verbindung @@ -2679,13 +2751,13 @@ sub FRITZBOX_Readout_Run_Web($) } } - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_fwUpdate", $result->{box_fwUpdate}; #unless(grep { /^(box_fwUpdate)$/ } @reading_list); - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_tr064", $result->{box_tr064}, "onoff"; #unless(grep { /^(box_tr064)$/ } @reading_list); - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_tr069", $result->{box_tr069}, "onoff"; #unless(grep { /^(box_tr069)$/ } @reading_list); - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_stdDialPort", $result->{box_stdDialPort}, "dialport"; #unless(grep { /^(box_stdDialPort)$/ } @reading_list); + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_fwUpdate", $result->{box_fwUpdate}; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_tr064", $result->{box_tr064}, "onoff"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_tr069", $result->{box_tr069}, "onoff"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_stdDialPort", $result->{box_stdDialPort}, "dialport"; # FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_ipExtern", $result->{box_ipExtern}; # FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_connect", $result->{box_connect}; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_cpuTemp", $result->{box_cpuTemp}; #unless(grep { /^(box_cpuTemp)$/ } @reading_list); + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_cpuTemp", $result->{box_cpuTemp}; if ( defined ($result->{dslStatGlobalOut}) && looks_like_number($result->{dslStatGlobalOut}) ) { FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_dsl_upStream", sprintf ("%.3f", $result->{dslStatGlobalOut}/1000000) unless (grep { /^(box_dsl_upStream)$/ } @reading_list); } @@ -6696,6 +6768,75 @@ sub FRITZBOX_Kid_Profiles_List($) { return $returnStr; } + +# get list of WLAN in environment +############################################ +sub FRITZBOX_WLAN_Environment($) { + + my ($hash) = @_; + my $name = $hash->{NAME}; + + # "xhr 1 lang de page chan xhrId environment; + #my $queryStr; + #$queryStr .= "'xhr' => '1'\n"; + #$queryStr .= "'lang' => 'de'\n"; + #$queryStr .= "'page' => 'chan'\n"; + #$queryStr .= "'xhrId' => 'environment'\n"; + + my @webCmdArray; + push @webCmdArray, "xhr" => "1"; + push @webCmdArray, "lang" => "de"; + push @webCmdArray, "page" => "chan"; + push @webCmdArray, "xhrId" => "environment"; + + my $returnStr; + + $returnStr .= "WLAN: Netzwerke in der Umgebung\n"; + $returnStr .= "---------------------------------\n"; + + my $result = FRITZBOX_Lua_Data( $hash, \@webCmdArray) ; + my $tmp; + + if(defined $result->{Error}) { + $tmp = FRITZBOX_ERR_Result($hash, $result); + return $returnStr . $tmp; + } + + FRITZBOX_Log $hash, 5, "DEBUG: \n" . Dumper ($result->{data}->{scanlist}); + + my $views = $result->{data}->{scanlist}; + my $nbViews = scalar @$views; + my $lDump = ""; + + $returnStr .= "
SSID | Kanal | BandID\n"; + $returnStr .= " |
" . $result->{data}->{scanlist}->[$i]->{ssid} . " | "; + $returnStr .= "" . $result->{data}->{scanlist}->[$i]->{channel} . " | "; + $returnStr .= "" . $result->{data}->{scanlist}->[$i]->{bandId} . " | "; + $returnStr .= "
enableWanInfo <0 | 1>
forceTelnetConnection <0 | 1>
enableWanInfo <0 | 1>
forceTelnetConnection <0 | 1>