From fc1b1afa7693b7d09c3ab4bf0ca1a5dc5e94f8ac Mon Sep 17 00:00:00 2001 From: wuehler <> Date: Mon, 12 Aug 2019 18:25:21 +0000 Subject: [PATCH] 74_Unifi: new setter to start RF-Scan git-svn-id: https://svn.fhem.de/fhem/trunk@19989 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/74_Unifi.pm | 47 ++++++++++++++++++++++++++++++------- fhem/FHEM/74_UnifiClient.pm | 4 ++-- fhem/FHEM/74_UnifiSwitch.pm | 4 +++- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/fhem/FHEM/74_Unifi.pm b/fhem/FHEM/74_Unifi.pm index 814ff18da..172877050 100644 --- a/fhem/FHEM/74_Unifi.pm +++ b/fhem/FHEM/74_Unifi.pm @@ -71,10 +71,14 @@ # - fixed: 74_Unifi: fixed restore clients at fhem restart # V 3.3.3 # - fixed: 74_Unifi: fixed (un)blockClient for UC Version 5.10.24 +# V 3.3.4 +# - fixed: 74_Unifi: fixed AP-Readingnames (use makeReadingName()) +# V 3.4.0 +# - feature: 74_Unifi: new setter to start RF-Scan package main; -my $version="3.3.3"; +my $version="3.4.0"; # Default für clientReadings setzen. Die Readings waren der Standard vor Einführung des Attributes customClientReadings. # Eine Änderung hat Auswirkungen auf (alte) Moduldefinitionen ohne dieses Attribut. my $defaultClientReadings=".:^accesspoint|^essid|^hostname|^last_seen|^snr|^uptime"; #ist wegen snr vs rssi nur halb korrekt, wird aber auch nicht wirklich verwendet ;-) @@ -347,14 +351,26 @@ sub Unifi_Set($@) { $disconnectedClientNames =~ s/.$//; #my $clientNames = Unifi_ClientNames($hash); - my $apNames = Unifi_ApNames($hash); + my $apNames = Unifi_ApNames($hash); # TODO: $apNames in $deviceNames umbenennen my $SSIDs = Unifi_SSIDs($hash); - - if($setName !~ /archiveAlerts|restartAP|setLocateAP|unsetLocateAP|disconnectClient|update|updateClient|clear|blockClient|unblockClient|enableWLAN|disableWLAN|switchSiteLEDs|createVoucher|removeClientReadings|refreshUsergroups/) { + + my $aps = ''; + for my $apID (keys %{$hash->{accespoints}}) { + my $apName=Unifi_ApNames($hash,$apID,'makeName'); + my $essid_Reading=ReadingsVal($name, '-AP_'.$apName.'_essid', undef); + my $has_essid=0; + $has_essid=1 if(defined $essid_Reading && $essid_Reading ne 'none'); + if ($has_essid){ + $aps .= $apName.','; + } + } + $aps =~ s/.$//; + + if($setName !~ /archiveAlerts|restartAP|setLocateAP|unsetLocateAP|startRFScan|disconnectClient|update|updateClient|clear|blockClient|unblockClient|enableWLAN|disableWLAN|switchSiteLEDs|createVoucher|removeClientReadings|refreshUsergroups/) { return "Unknown argument $setName, choose one of update:noArg " ."clear:all,readings,clientData,allData,voucherCache " .((defined $hash->{alerts_unarchived}[0] && scalar @{$hash->{alerts_unarchived}}) ? "archiveAlerts:noArg " : "") - .(($apNames && Unifi_CONNECTED($hash)) ? "restartAP:all,$apNames setLocateAP:all,$apNames unsetLocateAP:all,$apNames " : "") + .(($apNames && Unifi_CONNECTED($hash)) ? "restartAP:all,$apNames setLocateAP:all,$apNames unsetLocateAP:all,$apNames startRFScan:$aps " : "") .(($connectedClientNames && Unifi_CONNECTED($hash)) ? "disconnectClient:all,$connectedClientNames " : "") .(($disconnectedClientNames && Unifi_CONNECTED($hash)) ? "removeClientReadings:$disconnectedClientNames " : "") .(($unblockedClientNames && Unifi_CONNECTED($hash)) ? "blockClient:$unblockedClientNames " : "") @@ -490,6 +506,15 @@ sub Unifi_Set($@) { Unifi_ApCmd_Send($hash,'unset-locate',keys(%{$hash->{accespoints}})); } } + elsif ($setName eq 'startRFScan') { + $setVal = Unifi_ApNames($hash,$setVal,'makeID'); + if (defined $hash->{accespoints}->{$setVal}) { + Unifi_ApCmd_Send($hash,'spectrum-scan',$setVal); + } + else { + return "$hash->{NAME}: Unknown accesspoint '$setVal' in command '$setName', choose one of: $aps"; + } + } elsif ($setName eq 'removeClientReadings') { if($setVal && $setVal ne ""){ my $id = Unifi_ClientNames($hash,$setVal,'makeID'); @@ -1381,7 +1406,8 @@ sub Unifi_GetEvents_Receive($) { return undef; } ############################################################################### -sub Unifi_GetAccesspoints_Send($) { +sub Unifi_GetAccesspoints_Send($) { # TODO Umbenennen in Unifi_GetDevices_Send. Dann muss man auch an Get_ApNames() ran, da dort nicht nur APs sondern auch usg und switch drin sind. + # Waren wohl früher in Version 1 des Moduls nur APs unter devices my ($hash) = @_; my ($name,$self) = ($hash->{NAME},Unifi_Whoami()); Log3 $name, 5, "$name ($self) - executed."; @@ -1394,7 +1420,7 @@ sub Unifi_GetAccesspoints_Send($) { } ); return undef; } -sub Unifi_GetAccesspoints_Receive($) { +sub Unifi_GetAccesspoints_Receive($) {# TODO Umbenennen in Unifi_GetDevices_Receive my ($param, $err, $data) = @_; my ($name,$self,$hash) = ($param->{hash}->{NAME},Unifi_Whoami(),$param->{hash}); Log3 $name, 5, "$name ($self) - executed."; @@ -2038,7 +2064,7 @@ sub Unifi_CreateVoucher_Receive($) { } ############################################################################### -sub Unifi_ApCmd_Send($$@) { #cmd: 'set-locate', 'unset-locate', 'restart' +sub Unifi_ApCmd_Send($$@) { #cmd: 'set-locate', 'unset-locate', 'restart', 'startRFScan' my ($hash,$cmd,@aps) = @_; my ($name,$self) = ($hash->{NAME},Unifi_Whoami()); Log3 $name, 5, "$name ($self) - executed with cmd:'".$cmd."', count:'".scalar(@aps)."', ID:'".$aps[0]."'"; @@ -2663,11 +2689,14 @@ Or you can use the other readings or set and get features to control your unifi- Restart one ore all accesspoints.
  • set <name> setLocateAP <all|_id|name|ip>
    - Start 'locate' on one or all accesspoints.
  • + Start 'locate' on one or all accesspoints.
  • set <name> unsetLocateAP <all|_id|name|ip>
    Stop 'locate' on one or all accesspoints.

  • +
  • set <name> startRFScan <all|_id|name|ip>
    + Start 'RF-Scan' on one or all accesspoints. Does not work with 1. Gen APs.
  • +
  • set <name> blockClient <clientname>
    Block the <clientname>. Can also be called with the mac-address of the client.

  • diff --git a/fhem/FHEM/74_UnifiClient.pm b/fhem/FHEM/74_UnifiClient.pm index c7e1d6393..e7206ff13 100755 --- a/fhem/FHEM/74_UnifiClient.pm +++ b/fhem/FHEM/74_UnifiClient.pm @@ -264,8 +264,8 @@ sub UnifiClient_Parse($$) { $hash->{MODEL}=$clientRef->{oui}; my $old_tx=ReadingsVal($hash->{NAME},"tx_bytes",undef); - my $seconds=ReadingsAge($hash->{NAME},"tx_bytes",1); - $seconds=0.1 if ($seconds eq 0 || ! defined $seconds); + my $seconds=ReadingsAge($hash->{NAME},"tx_bytes",0); + $seconds=0.1 if (! defined $seconds || $seconds < 0.1); my $tx_used=0; if (defined $old_tx && defined $clientRef->{tx_bytes}){ $tx_used=($clientRef->{tx_bytes})-($old_tx); diff --git a/fhem/FHEM/74_UnifiSwitch.pm b/fhem/FHEM/74_UnifiSwitch.pm index 5b60b702b..ac3204bf3 100755 --- a/fhem/FHEM/74_UnifiSwitch.pm +++ b/fhem/FHEM/74_UnifiSwitch.pm @@ -23,12 +23,14 @@ # - bugfix: 74_UnififSwitch: fixed poe restart # V 0.0.94 # - feature: 74_UnififSwitch: supports new module UnifiClient +# V 0.0.95 +# - feature: 74_UnififSwitch: supports disablePort # # TODOs: # - state des USW für weiter state-Numbers korrekt in Worte übersetzen package main; -my $version="0.0.94"; +my $version="0.0.95"; # Laden evtl. abhängiger Perl- bzw. FHEM-Module use strict; use warnings;