From c3f84f295f139d05cc43dee17aecc25369329364 Mon Sep 17 00:00:00 2001 From: wzut <> Date: Sat, 25 Apr 2015 17:34:22 +0000 Subject: [PATCH] 98_Ubiquiti: add german commandref , fix some timings git-svn-id: https://svn.fhem.de/fhem/trunk@8478 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_UbiquitiMP.pm | 205 ++++++++++++++++++++++++++----------- 1 file changed, 143 insertions(+), 62 deletions(-) diff --git a/fhem/FHEM/98_UbiquitiMP.pm b/fhem/FHEM/98_UbiquitiMP.pm index 536e1aa84..7fbc9fd55 100644 --- a/fhem/FHEM/98_UbiquitiMP.pm +++ b/fhem/FHEM/98_UbiquitiMP.pm @@ -3,7 +3,7 @@ # $Id$ # # (c) 2015 Copyright: Wzut -# forum : http://forum.fhem.de/index.php/topic,34131.0.html +# forum : http://forum.fhem.de/index.php/topic,35722.0.html # All rights reserved # # This code is free software; you can redistribute it and/or modify @@ -25,6 +25,9 @@ # 10.04.15 add enable/disable # 18.04.15 add toggle # 20.04.15 add Groups +# first svn Version +# 23.04.15 add Set Extensions for 1 Port Ubi , change Client to UbiquitiOut, +# 25.06.15 add german docu, fix some timing problems package main; @@ -56,33 +59,37 @@ sub UbiquitiMP_Initialize($) sub UbiquitiMP_updateConfig($) { - # this routine is called 10 sec after the last define of a restart + # this routine is called 5 sec after the last define of a restart # this gives FHEM sufficient time to fill in attributes my ($hash) = @_; my $name = $hash->{NAME}; - $hash->{INTERVAL} = AttrVal($name, "interval", 300); - - readingsSingleUpdate($hash,"state","Initialized",1); - - $hash->{".led"} = AttrVal($name, "ledconnect", 0); - if ($hash->{".led"}) # Farben nach Kommando + if (!$init_done) { - $hash->{".led"} = 0 if ($hash->{".led"} eq "off"); - $hash->{".led"} = 1 if ($hash->{".led"} eq "blue"); - $hash->{".led"} = 2 if ($hash->{".led"} eq "yellow"); - $hash->{".led"} = 3 if ($hash->{".led"} eq "both"); - $hash->{".led"} = 4 if ($hash->{".led"} eq "alternate"); + RemoveInternalTimer($hash); + InternalTimer(gettimeofday()+5,"UbiquitiMP_updateConfig", $hash, 0); + return; + } + + + $hash->{INTERVAL} = AttrVal($name, "interval", 300); + $hash->{".led"} = AttrVal($name, "ledconnect", 0); + + if ($hash->{".led"}) # Farben nach Kommando + { + $hash->{".led"} = "0" if ($hash->{".led"} eq "off"); + $hash->{".led"} = "1" if ($hash->{".led"} eq "blue"); + $hash->{".led"} = "2" if ($hash->{".led"} eq "yellow"); + $hash->{".led"} = "3" if ($hash->{".led"} eq "both"); + $hash->{".led"} = "4" if ($hash->{".led"} eq "alternate"); } - #$hash->{SNAME} = ""; - #$hash->{BNAME} = ""; $hash->{MAC} = ""; $hash->{lastcmd} = "Init"; - + $hash->{".init"} = 1; RemoveInternalTimer($hash); - InternalTimer(gettimeofday()+($hash->{".timeout"}*2), "UbiquitiMP_GetStatus",$hash, 0) if ($hash->{".timeout"}); + InternalTimer(gettimeofday()+5, "UbiquitiMP_GetStatus",$hash, 0); return undef; } @@ -96,7 +103,7 @@ sub UbiquitiMP_Define($$) { my @a = split("[ \t][ \t]*", $def); return "wrong syntax: define UbiquitiMP " if(int(@a) < 3); - + $hash->{".host"} = $a[2]; if( !defined( $attr{$a[0]}{user} ) ) { $attr{$a[0]}{user} = "ubnt";} @@ -107,8 +114,8 @@ sub UbiquitiMP_Define($$) { if( !defined( $attr{$a[0]}{subDevices} ) ) { $attr{$a[0]}{subDevices} = "1";} - if( !defined( $attr{$a[0]}{timeout} ) ) { $attr{$a[0]}{timeout} = "2"} - $hash->{".timeout"} = (int($attr{$a[0]}{timeout}) > 1) ? $attr{$a[0]}{timeout} : "2"; + if( !defined( $attr{$a[0]}{timeout} ) ) { $attr{$a[0]}{timeout} = "5"} + $hash->{".timeout"} = (int($attr{$a[0]}{timeout}) > 1) ? $attr{$a[0]}{timeout} : "5"; if( !defined( $attr{$a[0]}{subDevices} ) ) { $attr{$a[0]}{subDevices} = "1"} $hash->{".subdevices"} = $attr{$a[0]}{subDevices}; @@ -121,7 +128,7 @@ sub UbiquitiMP_Define($$) { readingsSingleUpdate($hash, "state", "defined",0); RemoveInternalTimer($hash); - InternalTimer(gettimeofday()+10, "UbiquitiMP_updateConfig",$hash,0); # in 10 Sekunden machen wir den Rest + InternalTimer(gettimeofday()+5, "UbiquitiMP_updateConfig",$hash,0); # in 5 Sekunden machen wir den Rest return undef; } @@ -158,7 +165,7 @@ sub UbiquitiMP_force($) { Log3 $name, 5, "$name, BC force process started with PID(".$hash->{helper}{RUNNING_PID}{pid}.") cmd : $cmdlist"; } - else + else { # das war wohl schon wieder nix :( InternalTimer(gettimeofday()+(int($hash->{".timeout"})*3), "UbiquitiMP_force",$hash, 0); } @@ -179,7 +186,7 @@ sub UbiquitiMP_Attr(@) if ($attrName eq "timeout") { - if (int($attrVal)<"2") {$attrVal="2";} + if (int($attrVal) < 2) {$attrVal="5";} $hash->{".timeout"} = $attrVal; $attr{$name}{timeout} = $attrVal; } @@ -206,11 +213,11 @@ sub UbiquitiMP_Attr(@) } elsif ($attrName eq "ledconnect") { - $hash->{".led"} = 0 if ($attrVal eq "off"); - $hash->{".led"} = 1 if ($attrVal eq "blue"); - $hash->{".led"} = 2 if ($attrVal eq "yellow"); - $hash->{".led"} = 3 if ($attrVal eq "both"); - $hash->{".led"} = 4 if ($attrVal eq "alternate"); + $hash->{".led"} = "0" if ($attrVal eq "off"); + $hash->{".led"} = "1" if ($attrVal eq "blue"); + $hash->{".led"} = "2" if ($attrVal eq "yellow"); + $hash->{".led"} = "3" if ($attrVal eq "both"); + $hash->{".led"} = "4" if ($attrVal eq "alternate"); $attr{$name}{ledconnect} = $attrVal; } elsif ($attrName eq "groupPorts") @@ -228,7 +235,6 @@ sub UbiquitiMP_Attr(@) sub UbiquitiMP_Get($@) { my ($hash, $name , @a) = @_; my $cmd = $a[0]; - #Log3 $name, 5, "Get: ".join(" ", @a); return "get $name needs one argument" if (int(@a) != 1); @@ -252,7 +258,7 @@ sub UbiquitiMP_Get($@) { } else { # das war wohl nix :( - Log3 $name, 5, "$name, BC process start failed !"; + Log3 $name, 3, "$name, BC process start failed, cmd : $cmd "; return $name.", can't execute get command as NonBlockingCall"; } @@ -287,7 +293,7 @@ sub UbiquitiMP_Set($@) { } return "$name wrong command, please use on of on,off,toggle,lock,unlock,enable,disable or reset" if($cmd !~ /^(on|off|lock|unlock|reset|enable|disable|toggle)$/); } - else + else # die mPower mini { $port = "Out1"; $cmd = (defined($a[1])) ? $a[1] : ""; @@ -329,9 +335,9 @@ sub UbiquitiMP_Set($@) { $hash->{force} = ($subcmd eq "force") ? $hash->{helper}{RUNNING_PID}{pid} : 0; Log3 $name, 5, "$name, BC process started with PID(".$hash->{helper}{RUNNING_PID}{pid}.") cmd : $cmdlist , subcmd : $subcmd"; } - else + else { # das war wohl nix :( - Log3 $name, 5, "$name, BC process start failed !"; + Log3 $name, 3, "$name, BC process start failed , cmd : $cmdlist , subcmd : $subcmd"; UbiquitiMP_force($hash) if ($hash->{force}) ; # muessen wir das wiederholen ? return $name.", can't execute set as NonBlockingCall"; } @@ -368,7 +374,7 @@ sub UbiquitiMP_BCStart($) $sock->login( Name => $hash->{".user"}, Password => $hash->{".pwd"} ); if (!$sock->errmsg) { - $sock->cmd("echo '".$hash->{".led"}."' >/proc/led/status") if ($hash->{".led"}); + $sock->cmd("echo '".$hash->{".led"}."' >/proc/led/status") if ($hash->{".led"} ne "0"); if (($cmd eq "reset") || ($cmd eq "toggle") || ($cmd eq "lock") || ($cmd eq "unlock") || @@ -405,7 +411,7 @@ sub UbiquitiMP_BCStart($) } } # foreach - select(undef, undef, undef, 0.5); # 500 ms warten ! + select(undef, undef, undef, 0.25); # 250 ms warten ! @ret = $sock->cmd("/sbin/cgi /usr/www/mfi/sensors.cgi"); # neue Statuswerte holen if($ret[2]) @@ -418,7 +424,7 @@ sub UbiquitiMP_BCStart($) $output .= "|1|$cmd|"; foreach(@a) { - select(undef, undef, undef, 0.5); + select(undef, undef, undef, 0.25); @ret = $sock->cmd($_); Log3 $name, 5, "$name, ret -> ".$ret[0]; if ($cmd eq "status") { if($ret[2]) { ($ret[2],undef) = split("MF",$ret[2]); $output .= $ret[2]; } else { if ($ret[0]) {$ret[0] =~s/^MF.*//g; $output .= "|".$ret[0];}}} @@ -426,7 +432,7 @@ sub UbiquitiMP_BCStart($) } } - $sock->cmd("echo '0' >/proc/led/status") if ($hash->{".led"}); + $sock->cmd("echo '0' >/proc/led/status") if ($hash->{".led"} ne "0"); $sock->close; $output =~s/\n//g; @@ -505,7 +511,7 @@ sub UbiquitiMP_BCAborted($) { UbiquitiMP_force($hash); } - elsif ($hash->{lastcmd} eq "GetStatus") # war das ein erfolgloser auto status update ? + elsif ($hash->{lastcmd} eq "GetStatus") # war das ein erfolgloses auto status update ? { InternalTimer(gettimeofday()+$hash->{INTERVAL}, "UbiquitiMP_GetStatus",$hash, 0) if($hash->{INTERVAL}); } @@ -535,7 +541,6 @@ sub UbiquitiMP_Status($$@) $json = JSON->new->utf8(0)->decode($js); my $sensors = scalar keys $json->{sensors}; - #$sensors = 1 if ($sensors); if ((!$hash->{PORTS}) && ($sensors > 0)) # nur einmal zu Begin bzw nach reload { @@ -546,11 +551,10 @@ sub UbiquitiMP_Status($$@) # bei der 1 Port Ubi default keine Subdevices , bei den anderen ja my $subdev = (int($hash->{PORTS}) >1) ? AttrVal($name, "subDevices", 1) : AttrVal($name, "subDevices", 0); - @ener = split(" ",$a[2]) if (defined($a[2])); readingsBeginUpdate($hash); - + for (my $i=0; $i<$sensors; $i++) { if (index(AttrVal($name, "ignoreList", "") , $i+1) == -1) # welche Ports ignorieren ? @@ -725,7 +729,6 @@ sub UbiquitiMP_Info($$) if ($ports > 0) { $hash->{PORTS} = $ports; - #$hash->{PORTS} = 1; UbiquitiMP_createSets($hash); } } @@ -742,6 +745,13 @@ sub UbiquitiMP_Info($$) } } + if ($hash->{".init"}) # kommen wir ueber einen Neustart ? + { + readingsSingleUpdate($hash,"state","Initialized",1); + delete($hash->{".init"}); + InternalTimer(gettimeofday()+$hash->{".timeout"}, "UbiquitiMP_GetStatus",$hash, 0); + } + return undef; } @@ -753,11 +763,9 @@ sub UbiquitiMP_GetStatus($) my $name = $hash->{NAME}; my $cmd = $name; - #RemoveInternalTimer($hash); - Log3 $name, 5, "$name, GetStatus Interval : ".$hash->{INTERVAL}; - if ($hash->{lastcmd} eq "Init") # kommen wir ueber einen Neustart ? + if ($hash->{".init"}) # kommen wir ueber einen Neustart ? { $cmd .= "#info#cat /etc/board.info | grep board"; } @@ -777,7 +785,7 @@ sub UbiquitiMP_GetStatus($) } else { # das ging schief wiederholen nach doppelter timeout Wartezeit - Log3 $name, 5, "$name, BC process start failed !"; + Log3 $name, 3, "$name, BC process GetStatus start failed !"; InternalTimer(gettimeofday()+(int($hash->{".timeout"})*2), "UbiquitiMP_GetStatus",$hash, 0); } @@ -831,9 +839,9 @@ sub UbiquitiMP_summaryFn($$$$) { } } } else { $html .= $state }; - + $html .= ""; - return $html; + return $html; } ################################################################################ @@ -887,6 +895,12 @@ sub UbiquitiMP_createSets($)

UbiquitiMP