From 72b6b678b15c6795e2309038e5fd69968bdc45e9 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Tue, 3 Apr 2018 21:28:13 +0000 Subject: [PATCH] 49_SSCam: V3.8.0, new setHome command, minor fixes git-svn-id: https://svn.fhem.de/fhem/trunk@16548 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/49_SSCam.pm | 146 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 130 insertions(+), 17 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index a6b5a821f..39f0cd7e5 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # 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.8.0, new setHome command, minor fixes - feature: 72_XiaomiDevice: added zone and goto - bugfix: 57_Calendar: fix weekly events, get full all, defaultTimeFormat - change: 93_DbLog: V3.10.0, addLog considers DbLogExclude in Devices, diff --git a/fhem/FHEM/49_SSCam.pm b/fhem/FHEM/49_SSCam.pm index 40f8f7470..6161a1566 100644 --- a/fhem/FHEM/49_SSCam.pm +++ b/fhem/FHEM/49_SSCam.pm @@ -27,6 +27,7 @@ ######################################################################################################################### # Versions History: # +# 3.8.0 03.04.2018 new reading PresetHome, setHome command, minor fixes # 3.7.0 26.03.2018 minor details of setPreset changed, new command delPreset # 3.6.0 25.03.2018 setPreset command, changed SSCam_wdpollcaminfo, SSCam_getcaminfoall # 3.5.0 22.03.2018 new get command listPresets @@ -212,7 +213,7 @@ use Time::HiRes; use HttpUtils; # no if $] >= 5.017011, warnings => 'experimental'; -my $SSCamVersion = "3.7.0"; +my $SSCamVersion = "3.8.0"; # Aufbau Errorcode-Hashes (siehe Surveillance Station Web API) my %SSCam_errauthlist = ( @@ -568,9 +569,10 @@ sub SSCam_Set($@) { "optimizeParams ". "runView:live_fw,live_link,live_open,lastrec_fw,lastrec_open,lastsnap_fw ". ((ReadingsVal("$name", "CapPTZPan", "false") ne "false") ? "setPreset ": ""). + ((ReadingsVal("$name", "CapPTZPan", "false") ne "false") ? "setHome:---currentPosition---,".ReadingsVal("$name","Presets","")." " : ""). "stopView:noArg ". - ((ReadingsVal("$name", "CapPTZObjTracking", 0) != 0) ? "startTracking:noArg " : ""). - ((ReadingsVal("$name", "CapPTZObjTracking", 0) != 0) ? "stopTracking:noArg " : ""). + ((ReadingsVal("$name", "CapPTZObjTracking", "false") ne "false") ? "startTracking:noArg " : ""). + ((ReadingsVal("$name", "CapPTZObjTracking", "false") ne "false") ? "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", "")." " : ""). @@ -861,6 +863,12 @@ sub SSCam_Set($@) { $hash->{HELPER}{PSPEED} = $prop2 if($prop2); SSCam_setPreset($hash); + } elsif ($opt eq "setHome" && 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 (!$prop) {return "Function \"$opt\" needs a \"Presetname\" as argument";} + $hash->{HELPER}{SETHOME} = $prop; + SSCam_setHome($hash); + } elsif ($opt eq "delPreset" && 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 (!$prop) {return "Function \"$opt\" needs a \"Presetname\" as argument";} @@ -1774,6 +1782,55 @@ sub SSCam_delPreset($) { } } +############################################################################### +# Preset Home setzen +############################################################################### +sub SSCam_setHome($) { + my ($hash) = @_; + my $camname = $hash->{CAMNAME}; + my $name = $hash->{NAME}; + my $errorcode; + my $error; + + RemoveInternalTimer($hash, "SSCam_setHome"); + 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); + + readingsBeginUpdate($hash); + readingsBulkUpdate($hash,"Errorcode",$errorcode); + readingsBulkUpdate($hash,"Error",$error); + readingsEndUpdate($hash, 1); + + Log3($name, 2, "$name - ERROR - Home preset of Camera $camname can't be set - $error"); + + return; + } + + if ($hash->{HELPER}{ACTIVE} eq "off") { + $hash->{OPMODE} = "setHome"; + $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()+1.2, "SSCam_setHome", $hash, 0); + } +} + ############################################################################### # Kamera Liveview starten ############################################################################### @@ -3279,6 +3336,15 @@ sub SSCam_camop ($) { # einen Preset löschen $url = "http://$serveraddr:$serverport/webapi/$apipresetpath?api=\"$apipreset\"&version=\"$apipresetmaxver\"&method=\"DelPreset\"&position=\"$hash->{HELPER}{ALLPRESETS}{$hash->{HELPER}{DELPRESETNAME}}\"&cameraId=\"$camid\"&_sid=\"$sid\""; + } elsif ($OpMode eq "setHome") { + # aktuelle Position als Home setzen + if($hash->{HELPER}{SETHOME} eq "---currentPosition---") { + $url = "http://$serveraddr:$serverport/webapi/$apipresetpath?api=\"$apipreset\"&version=\"$apipresetmaxver\"&method=\"SetHome\"&cameraId=\"$camid\"&_sid=\"$sid\""; + } else { + my $bindpos = $hash->{HELPER}{ALLPRESETS}{$hash->{HELPER}{SETHOME}}; + $url = "http://$serveraddr:$serverport/webapi/$apipresetpath?api=\"$apipreset\"&version=\"$apipresetmaxver\"&method=\"SetHome\"&bindPosition=\"$bindpos\"&cameraId=\"$camid\"&_sid=\"$sid\""; + } + } elsif ($OpMode eq "startTrack") { # Object Tracking einschalten $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"ObjTracking\"&cameraId=\"$camid\"&_sid=\"$sid\""; @@ -3779,6 +3845,16 @@ sub SSCam_camop_parse ($) { my $dp = $hash->{HELPER}{DELPRESETNAME}; Log3($name, 3, "$name - Preset \"$dp\" of camera \"$camname\" was deleted successfully"); + SSCam_getptzlistpreset($hash); + + } elsif ($OpMode eq "setHome") { + readingsBeginUpdate($hash); + readingsBulkUpdate($hash,"Errorcode","none"); + readingsBulkUpdate($hash,"Error","none"); + readingsEndUpdate($hash, 1); + + my $sh = $hash->{HELPER}{SETHOME}; + Log3($name, 3, "$name - Preset \"$sh\" of camera \"$camname\" was set as Home position"); SSCam_getptzlistpreset($hash); } elsif ($OpMode eq "setoptpar") { @@ -4475,6 +4551,13 @@ sub SSCam_camop_parse ($) { $ptziris = "support continuous operation"; } + my $pot; + if($data->{'data'}{'ptzHasObjTracking'} == 1 || $data->{'data'}{'ptzHasObjTracking'} eq "true") { + $pot = "true"; + } else { + $pot = "false"; + } + # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"CapPTZAutoFocus",$data->{'data'}{'ptzAutoFocus'}); @@ -4485,7 +4568,7 @@ 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,"CapPTZObjTracking",$pot); readingsBulkUpdate($hash,"CapPTZPan",$ptzpan); readingsBulkUpdate($hash,"CapPTZPresetNumber",$data->{'data'}{'ptzPresetNumber'}); readingsBulkUpdate($hash,"CapPTZTilt",$ptztilt); @@ -4505,11 +4588,16 @@ sub SSCam_camop_parse ($) { # alle Presets der Kamera mit Id's in Assoziatives Array einlesen # "my" nicht am Anfang deklarieren, sonst wird Hash %allpresets wieder geleert ! my %allpresets; + my $home = "not set"; while ($cnt < $presetcnt) { # my $presid = $data->{'data'}->{'presets'}->[$cnt]->{'id'}; - my $presid = $data->{'data'}->{'presets'}->[$cnt]->{'position'}; + my $presid = $data->{'data'}->{'presets'}->[$cnt]->{'position'}; my $presname = $data->{'data'}->{'presets'}->[$cnt]->{'name'}; $allpresets{$presname} = "$presid"; + my $ptype = $data->{'data'}->{'presets'}->[$cnt]->{'type'}; + if ($ptype) { + $home = $presname; + } $cnt += 1; } @@ -4522,6 +4610,7 @@ sub SSCam_camop_parse ($) { # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Presets",$presetlist); + readingsBulkUpdate($hash,"PresetHome",$home); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); @@ -5166,7 +5255,8 @@ sub SSCam_experror {
  • show the stored credentials of a device
  • fetch the Surveillance Station Logs, exploit the newest entry as reading
  • Start/Stop Object Tracking (only supported PTZ-Cams with this capability)
  • -
  • Set/Delete a Preset (at PTZ-cameras)
  • +
  • set/delete a Preset (at PTZ-cameras)
  • +
  • set a Preset or current position as Home Preset (at PTZ-cameras)

  • @@ -5308,7 +5398,8 @@ sub SSCam_experror {
  • set ... goAbsPTZ session: ServeillanceStation - observer with privilege objective control of camera
  • set ... move session: ServeillanceStation - observer with privilege objective control of camera
  • set ... runView session: ServeillanceStation - observer with privilege liveview of camera
  • -
  • set ... setPreset session: ServeillanceStation - observer
  • +
  • set ... setHome session: ServeillanceStation - observer
  • +
  • set ... setPreset session: ServeillanceStation - observer
  • set ... snap session: ServeillanceStation - observer
  • set ... snapGallery session: ServeillanceStation - observer
  • set ... stopView -
  • @@ -5696,7 +5787,15 @@ sub SSCam_experror {

    +

    + +

    @@ -5760,8 +5859,8 @@ sub SSCam_experror {
  • set <name> stopTracking     (valid for CAM with tracking capability)

  • Stops object tracking of camera. - The command is only available if surveillance station has recognise the object tracking capability of camera - (Reading "CapPTZObjTracking != 0"). + The command is only available if surveillance station has recognised the object tracking capability of camera + (Reading "CapPTZObjTracking").

    @@ -6170,6 +6269,7 @@ http(s)://<hostname><port>/webapi/entry.cgi?api=SYNO.SurveillanceSta
  • LiveStreamUrl
  • - the livestream URL if stream is started (is shown if attribute "showStmInfoFull" is set)
  • Patrols
  • - in Synology Surveillance Station predefined patrols (at PTZ-Cameras)
  • PollState
  • - shows the state of automatic polling +
  • PresetHome
  • - Name of Home-position (at PTZ-Cameras)
  • Presets
  • - in Synology Surveillance Station predefined Presets (at PTZ-Cameras)
  • Record
  • - if recording is running = Start, if no recording is running = Stop
  • StmKey
  • - current streamkey. it can be used to open livestreams without session id @@ -6224,6 +6324,7 @@ http(s)://<hostname><port>/webapi/entry.cgi?api=SYNO.SurveillanceSta
  • erzeugen einer Gallerie der letzten 1-10 Schnappschüsse (als Popup oder permanentes Device)
  • Start bzw. Stop Objekt Tracking (nur unterstützte PTZ-Kameras mit dieser Fähigkeit)
  • Setzen/Löschen eines Presets (bei PTZ-Kameras)
  • +
  • Setzen der Home-Position (bei PTZ-Kameras)

  • @@ -6366,7 +6467,8 @@ http(s)://<hostname><port>/webapi/entry.cgi?api=SYNO.SurveillanceSta
  • set ... off session: ServeillanceStation - Betrachter mit erweiterten Privileg "manuelle Aufnahme"
  • set ... runView session: ServeillanceStation - Betrachter mit Privileg Liveansicht für Kamera
  • set ... runPatrol session: ServeillanceStation - Betrachter mit Privileg Objektivsteuerung der Kamera
  • -
  • set ... setPreset session: ServeillanceStation - Betrachter
  • +
  • set ... setHome session: ServeillanceStation - Betrachter
  • +
  • set ... setPreset session: ServeillanceStation - Betrachter
  • set ... snap session: ServeillanceStation - Betrachter
  • set ... snapGallery session: ServeillanceStation - Betrachter
  • set ... stopView -
  • @@ -6755,7 +6857,16 @@ http(s)://<hostname><port>/webapi/entry.cgi?api=SYNO.SurveillanceSta

    +

    + +

    @@ -6818,7 +6929,7 @@ http(s)://<hostname><port>/webapi/entry.cgi?api=SYNO.SurveillanceSta Stoppt Objekt Tracking der Kamera. Der Befehl ist nur vorhanden wenn die Surveillance Station die Fähigkeit der Kamera zum Objekt Tracking erkannt hat - (Reading "CapPTZObjTracking != 0"). + (Reading "CapPTZObjTracking").

    @@ -7243,7 +7354,8 @@ http(s)://<hostname><port>/webapi/entry.cgi?api=SYNO.SurveillanceSta
  • LastUpdateTime
  • - Datum / Zeit der letzten Aktualisierung durch "caminfoall"
  • LiveStreamUrl
  • - die LiveStream-Url wenn der Stream gestartet ist. (Attribut "showStmInfoFull" muss gesetzt sein)
  • Patrols
  • - in Surveillance Station voreingestellte Überwachungstouren (bei PTZ-Kameras) -
  • PollState
  • - zeigt den Status des automatischen Pollings an +
  • PollState
  • - zeigt den Status des automatischen Pollings an +
  • PresetHome
  • - Name der Home-Position (bei PTZ-Kameras)
  • Presets
  • - in Surveillance Station voreingestellte Positionen (bei PTZ-Kameras)
  • Record
  • - Aufnahme läuft = Start, keine Aufnahme = Stop
  • StmKey
  • - aktueller StreamKey. Kann zum öffnen eines Livestreams ohne Session Id genutzt werden.