diff --git a/fhem/CHANGED b/fhem/CHANGED index aca34244e..cae664582 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # 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: 49_SSCam: V3.4.0, new commands startTracking, stopTracking for + PTZ-Cams with object tracking capability - added: 74_HOMBOT: add commandref summary, code design - change: 73_GardenaSmartBridge: change logging output for username and password diff --git a/fhem/FHEM/49_SSCam.pm b/fhem/FHEM/49_SSCam.pm index 158d140ba..926d4551d 100644 --- a/fhem/FHEM/49_SSCam.pm +++ b/fhem/FHEM/49_SSCam.pm @@ -27,6 +27,8 @@ ######################################################################################################################### # Versions History: # +# 3.4.0 21.03.2018 new commands startTracking, stopTracking +# 3.3.1 20.03.2018 new readings CapPTZObjTracking, CapPTZPresetNumber # 3.3.0 25.02.2018 code review, API bug fix of runview lastrec, commandref revised (forum:#84953) # 3.2.4 18.11.2017 fix bug don't retrieve SSCam_getptzlistpreset if cam is disabled # 3.2.3 08.10.2017 set optimizeParams, get caminfo (simple), minor bugfix, commandref revised @@ -207,7 +209,7 @@ use Time::HiRes; use HttpUtils; # no if $] >= 5.017011, warnings => 'experimental'; -my $SSCamVersion = "3.3.0"; +my $SSCamVersion = "3.4.0"; # Aufbau Errorcode-Hashes (siehe Surveillance Station Web API) my %SSCam_errauthlist = ( @@ -548,16 +550,19 @@ sub SSCam_Set($@) { "credentials ". "expmode:auto,day,night ". "on ". - "off ". + "off:noArg ". "motdetsc:disable,camera,SVS ". - "snap ". + "snap:noArg ". (AttrVal($name, "snapGalleryBoost",0)?(AttrVal($name,"snapGalleryNumber",undef) || AttrVal($name,"snapGalleryBoost",0))?"snapGallery:noArg ":"snapGallery:$SSCAM_snum ":" "). "createSnapGallery:noArg ". - "enable ". - "disable ". + "enable:noArg ". + "disable:noArg ". "optimizeParams ". "runView:live_fw,live_link,live_open,lastrec_fw,lastrec_open,lastsnap_fw ". "stopView:noArg ". + ((ReadingsVal("$name", "CapPTZObjTracking", "0") != 0) ? "startTracking:noArg " : ""). + ((ReadingsVal("$name", "CapPTZObjTracking", "0") != 0) ? "stopTracking:noArg " : ""). + ((ReadingsVal("$name", "CapPTZDirections", "0") > 0) ? "move"." " : ""). ((ReadingsVal("$name", "CapPTZPan", "false") ne "false") ? "runPatrol:".ReadingsVal("$name", "Patrols", "")." " : ""). ((ReadingsVal("$name", "CapPTZPan", "false") ne "false") ? "goPreset:".ReadingsVal("$name", "Presets", "")." " : ""). ((ReadingsVal("$name", "CapPTZAbs", "false") ne "false") ? "goAbsPTZ"." " : ""). @@ -587,6 +592,16 @@ sub SSCam_Set($@) { if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} SSCam_camsnap($hash); + } elsif ($opt eq "startTracking" && SSCam_IsModelCam($hash)) { + if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} + if ($hash->{HELPER}{APIPTZMAXVER} < 5) {return "Function \"$opt\" needs a higher version of Surveillance Station";} + SSCam_starttrack($hash); + + } elsif ($opt eq "stopTracking" && SSCam_IsModelCam($hash)) { + if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} + if ($hash->{HELPER}{APIPTZMAXVER} < 5) {return "Function \"$opt\" needs a higher version of Surveillance Station";} + SSCam_stoptrack($hash); + } elsif ($opt eq "snapGallery" && SSCam_IsModelCam($hash)) { if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} my $ret = SSCam_getclhash($hash); @@ -1471,6 +1486,106 @@ sub SSCam_camsnap($) { } } +############################################################################### +# Start Object Tracking +############################################################################### +sub SSCam_starttrack($) { + my ($hash) = @_; + my $camname = $hash->{CAMNAME}; + my $name = $hash->{NAME}; + my $errorcode; + my $error; + + RemoveInternalTimer($hash, "SSCam_starttrack"); + return if(IsDisabled($name)); + + if (ReadingsVal("$name", "state", "") =~ /^dis.*/) { + if (ReadingsVal("$name", "state", "") eq "disabled") { + $errorcode = "402"; + } elsif (ReadingsVal("$name", "state", "") eq "disconnected") { + $errorcode = "502"; + } + + # Fehlertext zum Errorcode ermitteln + $error = SSCam_experror($hash,$errorcode); + + # Setreading + readingsBeginUpdate($hash); + readingsBulkUpdate($hash,"Errorcode",$errorcode); + readingsBulkUpdate($hash,"Error",$error); + readingsEndUpdate($hash, 1); + + Log3($name, 2, "$name - ERROR - Object Tracking of Camera $camname can't switched on - $error"); + + return; + } + + if ($hash->{HELPER}{ACTIVE} eq "off") { + $hash->{OPMODE} = "startTrack"; + $hash->{HELPER}{ACTIVE} = "on"; + $hash->{HELPER}{LOGINRETRIES} = 0; + + if ($attr{$name}{debugactivetoken}) { + Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}"); + } + + SSCam_getapisites($hash); + + } else { + InternalTimer(gettimeofday()+0.9, "SSCam_starttrack", $hash, 0); + } +} + +############################################################################### +# Stopp Object Tracking +############################################################################### +sub SSCam_stoptrack($) { + my ($hash) = @_; + my $camname = $hash->{CAMNAME}; + my $name = $hash->{NAME}; + my $errorcode; + my $error; + + RemoveInternalTimer($hash, "SSCam_stoptrack"); + return if(IsDisabled($name)); + + if (ReadingsVal("$name", "state", "") =~ /^dis.*/) { + if (ReadingsVal("$name", "state", "") eq "disabled") { + $errorcode = "402"; + } elsif (ReadingsVal("$name", "state", "") eq "disconnected") { + $errorcode = "502"; + } + + # Fehlertext zum Errorcode ermitteln + $error = SSCam_experror($hash,$errorcode); + + # Setreading + readingsBeginUpdate($hash); + readingsBulkUpdate($hash,"Errorcode",$errorcode); + readingsBulkUpdate($hash,"Error",$error); + readingsEndUpdate($hash, 1); + + Log3($name, 2, "$name - ERROR - Object Tracking of Camera $camname can't switched off - $error"); + + return; + } + + if ($hash->{HELPER}{ACTIVE} eq "off") { + $hash->{OPMODE} = "stopTrack"; + $hash->{HELPER}{ACTIVE} = "on"; + $hash->{HELPER}{LOGINRETRIES} = 0; + + if ($attr{$name}{debugactivetoken}) { + Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}"); + } + + SSCam_getapisites($hash); + + } else { + InternalTimer(gettimeofday()+0.9, "SSCam_stoptrack", $hash, 0); + } +} + ############################################################################### # Kamera Liveview starten ############################################################################### @@ -2936,12 +3051,20 @@ sub SSCam_camop ($) { Log3($name, 4, "$name - Get filename of present Snap-ID $snapid"); $url = "http://$serveraddr:$serverport/webapi/$apitakesnappath?api=\"$apitakesnap\"&method=\"List\"&version=\"$apitakesnapmaxver\"&imgSize=\"0\"&idList=\"$snapid\"&_sid=\"$sid\""; - }elsif ($OpMode eq "gopreset") { + } elsif ($OpMode eq "gopreset") { # Preset wird angefahren $apiptzmaxver = ($apiptzmaxver >= 5)?4:$apiptzmaxver; $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"GoPreset\"&position=\"$hash->{HELPER}{ALLPRESETS}{$hash->{HELPER}{GOPRESETNAME}}\"&cameraId=\"$camid\"&_sid=\"$sid\""; readingsSingleUpdate($hash,"state", "moving", 0); + } elsif ($OpMode eq "startTrack") { + # Object Tracking einschalten + $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"ObjTracking\"&cameraId=\"$camid\"&_sid=\"$sid\""; + + } elsif ($OpMode eq "stopTrack") { + # Object Tracking stoppen + $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"ObjTracking\"&moveType=\"Stop\"&cameraId=\"$camid\"&_sid=\"$sid\""; + } elsif ($OpMode eq "runpatrol") { # eine Überwachungstour starten $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"RunPatrol\"&patrolId=\"$hash->{HELPER}{ALLPATROLS}{$hash->{HELPER}{GOPATROLNAME}}\"&cameraId=\"$camid\"&_sid=\"$sid\""; @@ -3604,6 +3727,40 @@ sub SSCam_camop_parse ($) { # Logausgabe Log3($name, 3, "$name - Camera $camname has been moved to absolute position \"posX=$hash->{HELPER}{GOPTZPOSX}\" and \"posY=$hash->{HELPER}{GOPTZPOSY}\""); + } elsif ($OpMode eq "startTrack") { + # Object Tracking wurde eingeschaltet + # falls Aufnahme noch läuft -> state = on setzen + if (ReadingsVal("$name", "Record", "Stop") eq "Start") { + readingsSingleUpdate($hash,"state", "on", 0); + } else { + readingsSingleUpdate($hash,"state", "off", 0); + } + + readingsBeginUpdate($hash); + readingsBulkUpdate($hash,"Errorcode","none"); + readingsBulkUpdate($hash,"Error","none"); + readingsEndUpdate($hash, 1); + + # Logausgabe + Log3($name, 3, "$name - Object tracking of Camera $camname has been switched on"); + + } elsif ($OpMode eq "stopTrack") { + # Object Tracking wurde eingeschaltet + # falls Aufnahme noch läuft -> state = on setzen + if (ReadingsVal("$name", "Record", "Stop") eq "Start") { + readingsSingleUpdate($hash,"state", "on", 0); + } else { + readingsSingleUpdate($hash,"state", "off", 0); + } + + readingsBeginUpdate($hash); + readingsBulkUpdate($hash,"Errorcode","none"); + readingsBulkUpdate($hash,"Error","none"); + readingsEndUpdate($hash, 1); + + # Logausgabe + Log3($name, 3, "$name - Object tracking of Camera $camname has been stopped"); + } elsif ($OpMode eq "movestart") { # ein "Move" in eine bestimmte Richtung wird durchgeführt @@ -4072,7 +4229,9 @@ sub SSCam_camop_parse ($) { readingsBulkUpdate($hash,"CapPTZDirections",$data->{'data'}{'ptzDirection'}); readingsBulkUpdate($hash,"CapPTZFocus",$ptzfocus); readingsBulkUpdate($hash,"CapPTZIris",$ptziris); + readingsBulkUpdate($hash,"CapPTZObjTracking",$data->{'data'}{'ptzHasObjTracking'}); readingsBulkUpdate($hash,"CapPTZPan",$ptzpan); + readingsBulkUpdate($hash,"CapPTZPresetNumber",$data->{'data'}{'ptzPresetNumber'}); readingsBulkUpdate($hash,"CapPTZTilt",$ptztilt); readingsBulkUpdate($hash,"CapPTZZoom",$ptzzoom); readingsBulkUpdate($hash,"Errorcode","none"); @@ -4750,9 +4909,10 @@ sub SSCam_experror {