######################################################################################################################### # $Id$ ######################################################################################################################### # 49_SSCam.pm # # (c) 2015-2017 by Heiko Maaz # e-mail: Heiko dot Maaz at t-online dot de # # This Module can be used to operate Cameras defined in Synology Surveillance Station 7.0 or higher. # It's based on and it's using Synology Surveillance Station API # # This script is part of fhem. # # Fhem is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # Fhem is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with fhem. If not, see .# # ######################################################################################################################### # Versions History: # # 2.2.1 15.05.2017 avoid FW_detailFn because of FW_deviceOverview is active (double streams in detailview if on) # 2.2.0 10.05.2017 check if JSON module has been loaded successfully, DeviceOverview available, options of # runView changed image->live_fw, link->live_link, link_open->live_open, lastrec ->lastrec_fw, # commandref revised # 2.1.4 08.05.2017 commandref changed # 2.1.3 05.05.2017 issue of operation error if CAMID is set and SID isn't valid, more login-errorcodes evaluation # 2.1.2 04.05.2017 default login retries increased to 3 # 2.1.1 17.04.2017 runliveview routine changed, {HELPER}{SID_STRM} deleted # 2.1.0 12.04.2017 some codereview, getapisites cached, CAMID cached, rewrite logs from verbose 4 to 5, # get scanVirgin, commandref replenished # 2.0.0 10.04.2017 redesign login procedure, fix Reading SVSversion use SMALL version, new attr loginRetries # 1.42 15.03.2017 sscam_camop changed to get all cam id's and names # 1.41 15.03.2017 minor bugfix of blank character in state "disabled" (row 3383) # 1.40 21.01.2017 downgrade of API apicammaxver in SVS 8.0.0 # 1.39 20.01.2017 compatibility to SVS 8.0.0, Version in Internals, execute getsvsinfo after set credentials # 1.37 10.10.2016 bugfix Experimental keys on scalar is now forbidden (Perl >= 5.23) # (Forum: #msg501709) # 1.36 18.09.2016 bugfix of get presets, get patrols of zoom-cams without pan/tilt # 1.35 17.09.2016 internal timer of start-routines optimized # 1.34 15.09.2016 simu_SVSversion changed, added 407 errorcode message, external recording changed # for SVS 7.2 # 1.33 21.08.2016 function get stmUrlPath added, fit to new commandref style, attribute showStmInfoFull added # 1.32.1 18.08.2016 empty event LastSnapId fixed # 1.32 17.08.2016 Logging of verbose 4 changed # 1.31 15.08.2016 Attr "noQuotesForSID" added, avoid possible 402 - permission denied problems # in some SVS/DS-combinations # 1.30 15.08.2016 commandref revised, more v4 logging in special case # 1.29 02.07.2016 add regex for adaption SVS version, url call for "snap" changed # 1.28 30.06.2016 Attr "showPassInLog" added, per default no password will be shown in log # 1.27 29.06.2016 Attr "simu_SVSversion" added, sub login_nonbl changed, # sub camret_nonbl changed (getlistptzpreset) due to 7.2 problem # 1.26.3 28.06.2016 Time::HiRes added # 1.26.2 05.05.2016 change: get "snapfileinfo" will get back an Infomessage if Reading "LastSnapId" # isn't available # 1.26.1 27.04.2016 bugfix module will not load due to Unknown warnings category 'experimental' # when using an older perl version # 1.26 22.04.2016 Attribute "disable" to deactivate the module added # 1.25 18.04.2016 motion detection parameters can be entered if # motion detection by camera or SVS is used # 1.24 16.04.2016 behavior of "set ... on" changed, Attr "recextend" added # please have a look at commandref and Wiki # bugfix: setstate-warning if FHEM will restarted and SVS is not reachable # (Forum: #308) # 1.23.2 12.04.2016 code review, no functional changes # 1.23.1 07.04.2016 command check for set cmd's don't work completely # 1.23 02.04.2016 change to RemoveInternalTimer for functions # 1.22 27.03.2016 bugfix "link_open" doesn't work after last update # 1.21 23.03.2016 added "lastrec"," lastrec_open" to playback last recording # 1.20.3 19.03.2016 change: delay of InternalTimer(s) changed # "ptzlistpresets" - "id" changed to "position" according to Synology-ticket # run "geteventlist" automatically after recording-stop # 1.20.2 14.03.2016 change: routine "initonboot" changed # 1.20.1 12.03.2016 bugfix: default recordtime 15 s is used if attribute "rectime" is set to "0" # 1.20 09.03.2016 command "extevent" added # 1.19.3 07.03.2016 bugfix "uninitialized value $lastrecstarttime", # "uninitialized value $lastrecstoptime", # new attribute "videofolderMap" # 1.19.2 06.03.2016 Reading "CamLastRec" added which contains Path/name # of last recording # 1.19.1 28.02.2016 enhanced command runView by option "link_open" to # open a streamlink immediately # 1.19 25.02.2016 functions for cam-livestream added # 1.18.1 21.02.2016 fixed a problem that the state is "disable" instead of # "disabled" if a camera is disabled and FHEM will be restarted # 1.18 20.02.2016 function "get ... eventlist" added, # Reading "CamEventNum" added which containes total number of # camera events, # change usage of reading "LastUpdateTime" # 1.17 19.02.2016 function "runPatrol" added that starts predefined patrols # of PTZ-cameras, # Reading "CamDetMotSc" added # 1.16.1 17.02.2016 Reading "CamExposureControl" added # 1.16 16.02.2016 set up of motion detection source now possible # 1.15 15.02.2016 control of exposure mode day, night & auto is possible now # 1.14 14.02.2016 The port in DEF-String is optional now, # if not given, default port 5000 is used # 1.13.2 13.02.2016 fixed a problem that manual updates using "getcaminfoall" are # leading to additional pollingloops if polling is used, # attribute "debugactivetoken" added for debugging-use # 1.13.1 12.02.2016 fixed a problem that a usersession won't be destroyed if a # function couldn't be executed successfully # 1.13 feature for retrieval snapfilename added # 1.12.1 09.02.2016 bugfix: "goAbsPTZ" may be unavailable on Windows-systems # 1.12 08.02.2016 added function "move" for continuous PTZ action # 1.11.1 07.02.2016 entries with loglevel "2" reviewed, changed to loglevel "3" # 1.11 05.02.2016 added function "goPreset" and "goAbsPTZ" to control the move of PTZ lense # to absolute positions # refere to commandref or have a look in forum at: # http://forum.fhem.de/index.php/topic,45671.msg404275.html#msg404275 , # http://forum.fhem.de/index.php/topic,45671.msg404892.html#msg404892 # 1.10 02.02.2016 added function "svsinfo" to get informations about installed SVS-package, # if Availability = " disconnected" then "state"-value will be "disconnected" too, # saved Credentials were deleted from file if a device will be deleted # 1.9.1 31.01.2016 a little bit code optimization # 1.9 28.01.2016 fixed the problem a recording may still stay active if fhem # will be restarted after a recording was triggered and # the recordingtime wasn't be over, # Enhancement of readings. # 1.8 25.01.2016 changed define in order to remove credentials from string, # added "set credentials" command to save username/password, # added Attribute "session" to make login-session selectable, # Note: You have to adapt your define-strings !! # Refere to commandref or look in forum at: # http://forum.fhem.de/index.php/topic,45671.msg397449.html#msg397449 # 1.7 18.01.2016 Attribute "httptimeout" added # 1.6 16.01.2016 Change the define-string related to rectime. # Note: See all changes to rectime usage in commandref or here: # http://forum.fhem.de/index.php/topic,45671.msg391664.html#msg391664 # 1.5.1 11.01.2016 Vars "USERNAME" and "RECTIME" removed from internals, # Var (Internals) "SERVERNAME" changed to "SERVERADDR", # minor change of Log messages, # Note: use rereadcfg in order to activate the changes # 1.5 04.01.2016 Function "Get" for creating Camera-Readings integrated, # Attributs pollcaminfoall, pollnologging added, # Function for Polling Cam-Infos added. # 1.4 23.12.2015 function "enable" and "disable" for SS-Cams added, # changed timout of Http-calls to a higher value # 1.3 19.12.2015 function "snap" for taking snapshots added, # fixed a bug that functions may impact each other # 1.2 14.12.2015 improve usage of verbose-modes # 1.1 13.12.2015 use of InternalTimer instead of fhem(sleep) # 1.0 12.12.2015 changed completly to HttpUtils_NonblockingGet for calling websites nonblocking, # LWP is not needed anymore # # # Definition: define SSCam [ServerPort] # # Example: define CamCP1 SSCAM Carport 192.168.2.20 [5000] # package main; eval "use JSON qw( decode_json );1" or my $SScamMMDBI = "JSON"; # Debian: apt-get install libjson-perl use Data::Dumper; # Perl Core module use strict; use warnings; use MIME::Base64; use Time::HiRes; use HttpUtils; # no if $] >= 5.017011, warnings => 'experimental'; my $SSCamVersion = "2.2.1"; # Aufbau Errorcode-Hashes (siehe Surveillance Station Web API) my %SSCam_errauthlist = ( 100 => "Unknown error", 101 => "The account parameter is not specified", 102 => "API does not exist", 400 => "Invalid user or password", 401 => "Guest or disabled account", 402 => "Permission denied - DSM-Session: make sure user is member of Admin-group, SVS-Session: make sure SVS package is started, make sure FHEM-Server IP won't be blocked in DSM automated blocking list", 403 => "One time password not specified", 404 => "One time password authenticate failed", 407 => "Permission denied - make sure FHEM-Server IP won't be blocked in DSM automated blocking list", ); my %SSCam_errlist = ( 100 => "Unknown error", 101 => "Invalid parameters", 102 => "API does not exist", 103 => "Method does not exist", 104 => "This API version is not supported", 105 => "Insufficient user privilege", 106 => "Connection time out", 107 => "Multiple login detected", 117 => "need manager rights in SurveillanceStation for operation", 400 => "Execution failed", 401 => "Parameter invalid", 402 => "Camera disabled", 403 => "Insufficient license", 404 => "Codec activation failed", 405 => "CMS server connection failed", 407 => "CMS closed", 410 => "Service is not enabled", 412 => "Need to add license", 413 => "Reach the maximum of platform", 414 => "Some events not exist", 415 => "message connect failed", 417 => "Test Connection Error", 418 => "Object is not exist", 419 => "Visualstation name repetition", 439 => "Too many items selected", 502 => "Camera disconnected", 600 => "Presetname and PresetID not found in Hash", ); sub SSCam_Initialize($) { my ($hash) = @_; $hash->{DefFn} = "SSCam_Define"; $hash->{UndefFn} = "SSCam_Undef"; $hash->{DeleteFn} = "SSCam_Delete"; $hash->{SetFn} = "SSCam_Set"; $hash->{GetFn} = "SSCam_Get"; $hash->{AttrFn} = "SSCam_Attr"; # Aufrufe aus FHEMWEB $hash->{FW_summaryFn} = "SSCam_FWview"; # $hash->{FW_detailFn} = "SSCam_FWview"; $hash->{FW_deviceOverview} = 1; $hash->{AttrList} = "disable:1,0 ". "httptimeout ". "htmlattr ". "livestreamprefix ". "loginRetries:1,2,3,4,5,6,7,8,9,10 ". "videofolderMap ". "pollcaminfoall ". "pollnologging:1,0 ". "debugactivetoken:1 ". "rectime ". "recextend:1,0 ". "noQuotesForSID:1,0 ". "session:SurveillanceStation,DSM ". "showPassInLog:1,0 ". "showStmInfoFull:1,0 ". "simu_SVSversion:7.2-xxxx,7.1-xxxx ". "webCmd ". $readingFnAttributes; return undef; } sub SSCam_Define { # Die Define-Funktion eines Moduls wird von Fhem aufgerufen wenn der Define-Befehl für ein Gerät ausgeführt wird # Welche und wie viele Parameter akzeptiert werden ist Sache dieser Funktion. Die Werte werden nach dem übergebenen Hash in ein Array aufgeteilt # define CamCP1 SSCAM Carport 192.168.2.20 [5000] # ($hash) [1] [2] [3] [4] # my ($hash, $def) = @_; my $name = $hash->{NAME}; return "Error: Perl module ".$SScamMMDBI." is missing. Install it on Debian with: sudo apt-get install libjson-perl" if($SScamMMDBI); my @a = split("[ \t][ \t]*", $def); if(int(@a) < 4) { return "You need to specify more parameters.\n". "Format: define SSCAM [Port]"; } my $camname = $a[2]; my $serveraddr = $a[3]; my $serverport = $a[4] ? $a[4] : 5000; $hash->{SERVERADDR} = $serveraddr; $hash->{SERVERPORT} = $serverport; $hash->{CAMNAME} = $camname; $hash->{VERSION} = $SSCamVersion; # benötigte API's in $hash einfügen $hash->{HELPER}{APIINFO} = "SYNO.API.Info"; # Info-Seite für alle API's, einzige statische Seite ! $hash->{HELPER}{APIAUTH} = "SYNO.API.Auth"; $hash->{HELPER}{APISVSINFO} = "SYNO.SurveillanceStation.Info"; $hash->{HELPER}{APIEVENT} = "SYNO.SurveillanceStation.Event"; $hash->{HELPER}{APIEXTREC} = "SYNO.SurveillanceStation.ExternalRecording"; $hash->{HELPER}{APIEXTEVT} = "SYNO.SurveillanceStation.ExternalEvent"; $hash->{HELPER}{APICAM} = "SYNO.SurveillanceStation.Camera"; $hash->{HELPER}{APISNAPSHOT} = "SYNO.SurveillanceStation.SnapShot"; $hash->{HELPER}{APIPTZ} = "SYNO.SurveillanceStation.PTZ"; $hash->{HELPER}{APICAMEVENT} = "SYNO.SurveillanceStation.Camera.Event"; $hash->{HELPER}{APIVIDEOSTM} = "SYNO.SurveillanceStation.VideoStreaming"; $hash->{HELPER}{APISTM} = "SYNO.SurveillanceStation.Streaming"; # Startwerte setzen $attr{$name}{webCmd} = "on:off:snap:enable:disable"; # initiale Webkommandos setzen $hash->{HELPER}{ACTIVE} = "off"; # Funktionstoken "off", Funktionen können sofort starten $hash->{HELPER}{OLDVALPOLLNOLOGGING} = "0"; # Loggingfunktion für Polling ist an $hash->{HELPER}{RECTIME_DEF} = "15"; # Standard für rectime setzen, überschreibbar durch Attribut "rectime" bzw. beim "set .. on-for-time" readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Availability", "???"); # Verfügbarkeit ist unbekannt readingsBulkUpdate($hash,"PollState","Inactive"); # es ist keine Gerätepolling aktiv readingsBulkUpdate($hash,"state", "off"); # Init für "state" , Problemlösung für setstate, Forum #308 readingsEndUpdate($hash,1); getcredentials($hash,1); # Credentials lesen und in RAM laden ($boot=1) # initiale Routinen nach Restart ausführen , verzögerter zufälliger Start RemoveInternalTimer($hash, "initonboot"); InternalTimer(gettimeofday()+int(rand(30)), "initonboot", $hash, 0); return undef; } ################################################################ sub SSCam_Undef { my ($hash, $arg) = @_; logout_nonbl($hash); RemoveInternalTimer($hash); return undef; } ################################################################ sub SSCam_Delete { my ($hash, $arg) = @_; my $index = $hash->{TYPE}."_".$hash->{NAME}."_credentials"; # gespeicherte Credentials löschen setKeyValue($index, undef); return undef; } ################################################################ sub SSCam_Attr { my ($cmd,$name,$aName,$aVal) = @_; my $hash = $defs{$name}; my $do; # $cmd can be "del" or "set" # $name is device name # aName and aVal are Attribute name and value if ($aName eq "disable") { if($cmd eq "set") { $do = ($aVal) ? 1 : 0; } $do = 0 if($cmd eq "del"); my $val = ($do == 1 ? "inactive" : "off"); readingsSingleUpdate($hash, "state", $val, 1); readingsSingleUpdate($hash, "PollState", "Inactive", 1) if($do == 1); readingsSingleUpdate($hash, "Availability", "???", 1) if($do == 1); } if ($aName eq "showStmInfoFull") { if($cmd eq "set") { $do = ($aVal) ? 1 : 0; } $do = 0 if($cmd eq "del"); if ($do == 0) { delete($defs{$name}{READINGS}{StmKeymjpegHttp}) if ($defs{$name}{READINGS}{StmKeymjpegHttp}); delete($defs{$name}{READINGS}{StmKeyUnicst}) if ($defs{$name}{READINGS}{StmKeyUnicst}); delete($defs{$name}{READINGS}{LiveStreamUrl}) if ($defs{$name}{READINGS}{LiveStreamUrl}); } } if ($aName eq "simu_SVSversion") { delete $hash->{HELPER}{APIPARSET}; getsvsinfo($hash); } if ($cmd eq "set") { if ($aName eq "pollcaminfoall") { unless ($aVal =~ /^\d+$/) { return " The Value for $aName is not valid. Use only figures 0-9 without decimal places !";} } if ($aName eq "rectime") { unless ($aVal =~ /^\d+$/) { return " The Value for $aName is not valid. Use only figures 0-9 without decimal places !";} } if ($aName eq "httptimeout") { unless ($aVal =~ /^[0-9]+$/) { return " The Value for $aName is not valid. Use only figures 1-9 !";} } } return undef; } ################################################################ sub SSCam_Set { my ($hash, @a) = @_; return "\"set X\" needs at least an argument" if ( @a < 2 ); my $name = $a[0]; my $opt = $a[1]; my $prop = $a[2]; my $prop1 = $a[3]; my $prop2 = $a[4]; my $prop3 = $a[5]; my $camname = $hash->{CAMNAME}; my $success; my $setlist; my @prop; $setlist = "Unknown argument $opt, choose one of ". "credentials ". "expmode:auto,day,night ". "on ". "off ". "motdetsc:disable,camera,SVS ". "snap ". "enable ". "disable ". "runView:live_fw,live_link,live_open,lastrec_fw,lastrec_open ". "stopView:noArg ". "extevent:1,2,3,4,5,6,7,8,9,10 ". ((ReadingsVal("$name", "CapPTZPan", "false") ne "false") ? "runPatrol:".ReadingsVal("$name", "Patrols", "")." " : ""). ((ReadingsVal("$name", "CapPTZPan", "false") ne "false") ? "goPreset:".ReadingsVal("$name", "Presets", "")." " : ""). ((ReadingsVal("$name", "CapPTZAbs", "false")) ? "goAbsPTZ"." " : ""). ((ReadingsVal("$name", "CapPTZDirections", "0") > 0) ? "move"." " : ""); if ($opt eq "on") { return "module is deactivated" if(IsDisabled($name)); if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} if (defined($prop)) { unless ($prop =~ /^\d+$/) { return " The Value for \"$opt\" is not valid. Use only figures 0-9 without decimal places !";} $hash->{HELPER}{RECTIME_TEMP} = $prop; } camstartrec($hash); } elsif ($opt eq "off") { return "module is deactivated" if(IsDisabled($name)); if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} camstoprec($hash); } elsif ($opt eq "snap") { return "module is deactivated" if(IsDisabled($name)); if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} camsnap($hash); } elsif ($opt eq "enable") { return "module is deactivated" if(IsDisabled($name)); if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} camenable($hash); } elsif ($opt eq "disable") { return "module is deactivated" if(IsDisabled($name)); if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} camdisable($hash); } elsif ($opt eq "motdetsc") { return "module is deactivated" if(IsDisabled($name)); if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} if (!$prop || $prop !~ /^(disable|camera|SVS)$/) { return " \"$opt\" needs one of those arguments: disable, camera, SVS !";} $hash->{HELPER}{MOTDETSC} = $prop; if ($prop1) { # check ob Zahl zwischen 1 und 99 return "invalid value for sensitivity (SVS or camera) - use number between 1 - 99" if ($prop1 !~ /^([1-9]|[1-9][0-9])*$/); $hash->{HELPER}{MOTDETSC_PROP1} = $prop1; } if ($prop2) { # check ob Zahl zwischen 1 und 99 return "invalid value for threshold (SVS) / object size (camera) - use number between 1 - 99" if ($prop2 !~ /^([1-9]|[1-9][0-9])*$/); $hash->{HELPER}{MOTDETSC_PROP2} = $prop2; } if ($prop3) { # check ob Zahl zwischen 1 und 99 return "invalid value for threshold (SVS) / object size (camera) - use number between 1 - 99" if ($prop3 !~ /^([1-9]|[1-9][0-9])*$/); $hash->{HELPER}{MOTDETSC_PROP3} = $prop3; } cammotdetsc($hash); } elsif ($opt eq "credentials") { return "module is deactivated" if(IsDisabled($name)); return "Credentials are incomplete, use username password" if (!$prop || !$prop1); delete $hash->{HELPER}{SID} if($hash->{HELPER}{SID}); ($success) = setcredentials($hash,$prop,$prop1); $hash->{HELPER}{ACTIVE} = "off"; if($success) { getsvsinfo($hash); return "Username and Password saved successfully"; } else { return "Error while saving Username / Password - see logfile for details"; } } elsif ($opt eq "expmode") { return "module is deactivated" if(IsDisabled($name)); if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} unless ($prop) { return " \"$opt\" needs one of those arguments: auto, day, night !";} $hash->{HELPER}{EXPMODE} = $prop; camexpmode($hash); } elsif ($opt eq "goPreset") { return "module is deactivated" if(IsDisabled($name)); 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 \"goPreset\" needs a \"Presetname\" as an argument";} @prop = split(/;/, $prop); $prop = $prop[0]; @prop = split(/,/, $prop); $prop = $prop[0]; $hash->{HELPER}{GOPRESETNAME} = $prop; $hash->{HELPER}{PTZACTION} = "gopreset"; doptzaction($hash); } elsif ($opt eq "runPatrol") { return "module is deactivated" if(IsDisabled($name)); 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 \"runPatrol\" needs a \"Patrolname\" as an argument";} @prop = split(/;/, $prop); $prop = $prop[0]; @prop = split(/,/, $prop); $prop = $prop[0]; $hash->{HELPER}{GOPATROLNAME} = $prop; $hash->{HELPER}{PTZACTION} = "runpatrol"; doptzaction($hash); } elsif ($opt eq "goAbsPTZ") { return "module is deactivated" if(IsDisabled($name)); if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} if ($prop eq "up" || $prop eq "down" || $prop eq "left" || $prop eq "right") { if ($prop eq "up") {$hash->{HELPER}{GOPTZPOSX} = 320; $hash->{HELPER}{GOPTZPOSY} = 480;} if ($prop eq "down") {$hash->{HELPER}{GOPTZPOSX} = 320; $hash->{HELPER}{GOPTZPOSY} = 0;} if ($prop eq "left") {$hash->{HELPER}{GOPTZPOSX} = 0; $hash->{HELPER}{GOPTZPOSY} = 240;} if ($prop eq "right") {$hash->{HELPER}{GOPTZPOSX} = 640; $hash->{HELPER}{GOPTZPOSY} = 240;} $hash->{HELPER}{PTZACTION} = "goabsptz"; doptzaction($hash); return undef; } else { if ($prop !~ /\d+/ || $prop1 !~ /\d+/ || abs($prop) > 640 || abs($prop1) > 480) { return "Function \"goAbsPTZ\" needs two coordinates, posX=0-640 and posY=0-480, as arguments or use up, down, left, right instead"; } $hash->{HELPER}{GOPTZPOSX} = abs($prop); $hash->{HELPER}{GOPTZPOSY} = abs($prop1); $hash->{HELPER}{PTZACTION} = "goabsptz"; doptzaction($hash); return undef; } return "Function \"goAbsPTZ\" needs two coordinates, posX=0-640 and posY=0-480, as arguments or use up, down, left, right instead"; } elsif ($opt eq "move") { return "module is deactivated" if(IsDisabled($name)); if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} if (!defined($prop) || ($prop ne "up" && $prop ne "down" && $prop ne "left" && $prop ne "right" && $prop !~ m/dir_\d/)) {return "Function \"move\" needs an argument like up, down, left, right or dir_X (X = 0 to CapPTZDirections-1)";} $hash->{HELPER}{GOMOVEDIR} = $prop; $hash->{HELPER}{GOMOVETIME} = defined($prop1) ? $prop1 : 1; $hash->{HELPER}{PTZACTION} = "movestart"; doptzaction($hash); } elsif ($opt eq "runView") { return "module is deactivated" if(IsDisabled($name)); if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} if ($prop eq "live_open") { if ($prop1) {$hash->{HELPER}{VIEWOPENROOM} = $prop1;} else {delete $hash->{HELPER}{VIEWOPENROOM};} $hash->{HELPER}{OPENWINDOW} = 1; $hash->{HELPER}{WLTYPE} = "link"; $hash->{HELPER}{ALIAS} = "LiveView"; $hash->{HELPER}{RUNVIEW} = "live_open"; } elsif ($prop eq "live_link") { $hash->{HELPER}{OPENWINDOW} = 0; $hash->{HELPER}{WLTYPE} = "link"; $hash->{HELPER}{ALIAS} = "LiveView"; $hash->{HELPER}{RUNVIEW} = "live_link"; } elsif ($prop eq "lastrec_open") { if ($prop1) {$hash->{HELPER}{VIEWOPENROOM} = $prop1;} else {delete $hash->{HELPER}{VIEWOPENROOM};} $hash->{HELPER}{OPENWINDOW} = 1; $hash->{HELPER}{WLTYPE} = "link"; $hash->{HELPER}{ALIAS} = "LastRecording"; $hash->{HELPER}{RUNVIEW} = "lastrec_open"; } elsif ($prop eq "lastrec_fw") { $hash->{HELPER}{OPENWINDOW} = 0; $hash->{HELPER}{WLTYPE} = "iframe"; $hash->{HELPER}{ALIAS} = " "; $hash->{HELPER}{RUNVIEW} = "lastrec"; } elsif ($prop eq "live_fw") { $hash->{HELPER}{OPENWINDOW} = 0; $hash->{HELPER}{WLTYPE} = "image"; $hash->{HELPER}{ALIAS} = " "; $hash->{HELPER}{RUNVIEW} = "live_fw"; } else { return "$prop isn't a valid option of runview, use one of live_fw, live_link, live_open, lastrec_fw, lastrec_open"; } runliveview($hash); } elsif ($opt eq "extevent") { return "module is deactivated" if(IsDisabled($name)); if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} $hash->{HELPER}{EVENTID} = $prop; extevent($hash); } elsif ($opt eq "stopView") { return "module is deactivated" if(IsDisabled($name)); stopliveview($hash); } else { return "$setlist"; } return; } ################################################################ sub SSCam_Get { my ($hash, @a) = @_; return "\"get X\" needs at least an argument" if ( @a < 2 ); my $name = shift @a; my $opt = shift @a; my $getlist = "Unknown argument $opt, choose one of ". "caminfoall:noArg ". "svsinfo:noArg ". "snapfileinfo:noArg ". "eventlist:noArg ". "stmUrlPath:noArg ". "scanVirgin:noArg " ; return if(IsDisabled($name)); if (!$hash->{CREDENTIALS}) { # sind die Credentials gesetzt ? return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\""; } elsif ($opt eq "caminfoall") { # "1" ist Statusbit für manuelle Abfrage, kein Einstieg in Pollingroutine getcaminfoall($hash,1); } elsif ($opt eq "svsinfo") { getsvsinfo($hash); } elsif ($opt eq "snapfileinfo") { if (!ReadingsVal("$name", "LastSnapId", undef)) {return "Reading LastSnapId is empty - please take a snapshot before !"} getsnapfilename($hash); } elsif ($opt eq "eventlist") { geteventlist ($hash); } elsif ($opt eq "stmUrlPath") { getStmUrlPath ($hash); } elsif ($opt eq "scanVirgin") { delete $hash->{HELPER}{APIPARSET}; delete $hash->{HELPER}{SID}; delete $hash->{CAMID}; # "1" ist Statusbit für manuelle Abfrage, kein Einstieg in Pollingroutine getcaminfoall($hash,1); } else { return "$getlist"; } return; } ###################################################################################### # Kamera Liveview Anzeige in FHEMWEB ###################################################################################### # wird von FW aufgerufen. $FW_wname = aufrufende Webinstanz, $d = aufrufendes # Device (z.B. CamCP1) sub SSCam_FWview ($$$$) { my ($FW_wname, $d, $room, $pageHash) = @_; # # pageHash is set for summaryFn in FHEMWEB my $hash = $defs{$d}; my $name = $hash->{NAME}; my $link = $hash->{HELPER}{LINK}; my $wltype = $hash->{HELPER}{WLTYPE}; my $ret; my $alias; return if(!$hash->{HELPER}{LINK} || ReadingsVal("$name", "state", "") =~ /^dis.*/ || IsDisabled($name)); Log3($name, 5, "$name - SSCam_FWview called by FW_wname: $FW_wname, device: $d, room: $room"); my $attr = AttrVal($d, "htmlattr", ""); if($wltype eq "image") { $ret = "
" .weblink_FwDetail($d); } elsif($wltype eq "iframe") { $ret = "" .weblink_FwDetail($d); } elsif($wltype eq "link") { $alias = $hash->{HELPER}{ALIAS}; $ret = "$alias
"; # wenn attr target=_blank neuer Browsertab } # FW_directNotify("FILTER=room=$room", "#FHEMWEB:$FW_wname", "location.reload('true')", "") if($d eq $name); return $ret; } ###################################################################################### # initiale Startroutinen nach Restart FHEM ###################################################################################### sub initonboot ($) { my ($hash) = @_; my $name = $hash->{NAME}; if ($init_done == 1) { RemoveInternalTimer($hash); # alle Timer löschen delete($defs{$name}{READINGS}{LiveStreamUrl}) if($defs{$name}{READINGS}{LiveStreamUrl}); # LiveStream URL zurücksetzen # check ob alle Recordings = "Stop" nach Reboot -> sonst stoppen if (ReadingsVal($hash->{NAME}, "Record", "Stop") eq "Start") { Log3($name, 2, "$name - Recording of $hash->{CAMNAME} seems to be still active after FHEM restart - try to stop it now"); camstoprec($hash); } # Konfiguration der Synology Surveillance Station abrufen if (!$hash->{CREDENTIALS}) { Log3($name, 2, "$name - Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\""); } else { # allg. SVS-Eigenschaften abrufen getsvsinfo($hash); # Kameraspezifische Infos holen getcaminfo($hash); getcapabilities($hash); # Preset/Patrollisten in Hash einlesen zur PTZ-Steuerung getptzlistpreset($hash); getptzlistpatrol($hash); } # Subroutine Watchdog-Timer starten (sollen Cam-Infos regelmäßig abgerufen werden ?), verzögerter zufälliger Start 0-30s RemoveInternalTimer($hash, "watchdogpollcaminfo"); InternalTimer(gettimeofday()+int(rand(30)), "watchdogpollcaminfo", $hash, 0); } else { RemoveInternalTimer($hash, "initonboot"); InternalTimer(gettimeofday()+1, "initonboot", $hash, 0); } return; } ###################################################################################### # Username / Paßwort speichern ###################################################################################### sub setcredentials ($@) { my ($hash, @credentials) = @_; my $name = $hash->{NAME}; my $success; my $credstr; my $index; my $retcode; my (@key,$len,$i); $credstr = encode_base64(join(':', @credentials)); # Beginn Scramble-Routine @key = qw(1 3 4 5 6 3 2 1 9); $len = scalar @key; $i = 0; $credstr = join "", map { $i = ($i + 1) % $len; chr((ord($_) + $key[$i]) % 256) } split //, $credstr; # End Scramble-Routine $index = $hash->{TYPE}."_".$hash->{NAME}."_credentials"; $retcode = setKeyValue($index, $credstr); if ($retcode) { Log3($name, 2, "$name - Error while saving the Credentials - $retcode"); $success = 0; } else { getcredentials($hash,1); # Credentials nach Speicherung lesen und in RAM laden ($boot=1) $success = 1; } return ($success); } ###################################################################################### # Username / Paßwort abrufen ###################################################################################### sub getcredentials ($$) { my ($hash,$boot) = @_; my $name = $hash->{NAME}; my $success; my $username; my $passwd; my $index; my ($retcode, $credstr); my (@key,$len,$i); if ($boot eq 1) { # mit $boot=1 Credentials von Platte lesen und als scrambled-String in RAM legen $index = $hash->{TYPE}."_".$hash->{NAME}."_credentials"; ($retcode, $credstr) = getKeyValue($index); if ($retcode) { Log3($name, 2, "$name - Unable to read password from file: $retcode"); $success = 0; } if ($credstr) { # beim Boot scrambled Credentials in den RAM laden $hash->{HELPER}{CREDENTIALS} = $credstr; # "Credentials" wird als Statusbit ausgewertet. Wenn nicht gesetzt -> Warnmeldung und keine weitere Verarbeitung $hash->{CREDENTIALS} = "Set"; $success = 1; } } else { # boot = 0 -> Credentials aus RAM lesen, decoden und zurückgeben $credstr = $hash->{HELPER}{CREDENTIALS}; # Beginn Descramble-Routine @key = qw(1 3 4 5 6 3 2 1 9); $len = scalar @key; $i = 0; $credstr = join "", map { $i = ($i + 1) % $len; chr((ord($_) - $key[$i] + 256) % 256) } split //, $credstr; # Ende Descramble-Routine ($username, $passwd) = split(":",decode_base64($credstr)); my $logpw = AttrVal($name, "showPassInLog", "0") == 1 ? $passwd : "********"; Log3($name, 4, "$name - Credentials read from RAM: $username $logpw"); $success = (defined($passwd)) ? 1 : 0; } return ($success, $username, $passwd); } ###################################################################################### # Polling Überwachung ###################################################################################### sub watchdogpollcaminfo ($) { # Überwacht die Wert von Attribut "pollcaminfoall" und Reading "PollState" # wenn Attribut "pollcaminfoall" > 10 und "PollState"=Inactive -> start Polling my ($hash) = @_; my $name = $hash->{NAME}; my $camname = $hash->{CAMNAME}; my $watchdogtimer = 90; if (defined($attr{$name}{pollcaminfoall}) and $attr{$name}{pollcaminfoall} > 10 and ReadingsVal("$name", "PollState", "Active") eq "Inactive" and !IsDisabled($name)) { # Polling ist jetzt aktiv readingsSingleUpdate($hash,"PollState","Active",0); Log3($name, 3, "$name - Polling Camera $camname is activated - Pollinginterval: ".$attr{$name}{pollcaminfoall}."s"); # in $hash eintragen für späteren Vergleich (Changes von pollcaminfoall) $hash->{HELPER}{OLDVALPOLL} = $attr{$name}{pollcaminfoall}; &getcaminfoall($hash); } if (defined($hash->{HELPER}{OLDVALPOLL}) and defined($attr{$name}{pollcaminfoall}) and $attr{$name}{pollcaminfoall} > 10) { if ($hash->{HELPER}{OLDVALPOLL} != $attr{$name}{pollcaminfoall}) { Log3($name, 3, "$name - Polling Camera $camname was changed to new Pollinginterval: ".$attr{$name}{pollcaminfoall}."s"); $hash->{HELPER}{OLDVALPOLL} = $attr{$name}{pollcaminfoall}; } } if (defined($attr{$name}{pollnologging})) { if ($hash->{HELPER}{OLDVALPOLLNOLOGGING} ne $attr{$name}{pollnologging}) { if ($attr{$name}{pollnologging} == "1") { Log3($name, 3, "$name - Log of Polling Camera $camname is deactivated"); # in $hash eintragen für späteren Vergleich (Changes von pollnologging) $hash->{HELPER}{OLDVALPOLLNOLOGGING} = $attr{$name}{pollnologging}; } else { Log3($name, 3, "$name - Log of Polling Camera $camname is activated"); # in $hash eintragen für späteren Vergleich (Changes von pollnologging) $hash->{HELPER}{OLDVALPOLLNOLOGGING} = $attr{$name}{pollnologging}; } } } else { # alter Wert von "pollnologging" war 1 -> Logging war deaktiviert if ($hash->{HELPER}{OLDVALPOLLNOLOGGING} == "1") { Log3($name, 3, "$name - Log of Polling Camera $camname is activated"); $hash->{HELPER}{OLDVALPOLLNOLOGGING} = "0"; } } RemoveInternalTimer($hash, "watchdogpollcaminfo"); InternalTimer(gettimeofday()+$watchdogtimer, "watchdogpollcaminfo", $hash, 0); return undef; } ############################################################################################################ # OpMode-Startroutinen # # $hash->{HELPER}{ACTIVE} = Funktionstoken # # $hash->{HELPER}{ACTIVE} = "on" -> eine Routine läuft, Start anderer Routine erst wenn "off". # # $hash->{HELPER}{ACTIVE} = "off" -> keine andere Routine läuft, sofortiger Start möglich # ############################################################################################################ ############################################################################### # Kamera Aufnahme starten ############################################################################### sub camstartrec ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; my $errorcode; my $error; 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 = experror($hash,$errorcode); # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode",$errorcode); readingsBulkUpdate($hash,"Error",$error); readingsEndUpdate($hash, 1); Log3($name, 2, "$name - ERROR - Start Recording of Camera $camname can't be executed - $error"); return; } if (ReadingsVal("$name", "Record", undef) eq "Start" and !AttrVal($name, "recextend", undef)) { Log3($name, 3, "$name - another recording is already running - new start-command will be ignored"); return; } if ($hash->{HELPER}{ACTIVE} eq "off") { # Aufnahme starten Log3($name, 4, "$name - Recording of Camera $camname will be started now"); $hash->{OPMODE} = "Start"; $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 { RemoveInternalTimer($hash, "camstartrec"); InternalTimer(gettimeofday()+0.3, "camstartrec", $hash); } } ############################################################################### # Kamera Aufnahme stoppen ############################################################################### sub camstoprec ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; my $errorcode; my $error; 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 = experror($hash,$errorcode); # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode",$errorcode); readingsBulkUpdate($hash,"Error",$error); readingsEndUpdate($hash, 1); Log3($name, 2, "$name - ERROR - Stop Recording of Camera $camname can't be executed - $error"); return; } if (ReadingsVal("$name", "Record", undef) eq "Stop") { Log3($name, 3, "$name - recording is already stopped - new stop-command will be ignored"); return; } if ($hash->{HELPER}{ACTIVE} eq "off") { # Aufnahme stoppen Log3($name, 4, "$name - Recording of Camera $camname will be stopped now"); $hash->{OPMODE} = "Stop"; $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 { RemoveInternalTimer($hash, "camstoprec"); InternalTimer(gettimeofday()+0.3, "camstoprec", $hash, 0); } } ############################################################################### # Kamera Auto / Day / Nightmode setzen ############################################################################### sub camexpmode ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; my $errorcode; my $error; 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 = experror($hash,$errorcode); # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode",$errorcode); readingsBulkUpdate($hash,"Error",$error); readingsEndUpdate($hash, 1); Log3($name, 2, "$name - ERROR - Setting exposure mode of Camera $camname can't be executed - $error"); return; } if ($hash->{HELPER}{ACTIVE} eq "off") { Log3($name, 4, "$name - Setting of exposure mode of Camera $camname will be started now"); $hash->{OPMODE} = "ExpMode"; $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 { RemoveInternalTimer($hash, "camexpmode"); InternalTimer(gettimeofday()+0.5, "camexpmode", $hash, 0); } } ############################################################################### # Art der Bewegungserkennung setzen ############################################################################### sub cammotdetsc ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; my $errorcode; my $error; 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 = experror($hash,$errorcode); # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode",$errorcode); readingsBulkUpdate($hash,"Error",$error); readingsEndUpdate($hash, 1); Log3($name, 2, "$name - ERROR - Setting of motion detection source of Camera $camname can't be executed - $error"); return; } if ($hash->{HELPER}{ACTIVE} eq "off") { Log3($name, 4, "$name - Setting of motion detection source of Camera $camname will be started now"); $hash->{OPMODE} = "MotDetSc"; $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 { RemoveInternalTimer($hash, "cammotdetsc"); InternalTimer(gettimeofday()+0.5, "cammotdetsc", $hash, 0); } } ############################################################################### # Kamera Schappschuß aufnehmen ############################################################################### sub camsnap ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; my $errorcode; my $error; 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 = experror($hash,$errorcode); # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode",$errorcode); readingsBulkUpdate($hash,"Error",$error); readingsEndUpdate($hash, 1); Log3($name, 2, "$name - ERROR - Snapshot of Camera $camname can't be executed - $error"); return; } if ($hash->{HELPER}{ACTIVE} eq "off") { # einen Schnappschuß aufnehmen Log3($name, 4, "$name - Take Snapshot of Camera $camname"); $hash->{OPMODE} = "Snap"; $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 { RemoveInternalTimer($hash, "camsnap"); InternalTimer(gettimeofday()+0.3, "camsnap", $hash, 0); } } ############################################################################### # Kamera Liveview starten ############################################################################### sub runliveview ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; my $errorcode; my $error; 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 = &experror($hash,$errorcode); # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode",$errorcode); readingsBulkUpdate($hash,"Error",$error); readingsEndUpdate($hash, 1); Log3($name, 2, "$name - ERROR - Liveview of Camera $camname can't be started - $error"); return; } if ($hash->{HELPER}{ACTIVE} eq "off") { # Liveview starten Log3($name, 4, "$name - Start Liveview of Camera $camname"); $hash->{OPMODE} = "runliveview"; $hash->{HELPER}{ACTIVE} = "on"; $hash->{HELPER}{LOGINRETRIES} = 0; # erzwingen die Camid zu ermitteln und bei bei login-Fehler neu SID zu holen delete $hash->{CAMID}; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}"); } readingsSingleUpdate($hash,"state","startview",1); sscam_getapisites($hash); } else { RemoveInternalTimer($hash, "runliveview"); InternalTimer(gettimeofday()+0.5, "runliveview", $hash, 0); } } ############################################################################### # Kamera Liveview stoppen ############################################################################### sub stopliveview ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; my $errorcode; my $error; return if(IsDisabled($name)); if ($hash->{HELPER}{ACTIVE} eq "off") { # kurzer state-switch -> Browser aktualisieren readingsSingleUpdate($hash,"state","stopview",1); # Liveview stoppen Log3($name, 4, "$name - Stop Liveview of Camera $camname now"); $hash->{OPMODE} = "stopliveview"; $hash->{HELPER}{ACTIVE} = "on"; $hash->{HELPER}{LOGINRETRIES} = 0; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}"); } # Link aus Helper-hash löschen delete $hash->{HELPER}{LINK}; # Reading LiveStreamUrl löschen delete($defs{$name}{READINGS}{LiveStreamUrl}) if ($defs{$name}{READINGS}{LiveStreamUrl}); # vorhandenen Aufnahmestatus wieder herstellen if (ReadingsVal("$name", "Record", "") eq "Start") { readingsSingleUpdate( $hash,"state", "on", 1); } else { readingsSingleUpdate($hash,"state", "off", 1); } $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } } else { RemoveInternalTimer($hash, "stopliveview"); InternalTimer(gettimeofday()+0.5, "stopliveview", $hash, 0); } } ############################################################################### # Filename zu Schappschuß ermitteln ############################################################################### sub getsnapfilename ($) { my ($hash) = @_; my $name = $hash->{NAME}; my $snapid = ReadingsVal("$name", "LastSnapId", " "); return if(IsDisabled($name)); if ($hash->{HELPER}{ACTIVE} eq "off") { # den Filenamen zu einem Schnappschuß ermitteln Log3($name, 4, "$name - Get filename of present Snap-ID $snapid"); $hash->{OPMODE} = "getsnapfilename"; $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 { RemoveInternalTimer($hash, "getsnapfilename"); InternalTimer(gettimeofday()+0.5, "getsnapfilename", $hash, 0); } } ############################################################################### # external Event 1-10 auslösen ############################################################################### sub extevent ($) { my ($hash) = @_; my $name = $hash->{NAME}; return if(IsDisabled($name)); if ($hash->{HELPER}{ACTIVE} eq "off") { Log3($name, 4, "$name - trigger external event \"$hash->{HELPER}{EVENTID}\""); $hash->{OPMODE} = "extevent"; $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 { RemoveInternalTimer($hash, "extevent"); InternalTimer(gettimeofday()+0.5, "extevent", $hash, 0); } } ############################################################################### # PTZ-Kamera auf Position fahren ############################################################################### sub doptzaction ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; my $errorcode; my $error; return if(IsDisabled($name)); if (ReadingsVal("$name", "DeviceType", "Camera") ne "PTZ") { Log3($name, 2, "$name - ERROR - Operation \"$hash->{HELPER}{PTZACTION}\" is only possible for cameras of DeviceType \"PTZ\" - please compare with device Readings"); return; } if ($hash->{HELPER}{PTZACTION} eq "goabsptz" && !ReadingsVal("$name", "CapPTZAbs", "false")) { Log3($name, 2, "$name - ERROR - Operation \"$hash->{HELPER}{PTZACTION}\" is only possible if camera supports absolute PTZ action - please compare with device Reading \"CapPTZAbs\""); return; } if ( $hash->{HELPER}{PTZACTION} eq "movestart" && ReadingsVal("$name", "CapPTZDirections", "0") < 1) { Log3($name, 2, "$name - ERROR - Operation \"$hash->{HELPER}{PTZACTION}\" is only possible if camera supports \"Tilt\" and \"Pan\" operations - please compare with device Reading \"CapPTZDirections\""); return; } if ($hash->{HELPER}{PTZACTION} eq "gopreset") { if (!defined($hash->{HELPER}{ALLPRESETS}{$hash->{HELPER}{GOPRESETNAME}})) { $errorcode = "600"; # Fehlertext zum Errorcode ermitteln $error = experror($hash,$errorcode); # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode",$errorcode); readingsBulkUpdate($hash,"Error",$error); readingsEndUpdate($hash, 1); Log3($name, 2, "$name - ERROR - goPreset to position \"$hash->{HELPER}{GOPRESETNAME}\" of Camera $camname can't be executed - $error"); return; } } if ($hash->{HELPER}{PTZACTION} eq "runpatrol") { if (!defined($hash->{HELPER}{ALLPATROLS}{$hash->{HELPER}{GOPATROLNAME}})) { $errorcode = "600"; # Fehlertext zum Errorcode ermitteln $error = experror($hash,$errorcode); # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode",$errorcode); readingsBulkUpdate($hash,"Error",$error); readingsEndUpdate($hash, 1); Log3($name, 2, "$name - ERROR - runPatrol to patrol \"$hash->{HELPER}{GOPATROLNAME}\" of Camera $camname can't be executed - $error"); return; } } 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 = experror($hash,$errorcode); # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode",$errorcode); readingsBulkUpdate($hash,"Error",$error); readingsEndUpdate($hash, 1); Log3($name, 2, "$name - ERROR - $hash->{HELPER}{PTZACTION} of Camera $camname can't be executed - $error"); return; } if ($hash->{HELPER}{ACTIVE} eq "off") { if ($hash->{HELPER}{PTZACTION} eq "gopreset") { Log3($name, 4, "$name - Move Camera $camname to position \"$hash->{HELPER}{GOPRESETNAME}\" with ID \"$hash->{HELPER}{ALLPRESETS}{$hash->{HELPER}{GOPRESETNAME}}\" now"); } elsif ($hash->{HELPER}{PTZACTION} eq "runpatrol") { Log3($name, 4, "$name - Start patrol \"$hash->{HELPER}{GOPATROLNAME}\" with ID \"$hash->{HELPER}{ALLPATROLS}{$hash->{HELPER}{GOPATROLNAME}}\" of Camera $camname now"); } elsif ($hash->{HELPER}{PTZACTION} eq "goabsptz") { Log3($name, 4, "$name - Start move Camera $camname to position posX=\"$hash->{HELPER}{GOPTZPOSX}\" and posY=\"$hash->{HELPER}{GOPTZPOSY}\" now"); } elsif ($hash->{HELPER}{PTZACTION} eq "movestart") { Log3($name, 4, "$name - Start move Camera $camname to direction \"$hash->{HELPER}{GOMOVEDIR}\" with duration of $hash->{HELPER}{GOMOVETIME} s"); } if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}"); } $hash->{OPMODE} = $hash->{HELPER}{PTZACTION}; $hash->{HELPER}{ACTIVE} = "on"; $hash->{HELPER}{LOGINRETRIES} = 0; sscam_getapisites($hash); } else { RemoveInternalTimer($hash, "doptzaction"); InternalTimer(gettimeofday()+0.5, "doptzaction", $hash, 0); } } ############################################################################### # stoppen continues move ############################################################################### sub movestop ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; return if(IsDisabled($name)); if ($hash->{HELPER}{ACTIVE} eq "off") { Log3($name, 4, "$name - Stop Camera $camname moving to direction \"$hash->{HELPER}{GOMOVEDIR}\" now"); $hash->{OPMODE} = "movestop"; $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 { RemoveInternalTimer($hash, "movestop"); InternalTimer(gettimeofday()+0.3, "movestop", $hash, 0); } } ############################################################################### # Kamera aktivieren ############################################################################### sub camenable ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; return if(IsDisabled($name)); # if (ReadingsVal("$name", "Availability", "disabled") eq "enabled") {return;} # Kamera ist bereits enabled if ($hash->{HELPER}{ACTIVE} eq "off") { # eine Kamera aktivieren Log3($name, 4, "$name - Enable Camera $camname"); $hash->{OPMODE} = "Enable"; $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 { RemoveInternalTimer($hash, "camenable"); InternalTimer(gettimeofday()+0.5, "camenable", $hash, 0); } } ############################################################################### # Kamera deaktivieren ############################################################################### sub camdisable ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; return if(IsDisabled($name)); # if (ReadingsVal("$name", "Availability", "enabled") eq "disabled") {return;} # Kamera ist bereits disabled if ($hash->{HELPER}{ACTIVE} eq "off" and ReadingsVal("$name", "Record", "Start") ne "Start") { # eine Kamera deaktivieren Log3($name, 4, "$name - Disable Camera $camname"); $hash->{OPMODE} = "Disable"; $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 { RemoveInternalTimer($hash, "camdisable"); InternalTimer(gettimeofday()+0.5, "camdisable", $hash, 0); } } ############################################################################### # Kamera alle Informationen abrufen (Get) bzw. Einstieg Polling ############################################################################### sub getcaminfoall { my ($hash,$mode) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; my ($now,$new); return if(IsDisabled($name)); geteventlist($hash); RemoveInternalTimer($hash, "getcaminfo"); InternalTimer(gettimeofday()+0.5, "getcaminfo", $hash, 0); RemoveInternalTimer($hash, "getmotionenum"); InternalTimer(gettimeofday()+0.8, "getmotionenum", $hash, 0); RemoveInternalTimer($hash, "getcapabilities"); InternalTimer(gettimeofday()+1.3, "getcapabilities", $hash, 0); RemoveInternalTimer($hash, "getptzlistpreset"); InternalTimer(gettimeofday()+1.6, "getptzlistpreset", $hash, 0); RemoveInternalTimer($hash, "getptzlistpatrol"); InternalTimer(gettimeofday()+1.9, "getptzlistpatrol", $hash, 0); RemoveInternalTimer($hash, "getStmUrlPath"); InternalTimer(gettimeofday()+2.1, "getStmUrlPath", $hash, 0); # wenn gesetzt = manuelle Abfrage, if ($mode) { getsvsinfo($hash); return; } if (defined($attr{$name}{pollcaminfoall}) and $attr{$name}{pollcaminfoall} > 10) { # Pollen wenn pollcaminfo > 10, sonst kein Polling $new = gettimeofday()+$attr{$name}{pollcaminfoall}; InternalTimer($new, "getcaminfoall", $hash, 0); if (!$attr{$name}{pollnologging}) { $now = FmtTime(gettimeofday()); $new = FmtTime(gettimeofday()+$attr{$name}{pollcaminfoall}); Log3($name, 3, "$name - Polling now: $now , next Polling: $new"); } } else { # Beenden Polling aller Caminfos readingsSingleUpdate($hash,"PollState","Inactive",0); Log3($name, 3, "$name - Polling of Camera $camname is deactivated"); } return; } ########################################################################### # allgemeine Infos über Synology Surveillance Station ########################################################################### sub getsvsinfo ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; return if(IsDisabled($name)); if ($hash->{HELPER}{ACTIVE} eq "off") { # Kamerainfos abrufen Log3($name, 4, "$name - Retrieval of Surveillance Station related informations starts now"); $hash->{OPMODE} = "Getsvsinfo"; $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 { RemoveInternalTimer($hash, "getsvsinfo"); InternalTimer(gettimeofday()+1, "getsvsinfo", $hash, 0); } } ########################################################################### # Kamera allgemeine Informationen abrufen (Get), sub von getcaminfoall ########################################################################### sub getcaminfo ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; return if(IsDisabled($name)); if ($hash->{HELPER}{ACTIVE} eq "off") { # Kamerainfos abrufen Log3($name, 4, "$name - Retrieval Camera-Informations of $camname starts now"); $hash->{OPMODE} = "Getcaminfo"; $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 { RemoveInternalTimer($hash, "getcaminfo"); InternalTimer(gettimeofday()+2, "getcaminfo", $hash, 0); } } ################################################################################ # Kamera Stream Urls abrufen (Get), Aufruf aus getcaminfoall ################################################################################ sub getStmUrlPath ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; return if(IsDisabled($name)); if ($hash->{HELPER}{ACTIVE} eq "off") { # Stream-Urls abrufen Log3($name, 4, "$name - Retrieval Stream-URLs of $camname starts now"); $hash->{OPMODE} = "getStmUrlPath"; $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 { RemoveInternalTimer($hash, "getStmUrlPath"); InternalTimer(gettimeofday()+2, "getStmUrlPath", $hash, 0); } } ########################################################################### # query SVS-Event information , sub von getcaminfoall ########################################################################### sub geteventlist ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; return if(IsDisabled($name)); if ($hash->{HELPER}{ACTIVE} eq "off") { # Kamerainfos abrufen Log3($name, 4, "$name - Query event informations of $camname starts now"); $hash->{OPMODE} = "geteventlist"; $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 { RemoveInternalTimer($hash, "geteventlist"); InternalTimer(gettimeofday()+2, "geteventlist", $hash, 0); } } ########################################################################### # Enumerate motion detection parameters, sub von getcaminfoall ########################################################################### sub getmotionenum ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; return if(IsDisabled($name)); if ($hash->{HELPER}{ACTIVE} eq "off") { Log3($name, 4, "$name - Enumerate motion detection parameters of $camname starts now"); $hash->{OPMODE} = "getmotionenum"; $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 { RemoveInternalTimer($hash, "getmotionenum"); InternalTimer(gettimeofday()+2, "getmotionenum", $hash, 0); } } ########################################################################## # Capabilities von Kamera abrufen (Get), sub von getcaminfoall ########################################################################## sub getcapabilities ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; return if(IsDisabled($name)); if ($hash->{HELPER}{ACTIVE} eq "off") { # PTZ-ListPresets abrufen Log3($name, 4, "$name - Retrieval Capabilities of Camera $camname starts now"); $hash->{OPMODE} = "Getcapabilities"; $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 { RemoveInternalTimer($hash, "getcapabilities"); InternalTimer(gettimeofday()+2, "getcapabilities", $hash, 0); } } ########################################################################## # PTZ Presets abrufen (Get), sub von getcaminfoall ########################################################################## sub getptzlistpreset ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; return if(IsDisabled($name)); if (ReadingsVal("$name", "DeviceType", "") ne "PTZ") { Log3($name, 4, "$name - Retrieval of Presets for $camname can't be executed - $camname is not a PTZ-Camera"); return; } if (ReadingsVal("$name", "CapPTZTilt", "") eq "false" | ReadingsVal("$name", "CapPTZPan", "") eq "false") { Log3($name, 4, "$name - Retrieval of Presets for $camname can't be executed - $camname has no capability to tilt/pan"); return; } if ($hash->{HELPER}{ACTIVE} eq "off") { # PTZ-ListPresets abrufen Log3($name, 4, "$name - Retrieval PTZ-ListPresets of $camname starts now"); $hash->{OPMODE} = "Getptzlistpreset"; $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 { RemoveInternalTimer($hash, "getptzlistpreset"); InternalTimer(gettimeofday()+2, "getptzlistpreset", $hash, 0); } } ########################################################################## # PTZ Patrols abrufen (Get), sub von getcaminfoall ########################################################################## sub getptzlistpatrol ($) { my ($hash) = @_; my $camname = $hash->{CAMNAME}; my $name = $hash->{NAME}; return if(IsDisabled($name)); if (ReadingsVal("$name", "DeviceType", "") ne "PTZ") { Log3($name, 4, "$name - Retrieval of Patrols for $camname can't be executed - $camname is not a PTZ-Camera"); return; } if (ReadingsVal("$name", "CapPTZTilt", "") eq "false" | ReadingsVal("$name", "CapPTZPan", "") eq "false") { Log3($name, 4, "$name - Retrieval of Patrols for $camname can't be executed - $camname has no capability to tilt/pan"); return; } if ($hash->{HELPER}{ACTIVE} ne "on") { # PTZ-ListPatrols abrufen Log3($name, 4, "$name - Retrieval PTZ-ListPatrols of $camname starts now"); $hash->{OPMODE} = "Getptzlistpatrol"; $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 { RemoveInternalTimer($hash, "getptzlistpatrol"); InternalTimer(gettimeofday()+2, "getptzlistpatrol", $hash, 0); } } ############################################################################################################################# ####### Begin Kameraoperationen mit NonblockingGet (nicht blockierender HTTP-Call) ####### ############################################################################################################################# sub sscam_getapisites { my ($hash) = @_; my $serveraddr = $hash->{SERVERADDR}; my $serverport = $hash->{SERVERPORT}; my $name = $hash->{NAME}; my $apiinfo = $hash->{HELPER}{APIINFO}; # Info-Seite für alle API's, einzige statische Seite ! my $apiauth = $hash->{HELPER}{APIAUTH}; my $apiextrec = $hash->{HELPER}{APIEXTREC}; my $apiextevt = $hash->{HELPER}{APIEXTEVT}; my $apicam = $hash->{HELPER}{APICAM}; my $apitakesnap = $hash->{HELPER}{APISNAPSHOT}; my $apiptz = $hash->{HELPER}{APIPTZ}; my $apisvsinfo = $hash->{HELPER}{APISVSINFO}; my $apicamevent = $hash->{HELPER}{APICAMEVENT}; my $apievent = $hash->{HELPER}{APIEVENT}; my $apivideostm = $hash->{HELPER}{APIVIDEOSTM}; my $apistm = $hash->{HELPER}{APISTM}; my $url; my $param; # API-Pfade und MaxVersions ermitteln Log3($name, 4, "$name - ####################################################"); Log3($name, 4, "$name - ### start new cam operation ##"); Log3($name, 4, "$name - ####################################################"); Log3($name, 4, "$name - --- Begin Function sscam_getapisites nonblocking ---"); if ($hash->{HELPER}{APIPARSET}) { # API-Hashwerte sind bereits gesetzt -> Abruf überspringen Log3($name, 4, "$name - API hashvalues already set - ignore get apisites"); return sscam_checksid($hash); } my $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4"; Log3($name, 5, "$name - HTTP-Call will be done with httptimeout-Value: $httptimeout s"); # URL zur Abfrage der Eigenschaften der API's $url = "http://$serveraddr:$serverport/webapi/query.cgi?api=$apiinfo&method=Query&version=1&query=$apiauth,$apiextrec,$apicam,$apitakesnap,$apiptz,$apisvsinfo,$apicamevent,$apievent,$apivideostm,$apiextevt,$apistm"; Log3($name, 4, "$name - Call-Out now: $url"); $param = { url => $url, timeout => $httptimeout, hash => $hash, method => "GET", header => "Accept: application/json", callback => \&sscam_getapisites_parse }; HttpUtils_NonblockingGet ($param); } #################################################################################### # Auswertung Abruf apisites #################################################################################### sub sscam_getapisites_parse ($) { my ($param, $err, $myjson) = @_; my $hash = $param->{hash}; my $name = $hash->{NAME}; my $serveraddr = $hash->{SERVERADDR}; my $serverport = $hash->{SERVERPORT}; my $apiauth = $hash->{HELPER}{APIAUTH}; my $apiextrec = $hash->{HELPER}{APIEXTREC}; my $apiextevt = $hash->{HELPER}{APIEXTEVT}; my $apicam = $hash->{HELPER}{APICAM}; my $apitakesnap = $hash->{HELPER}{APISNAPSHOT}; my $apiptz = $hash->{HELPER}{APIPTZ}; my $apisvsinfo = $hash->{HELPER}{APISVSINFO}; my $apicamevent = $hash->{HELPER}{APICAMEVENT}; my $apievent = $hash->{HELPER}{APIEVENT}; my $apivideostm = $hash->{HELPER}{APIVIDEOSTM}; my $apistm = $hash->{HELPER}{APISTM}; my ($apicammaxver,$apicampath); if ($err ne "") { # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist Log3($name, 2, "$name - error while requesting ".$param->{url}." - $err"); readingsSingleUpdate($hash, "Error", $err, 1); # ausgeführte Funktion ist abgebrochen, Freigabe Funktionstoken $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } return; } elsif ($myjson ne "") { # Evaluiere ob Daten im JSON-Format empfangen wurden ($hash, my $success) = &evaljson($hash,$myjson,$param->{url}); unless ($success) { Log3($name, 4, "$name - Data returned: $myjson"); $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } return; } my $data = decode_json($myjson); # Logausgabe decodierte JSON Daten Log3($name, 5, "$name - JSON returned: ". Dumper $data); $success = $data->{'success'}; if ($success) { my $logstr; # Pfad und Maxversion von "SYNO.API.Auth" ermitteln my $apiauthpath = $data->{'data'}->{$apiauth}->{'path'}; $apiauthpath =~ tr/_//d if (defined($apiauthpath)); my $apiauthmaxver = $data->{'data'}->{$apiauth}->{'maxVersion'}; $logstr = defined($apiauthpath) ? "Path of $apiauth selected: $apiauthpath" : "Path of $apiauth undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); $logstr = defined($apiauthmaxver) ? "MaxVersion of $apiauth selected: $apiauthmaxver" : "MaxVersion of $apiauth undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); # Pfad und Maxversion von "SYNO.SurveillanceStation.ExternalRecording" ermitteln my $apiextrecpath = $data->{'data'}->{$apiextrec}->{'path'}; $apiextrecpath =~ tr/_//d if (defined($apiextrecpath)); my $apiextrecmaxver = $data->{'data'}->{$apiextrec}->{'maxVersion'}; $logstr = defined($apiextrecpath) ? "Path of $apiextrec selected: $apiextrecpath" : "Path of $apiextrec undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); $logstr = defined($apiextrecmaxver) ? "MaxVersion of $apiextrec selected: $apiextrecmaxver" : "MaxVersion of $apiextrec undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); # Pfad und Maxversion von "SYNO.SurveillanceStation.Camera" ermitteln $apicampath = $data->{'data'}->{$apicam}->{'path'}; $apicampath =~ tr/_//d if (defined($apicampath)); $apicammaxver = $data->{'data'}->{$apicam}->{'maxVersion'}; $logstr = defined($apicampath) ? "Path of $apicam selected: $apicampath" : "Path of $apicam undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); $logstr = defined($apiextrecmaxver) ? "MaxVersion of $apicam: $apicammaxver" : "MaxVersion of $apicam undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); # Pfad und Maxversion von "SYNO.SurveillanceStation.SnapShot" ermitteln my $apitakesnappath = $data->{'data'}->{$apitakesnap}->{'path'}; $apitakesnappath =~ tr/_//d if (defined($apitakesnappath)); my $apitakesnapmaxver = $data->{'data'}->{$apitakesnap}->{'maxVersion'}; $logstr = defined($apitakesnappath) ? "Path of $apitakesnap selected: $apitakesnappath" : "Path of $apitakesnap undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); $logstr = defined($apitakesnapmaxver) ? "MaxVersion of $apitakesnap: $apitakesnapmaxver" : "MaxVersion of $apitakesnap undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); # Pfad und Maxversion von "SYNO.SurveillanceStation.PTZ" ermitteln my $apiptzpath = $data->{'data'}->{$apiptz}->{'path'}; $apiptzpath =~ tr/_//d if (defined($apiptzpath)); my $apiptzmaxver = $data->{'data'}->{$apiptz}->{'maxVersion'}; $logstr = defined($apiptzpath) ? "Path of $apiptz selected: $apiptzpath" : "Path of $apiptz undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); $logstr = defined($apiptzmaxver) ? "MaxVersion of $apiptz: $apiptzmaxver" : "MaxVersion of $apiptz undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); # Pfad und Maxversion von "SYNO.SurveillanceStation.Info" ermitteln my $apisvsinfopath = $data->{'data'}->{$apisvsinfo}->{'path'}; $apisvsinfopath =~ tr/_//d if (defined($apisvsinfopath)); my $apisvsinfomaxver = $data->{'data'}->{$apisvsinfo}->{'maxVersion'}; $logstr = defined($apisvsinfopath) ? "Path of $apisvsinfo selected: $apisvsinfopath" : "Path of $apisvsinfo undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); $logstr = defined($apisvsinfomaxver) ? "MaxVersion of $apisvsinfo: $apisvsinfomaxver" : "MaxVersion of $apisvsinfo undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); # Pfad und Maxversion von "SYNO.Surveillance.Camera.Event" ermitteln my $apicameventpath = $data->{'data'}->{$apicamevent}->{'path'}; $apicameventpath =~ tr/_//d if (defined($apicameventpath)); my $apicameventmaxver = $data->{'data'}->{$apicamevent}->{'maxVersion'}; $logstr = defined($apicameventpath) ? "Path of $apicamevent selected: $apicameventpath" : "Path of $apicamevent undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); $logstr = defined($apicameventmaxver) ? "MaxVersion of $apicamevent: $apicameventmaxver" : "MaxVersion of $apicamevent undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); # Pfad und Maxversion von "SYNO.Surveillance.Event" ermitteln my $apieventpath = $data->{'data'}->{$apievent}->{'path'}; $apieventpath =~ tr/_//d if (defined($apieventpath)); my $apieventmaxver = $data->{'data'}->{$apievent}->{'maxVersion'}; $logstr = defined($apieventpath) ? "Path of $apievent selected: $apieventpath" : "Path of $apievent undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); $logstr = defined($apieventmaxver) ? "MaxVersion of $apievent: $apieventmaxver" : "MaxVersion of $apievent undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); # Pfad und Maxversion von "SYNO.Surveillance.VideoStream" ermitteln my $apivideostmpath = $data->{'data'}->{$apivideostm}->{'path'}; $apivideostmpath =~ tr/_//d if (defined($apivideostmpath)); my $apivideostmmaxver = $data->{'data'}->{$apivideostm}->{'maxVersion'}; $logstr = defined($apivideostmpath) ? "Path of $apivideostm selected: $apivideostmpath" : "Path of $apivideostm undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); $logstr = defined($apivideostmmaxver) ? "MaxVersion of $apivideostm: $apivideostmmaxver" : "MaxVersion of $apivideostm undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); # Pfad und Maxversion von "SYNO.SurveillanceStation.ExternalEvent" ermitteln my $apiextevtpath = $data->{'data'}->{$apiextevt}->{'path'}; $apiextevtpath =~ tr/_//d if (defined($apiextevtpath)); my $apiextevtmaxver = $data->{'data'}->{$apiextevt}->{'maxVersion'}; $logstr = defined($apiextevtpath) ? "Path of $apiextevt selected: $apiextevtpath" : "Path of $apiextevt undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); $logstr = defined($apiextevtmaxver) ? "MaxVersion of $apiextevt selected: $apiextevtmaxver" : "MaxVersion of $apiextevt undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); # Pfad und Maxversion von "SYNO.SurveillanceStation.Streaming" ermitteln my $apistmpath = $data->{'data'}->{$apistm}->{'path'}; $apistmpath =~ tr/_//d if (defined($apistmpath)); my $apistmmaxver = $data->{'data'}->{$apistm}->{'maxVersion'}; $logstr = defined($apistmpath) ? "Path of $apistm selected: $apistmpath" : "Path of $apistm undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); $logstr = defined($apistmmaxver) ? "MaxVersion of $apistm selected: $apistmmaxver" : "MaxVersion of $apistm undefined - Surveillance Station may be stopped"; Log3($name, 4, "$name - $logstr"); # aktuelle oder simulierte SVS-Version für Fallentscheidung setzen no warnings 'uninitialized'; my $major = $hash->{HELPER}{SVSVERSION}{MAJOR}; my $minor = $hash->{HELPER}{SVSVERSION}{MINOR}; my $build = $hash->{HELPER}{SVSVERSION}{BUILD}; my $actvs = $major.$minor.$build; Log3($name, 4, "$name - saved SVS version is: $actvs"); use warnings; if(!$actvs and AttrVal($name, "simu_SVSversion", undef)) { my @vl = split (/\.|-/,AttrVal($name, "simu_SVSversion", "")); $actvs = $vl[0]; $actvs .= $vl[1]; $actvs .= $vl[2]."-simu" if($vl[2]); } # Simulation anderer SVS-Versionen Log3($name, 4, "$name - ------- Begin of simulation section -------"); if (AttrVal($name, "simu_SVSversion", undef)) { Log3($name, 4, "$name - SVS version $actvs will be simulated"); if ($actvs =~ /^71/) { $apicammaxver = 8; Log3($name, 4, "$name - MaxVersion of $apicam adapted to: $apicammaxver"); $apiauthmaxver = 4; Log3($name, 4, "$name - MaxVersion of $apiauth adapted to: $apiauthmaxver"); $apiextrecmaxver = 2; Log3($name, 4, "$name - MaxVersion of $apiextrec adapted to: $apiextrecmaxver"); $apiptzmaxver = 4; Log3($name, 4, "$name - MaxVersion of $apiptz adapted to: $apiptzmaxver"); } elsif ($actvs =~ /^72/) { $apicammaxver = 8; Log3($name, 4, "$name - MaxVersion of $apicam adapted to: $apicammaxver"); $apiauthmaxver = 6; Log3($name, 4, "$name - MaxVersion of $apiauth adapted to: $apiauthmaxver"); $apiextrecmaxver = 3; Log3($name, 4, "$name - MaxVersion of $apiextrec adapted to: $apiextrecmaxver"); $apiptzmaxver = 5; Log3($name, 4, "$name - MaxVersion of $apiptz adapted to: $apiptzmaxver"); } } else { Log3($name, 4, "$name - no simulations done !"); } Log3($name, 4, "$name - ------- End of simulation section -------"); # Downgrades für nicht kompatible API-Versionen Log3($name, 4, "$name - ------- Begin of adaption section -------"); $apiptzmaxver = 4; Log3($name, 4, "$name - MaxVersion of $apiptz adapted to: $apiptzmaxver"); $apicammaxver = 8; Log3($name, 4, "$name - MaxVersion of $apicam adapted to: $apicammaxver"); Log3($name, 4, "$name - ------- End of adaption section -------"); # ermittelte Werte in $hash einfügen $hash->{HELPER}{APIAUTHPATH} = $apiauthpath; $hash->{HELPER}{APIAUTHMAXVER} = $apiauthmaxver; $hash->{HELPER}{APIEXTRECPATH} = $apiextrecpath; $hash->{HELPER}{APIEXTRECMAXVER} = $apiextrecmaxver; $hash->{HELPER}{APICAMPATH} = $apicampath; $hash->{HELPER}{APICAMMAXVER} = $apicammaxver; $hash->{HELPER}{APITAKESNAPPATH} = $apitakesnappath; $hash->{HELPER}{APITAKESNAPMAXVER} = $apitakesnapmaxver; $hash->{HELPER}{APIPTZPATH} = $apiptzpath; $hash->{HELPER}{APIPTZMAXVER} = $apiptzmaxver; $hash->{HELPER}{APISVSINFOPATH} = $apisvsinfopath; $hash->{HELPER}{APISVSINFOMAXVER} = $apisvsinfomaxver; $hash->{HELPER}{APICAMEVENTPATH} = $apicameventpath; $hash->{HELPER}{APICAMEVENTMAXVER} = $apicameventmaxver; $hash->{HELPER}{APIEVENTPATH} = $apieventpath; $hash->{HELPER}{APIEVENTMAXVER} = $apieventmaxver; $hash->{HELPER}{APIVIDEOSTMPATH} = $apivideostmpath; $hash->{HELPER}{APIVIDEOSTMMAXVER} = $apivideostmmaxver; $hash->{HELPER}{APIEXTEVTPATH} = $apiextevtpath; $hash->{HELPER}{APIEXTEVTMAXVER} = $apiextevtmaxver; $hash->{HELPER}{APISTMPATH} = $apistmpath; $hash->{HELPER}{APISTMMAXVER} = $apistmmaxver; readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash,1); # API Hash values sind gesetzt $hash->{HELPER}{APIPARSET} = 1; } else { my $error = "couldn't call API-Infosite"; readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error",$error); readingsEndUpdate($hash, 1); Log3($name, 2, "$name - ERROR - the API-Query couldn't be executed successfully"); # ausgeführte Funktion ist abgebrochen, Freigabe Funktionstoken $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } return; } } return sscam_checksid($hash); } ############################################################################################# # Check ob Session ID gesetzt ist - ggf. login ############################################################################################# sub sscam_checksid ($) { my ($hash) = @_; my $name = $hash->{NAME}; # SID holen bzw. login my $sid = $hash->{HELPER}{SID}; if(!$sid) { Log3($name, 3, "$name - no session ID found - get new one"); sscam_login($hash,'sscam_getcamid'); return; } return sscam_getcamid($hash); } ############################################################################################# # Abruf der installierten Cams ############################################################################################# sub sscam_getcamid ($) { my ($hash) = @_; my $name = $hash->{NAME}; my $serveraddr = $hash->{SERVERADDR}; my $serverport = $hash->{SERVERPORT}; my $apicam = $hash->{HELPER}{APICAM}; my $apicampath = $hash->{HELPER}{APICAMPATH}; my $apicammaxver = $hash->{HELPER}{APICAMMAXVER}; my $sid = $hash->{HELPER}{SID}; # die Kamera-Id wird aus dem Kameranamen (Surveillance Station) ermittelt Log3($name, 4, "$name - --- Begin Function sscam_getcamid nonblocking ---"); if ($hash->{CAMID}) { # Camid ist bereits ermittelt -> Abruf überspringen Log3($name, 4, "$name - CAMID already set - ignore get camid"); return sscam_camop($hash); } my $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4"; Log3($name, 5, "$name - HTTP-Call will be done with httptimeout-Value: $httptimeout s"); my $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=$apicam&version=$apicammaxver&method=List&basic=true&streamInfo=true&camStm=true&_sid=\"$sid\""; Log3($name, 4, "$name - Call-Out now: $url"); my $param = { url => $url, timeout => $httptimeout, hash => $hash, method => "GET", header => "Accept: application/json", callback => \&sscam_getcamid_parse }; HttpUtils_NonblockingGet($param); } ############################################################################################# # Auswertung installierte Cams, Selektion Cam , Ausführung Operation ############################################################################################# sub sscam_getcamid_parse ($) { my ($param, $err, $myjson) = @_; my $hash = $param->{hash}; my $name = $hash->{NAME}; my $camname = $hash->{CAMNAME}; my $apicammaxver = $hash->{HELPER}{APICAMMAXVER}; my ($data,$success,$error,$errorcode,$camid); my ($i,$n,$id); my %allcams; if ($err ne "") { # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist Log3($name, 2, "$name - error while requesting ".$param->{url}." - $err"); readingsSingleUpdate($hash, "Error", $err, 1); return sscam_login($hash,'sscam_getapisites'); } elsif ($myjson ne "") { # wenn die Abfrage erfolgreich war ($data enthält die Ergebnisdaten des HTTP Aufrufes) # evaluiere ob Daten im JSON-Format empfangen wurden, Achtung: sehr viele Daten mit verbose=5 ($hash, $success) = evaljson($hash,$myjson,$param->{url}); unless ($success) { Log3($name, 4, "$name - Data returned: ".$myjson); $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } return; } $data = decode_json($myjson); # lesbare Ausgabe der decodierten JSON-Daten Log3($name, 5, "$name - JSON returned: ". Dumper $data); $success = $data->{'success'}; if ($success) { # die Liste aller Kameras konnte ausgelesen werden, Anzahl der definierten Kameras ist in Var "total" $i = 0; # Namen aller installierten Kameras mit Id's in Assoziatives Array einlesen %allcams = (); while ($data->{'data'}->{'cameras'}->[$i]) { if ($apicammaxver <= 8) { $n = $data->{'data'}->{'cameras'}->[$i]->{'name'}; } else { $n = $data->{'data'}->{'cameras'}->[$i]->{'newName'}; # Änderung ab SVS 8.0.0 } $id = $data->{'data'}->{'cameras'}->[$i]->{'id'}; $allcams{"$n"} = "$id"; $i += 1; } # Ist der gesuchte Kameraname im Hash enhalten (in SVS eingerichtet ?) if (exists($allcams{$camname})) { $camid = $allcams{$camname}; # in hash eintragen $hash->{CAMID} = $camid; # Logausgabe Log3($name, 4, "$name - Detection Camid successful - $camname ID: $camid"); } else { # Kameraname nicht gefunden, id = "" # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","Camera(ID) not found in Surveillance Station"); readingsEndUpdate($hash, 1); # Logausgabe Log3($name, 2, "$name - ERROR - Cameraname $camname wasn't found in Surveillance Station. Check Userrights, Cameraname and Spelling"); $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } return; } } else { # Errorcode aus JSON ermitteln $errorcode = $data->{'error'}->{'code'}; # Fehlertext zum Errorcode ermitteln $error = experror($hash,$errorcode); readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode",$errorcode); readingsBulkUpdate($hash,"Error",$error); readingsEndUpdate($hash, 1); if ($errorcode =~ /(105|401)/) { # neue Login-Versuche Log3($name, 2, "$name - ERROR - $errorcode - $error -> try new login"); return sscam_login($hash,'sscam_getapisites'); } else { # ausgeführte Funktion ist abgebrochen, Freigabe Funktionstoken $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } Log3($name, 2, "$name - ERROR - ID of Camera $camname couldn't be selected. Errorcode: $errorcode - $error"); return; } } } return sscam_camop($hash); } ############################################################################################# # Auswertung installierte Cams, Selektion Cam , Ausführung Operation ############################################################################################# sub sscam_camop ($) { my ($hash) = @_; my $name = $hash->{NAME}; my $serveraddr = $hash->{SERVERADDR}; my $serverport = $hash->{SERVERPORT}; my $apicam = $hash->{HELPER}{APICAM}; my $apicampath = $hash->{HELPER}{APICAMPATH}; my $apicammaxver = $hash->{HELPER}{APICAMMAXVER}; my $apiextrec = $hash->{HELPER}{APIEXTREC}; my $apiextrecpath = $hash->{HELPER}{APIEXTRECPATH}; my $apiextrecmaxver = $hash->{HELPER}{APIEXTRECMAXVER}; my $apiextevt = $hash->{HELPER}{APIEXTEVT}; my $apiextevtpath = $hash->{HELPER}{APIEXTEVTPATH}; my $apiextevtmaxver = $hash->{HELPER}{APIEXTEVTMAXVER}; my $apitakesnap = $hash->{HELPER}{APISNAPSHOT}; my $apitakesnappath = $hash->{HELPER}{APITAKESNAPPATH}; my $apitakesnapmaxver = $hash->{HELPER}{APITAKESNAPMAXVER}; my $apiptz = $hash->{HELPER}{APIPTZ}; my $apiptzpath = $hash->{HELPER}{APIPTZPATH}; my $apiptzmaxver = $hash->{HELPER}{APIPTZMAXVER}; my $apisvsinfo = $hash->{HELPER}{APISVSINFO}; my $apisvsinfopath = $hash->{HELPER}{APISVSINFOPATH}; my $apisvsinfomaxver = $hash->{HELPER}{APISVSINFOMAXVER}; my $apicamevent = $hash->{HELPER}{APICAMEVENT}; my $apicameventpath = $hash->{HELPER}{APICAMEVENTPATH}; my $apicameventmaxver = $hash->{HELPER}{APICAMEVENTMAXVER}; my $apievent = $hash->{HELPER}{APIEVENT}; my $apieventpath = $hash->{HELPER}{APIEVENTPATH}; my $apieventmaxver = $hash->{HELPER}{APIEVENTMAXVER}; my $apivideostm = $hash->{HELPER}{APIVIDEOSTM}; my $apivideostmpath = $hash->{HELPER}{APIVIDEOSTMPATH}; my $apivideostmmaxver = $hash->{HELPER}{APIVIDEOSTMMAXVER}; my $apistm = $hash->{HELPER}{APISTM}; my $apistmpath = $hash->{HELPER}{APISTMPATH}; my $apistmmaxver = $hash->{HELPER}{APISTMMAXVER}; my $sid = $hash->{HELPER}{SID}; my $OpMode = $hash->{OPMODE}; my $camid = $hash->{CAMID}; my ($livestream,$winname,$attr,$room,$param); my ($url,$snapid,$httptimeout,$expmode,$motdetsc); Log3($name, 4, "$name - --- Begin Function $OpMode nonblocking ---"); $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4"; Log3($name, 5, "$name - HTTP-Call will be done with httptimeout-Value: $httptimeout s"); if ($OpMode eq "Start") { $url = "http://$serveraddr:$serverport/webapi/$apiextrecpath?api=$apiextrec&method=Record&version=$apiextrecmaxver&cameraId=$camid&action=start&_sid=\"$sid\""; if($apiextrecmaxver >= 3) { $url = "http://$serveraddr:$serverport/webapi/$apiextrecpath?api=$apiextrec&method=Record&version=$apiextrecmaxver&cameraIds=$camid&action=start&_sid=\"$sid\""; } } elsif ($OpMode eq "Stop") { $url = "http://$serveraddr:$serverport/webapi/$apiextrecpath?api=$apiextrec&method=Record&version=$apiextrecmaxver&cameraId=$camid&action=stop&_sid=\"$sid\""; if($apiextrecmaxver >= 3) { $url = "http://$serveraddr:$serverport/webapi/$apiextrecpath?api=$apiextrec&method=Record&version=$apiextrecmaxver&cameraIds=$camid&action=stop&_sid=\"$sid\""; } } elsif ($OpMode eq "Snap") { # ein Schnappschuß wird ausgelöst $url = "http://$serveraddr:$serverport/webapi/$apitakesnappath?api=\"$apitakesnap\"&dsId=\"0\"&method=\"TakeSnapshot\"&version=\"$apitakesnapmaxver\"&camId=\"$camid\"&blSave=\"true\"&_sid=\"$sid\""; readingsSingleUpdate($hash,"state", "snap", 0); readingsSingleUpdate($hash, "LastSnapId", "", 0); } elsif ($OpMode eq "getsnapfilename") { # der Filename der aktuellen Schnappschuß-ID wird ermittelt $snapid = ReadingsVal("$name", "LastSnapId", " "); $url = "http://$serveraddr:$serverport/webapi/$apitakesnappath?api=\"$apitakesnap\"&method=\"List\"&version=\"$apitakesnapmaxver\"&imgSize=\"0\"&idList=\"$snapid\"&_sid=\"$sid\""; } elsif ($OpMode eq "gopreset") { # Preset wird angefahren $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 "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\""; readingsSingleUpdate($hash,"state", "moving", 0); } elsif ($OpMode eq "goabsptz") { $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"AbsPtz\"&cameraId=\"$camid\"&posX=\"$hash->{HELPER}{GOPTZPOSX}\"&posY=\"$hash->{HELPER}{GOPTZPOSY}\"&_sid=\"$sid\""; readingsSingleUpdate($hash,"state", "moving", 0); } elsif ($OpMode eq "movestart") { $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"Move\"&cameraId=\"$camid\"&direction=\"$hash->{HELPER}{GOMOVEDIR}\"&speed=\"3\"&moveType=\"Start\"&_sid=\"$sid\""; } elsif ($OpMode eq "movestop") { $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"Move\"&cameraId=\"$camid\"&direction=\"$hash->{HELPER}{GOMOVEDIR}\"&moveType=\"Stop\"&_sid=\"$sid\""; } elsif ($OpMode eq "Enable") { $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=$apicam&version=$apicammaxver&method=Enable&cameraIds=$camid&_sid=\"$sid\""; } elsif ($OpMode eq "Disable") { $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=$apicam&version=$apicammaxver&method=Disable&cameraIds=$camid&_sid=\"$sid\""; } elsif ($OpMode eq "Getsvsinfo") { $url = "http://$serveraddr:$serverport/webapi/$apisvsinfopath?api=\"$apisvsinfo\"&version=\"$apisvsinfomaxver\"&method=\"GetInfo\"&_sid=\"$sid\""; } elsif ($OpMode eq "Getcaminfo") { $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&version=\"$apicammaxver\"&method=\"GetInfo\"&cameraIds=\"$camid\"&deviceOutCap=\"true\"&streamInfo=\"true\"&ptz=\"true\"&basic=\"true\"&camAppInfo=\"true\"&optimize=\"true\"&fisheye=\"true\"&eventDetection=\"true\"&_sid=\"$sid\""; } elsif ($OpMode eq "getStmUrlPath") { $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&version=\"$apicammaxver\"&method=\"GetStmUrlPath\"&cameraIds=\"$camid\"&_sid=\"$sid\""; } elsif ($OpMode eq "geteventlist") { # Abruf der Events einer Kamera $url = "http://$serveraddr:$serverport/webapi/$apieventpath?api=\"$apievent\"&version=\"$apieventmaxver\"&method=\"List\"&cameraIds=\"$camid\"&locked=\"0\"&blIncludeSnapshot=\"false\"&reason=\"\"&limit=\"2\"&includeAllCam=\"false\"&_sid=\"$sid\""; } elsif ($OpMode eq "Getptzlistpreset") { $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=$apiptz&version=$apiptzmaxver&method=ListPreset&cameraId=$camid&_sid=\"$sid\""; } elsif ($OpMode eq "Getcapabilities") { # Capabilities einer Cam werden abgerufen $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=$apicam&version=$apicammaxver&method=GetCapabilityByCamId&cameraId=$camid&_sid=\"$sid\""; } elsif ($OpMode eq "Getptzlistpatrol") { # PTZ-ListPatrol werden abgerufen $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=$apiptz&version=$apiptzmaxver&method=ListPatrol&cameraId=$camid&_sid=\"$sid\""; } elsif ($OpMode eq "ExpMode") { if ($hash->{HELPER}{EXPMODE} eq "auto") { $expmode = "0"; } elsif ($hash->{HELPER}{EXPMODE} eq "day") { $expmode = "1"; } elsif ($hash->{HELPER}{EXPMODE} eq "night") { $expmode = "2"; } $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&version=\"$apicammaxver\"&method=\"SaveOptimizeParam\"&cameraIds=\"$camid\"&expMode=\"$expmode\"&camParamChkList=32&_sid=\"$sid\""; } elsif ($OpMode eq "MotDetSc") { # Hash für Optionswerte sichern für Logausgabe in Befehlsauswertung my %motdetoptions = (); if ($hash->{HELPER}{MOTDETSC} eq "disable") { $motdetsc = "-1"; $url = "http://$serveraddr:$serverport/webapi/$apicameventpath?api=\"$apicamevent\"&version=\"$apicameventmaxver\"&method=\"MDParamSave\"&camId=\"$camid\"&source=$motdetsc&keep=true&_sid=\"$sid\""; } elsif ($hash->{HELPER}{MOTDETSC} eq "camera") { $motdetsc = "0"; $motdetoptions{SENSITIVITY} = $hash->{'HELPER'}{'MOTDETSC_PROP1'} if ($hash->{'HELPER'}{'MOTDETSC_PROP1'}); $motdetoptions{OBJECTSIZE} = $hash->{'HELPER'}{'MOTDETSC_PROP2'} if ($hash->{'HELPER'}{'MOTDETSC_PROP2'}); $motdetoptions{PERCENTAGE} = $hash->{'HELPER'}{'MOTDETSC_PROP3'} if ($hash->{'HELPER'}{'MOTDETSC_PROP3'}); $url = "http://$serveraddr:$serverport/webapi/$apicameventpath?api=\"$apicamevent\"&version=\"$apicameventmaxver\"&method=\"MDParamSave\"&camId=\"$camid\"&source=$motdetsc&_sid=\"$sid\""; if ($hash->{HELPER}{MOTDETSC_PROP1} || $hash->{HELPER}{MOTDETSC_PROP2} || $hash->{HELPER}{MOTDETSC_PROP13}) { # umschalten und neue Werte setzen $url .= "&keep=false"; } else { # nur Umschaltung, alte Werte beibehalten $url .= "&keep=true"; } if ($hash->{HELPER}{MOTDETSC_PROP1}) { # der Wert für Bewegungserkennung Kamera -> Empfindlichkeit ist gesetzt my $sensitivity = delete $hash->{HELPER}{MOTDETSC_PROP1}; $url .= "&sensitivity=\"$sensitivity\""; } if ($hash->{HELPER}{MOTDETSC_PROP2}) { # der Wert für Bewegungserkennung Kamera -> Objektgröße ist gesetzt my $objectsize = delete $hash->{HELPER}{MOTDETSC_PROP2}; $url .= "&objectSize=\"$objectsize\""; } if ($hash->{HELPER}{MOTDETSC_PROP3}) { # der Wert für Bewegungserkennung Kamera -> Prozentsatz für Auslösung ist gesetzt my $percentage = delete $hash->{HELPER}{MOTDETSC_PROP3}; $url .= "&percentage=\"$percentage\""; } } elsif ($hash->{HELPER}{MOTDETSC} eq "SVS") { $motdetsc = "1"; $motdetoptions{SENSITIVITY} = $hash->{'HELPER'}{'MOTDETSC_PROP1'} if ($hash->{'HELPER'}{'MOTDETSC_PROP1'}); $motdetoptions{THRESHOLD} = $hash->{'HELPER'}{'MOTDETSC_PROP2'} if ($hash->{'HELPER'}{'MOTDETSC_PROP2'}); # nur Umschaltung, alte Werte beibehalten $url = "http://$serveraddr:$serverport/webapi/$apicameventpath?api=\"$apicamevent\"&version=\"$apicameventmaxver\"&method=\"MDParamSave\"&camId=\"$camid\"&source=$motdetsc&keep=true&_sid=\"$sid\""; if ($hash->{HELPER}{MOTDETSC_PROP1}) { # der Wert für Bewegungserkennung SVS -> Empfindlichkeit ist gesetzt my $sensitivity = delete $hash->{HELPER}{MOTDETSC_PROP1}; $url .= "&sensitivity=\"$sensitivity\""; } if ($hash->{HELPER}{MOTDETSC_PROP2}) { # der Wert für Bewegungserkennung SVS -> Schwellwert ist gesetzt my $threshold = delete $hash->{HELPER}{MOTDETSC_PROP2}; $url .= "&threshold=\"$threshold\""; } } # Optionswerte in Hash sichern für Logausgabe in Befehlsauswertung $hash->{HELPER}{MOTDETOPTIONS} = \%motdetoptions; } elsif ($OpMode eq "getmotionenum") { $url = "http://$serveraddr:$serverport/webapi/$apicameventpath?api=\"$apicamevent\"&version=\"$apicameventmaxver\"&method=\"MotionEnum\"&camId=\"$camid\"&_sid=\"$sid\""; } elsif ($OpMode eq "extevent") { $url = "http://$serveraddr:$serverport/webapi/$apiextevtpath?api=$apiextevt&version=$apiextevtmaxver&method=Trigger&eventId=$hash->{HELPER}{EVENTID}&eventName=$hash->{HELPER}{EVENTID}&_sid=\"$sid\""; } elsif ($OpMode eq "runliveview") { if ($hash->{HELPER}{RUNVIEW} =~ m/live/) { # externe URL $livestream = !AttrVal($name, "livestreamprefix", undef) ? "http://$serveraddr:$serverport" : AttrVal($name, "livestreamprefix", undef); $livestream .= "/webapi/$apivideostmpath?api=$apivideostm&version=$apivideostmmaxver&method=Stream&cameraId=$camid&format=mjpeg&_sid=\"$sid\""; # interne URL $url = "http://$serveraddr:$serverport/webapi/$apivideostmpath?api=$apivideostm&version=$apivideostmmaxver&method=Stream&cameraId=$camid&format=mjpeg&_sid=\"$sid\""; readingsSingleUpdate($hash,"LiveStreamUrl", $livestream, 1) if(AttrVal($name, "showStmInfoFull", undef)); } else { # Abspielen der letzten Aufnahme (EventId) $url = "http://$serveraddr:$serverport/webapi/$apistmpath?api=$apistm&version=$apistmmaxver&method=EventStream&eventId=$hash->{HELPER}{CAMLASTRECID}&_sid=$sid"; } # Liveview-Link in Hash speichern -> Anzeige über SSCam_FWview, in Reading setzen für Linkversand $hash->{HELPER}{LINK} = $url; Log3($name, 4, "$name - Set Streaming-URL: $url"); # livestream sofort in neuem Browsertab öffnen if ($hash->{HELPER}{OPENWINDOW}) { $winname = $name."_view"; $attr = AttrVal($name, "htmlattr", ""); # öffnen streamwindow für die Instanz die "VIEWOPENROOM" oder Attr "room" aktuell geöffnet hat if ($hash->{HELPER}{VIEWOPENROOM}) { $room = $hash->{HELPER}{VIEWOPENROOM}; map {FW_directNotify("FILTER=room=$room", "#FHEMWEB:$_", "window.open ('$url','$winname','$attr')", "")} devspec2array("WEB.*"); } else { map {FW_directNotify("#FHEMWEB:$_", "window.open ('$url','$winname','$attr')", "")} devspec2array("WEB.*"); } } if (ReadingsVal("$name", "Record", "") eq "Start") { readingsSingleUpdate( $hash,"state", "on", 1); } else { readingsSingleUpdate($hash,"state", "off", 1); } $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } return; } Log3($name, 4, "$name - Call-Out now: $url"); $param = { url => $url, timeout => $httptimeout, hash => $hash, method => "GET", header => "Accept: application/json", callback => \&sscam_camop_parse }; HttpUtils_NonblockingGet ($param); } ################################################################################### # Check ob Kameraoperation erfolgreich wie in "OpMOde" definiert # danach Verarbeitung Nutzdaten und weiter zum Logout ################################################################################### sub sscam_camop_parse ($) { my ($param, $err, $myjson) = @_; my $hash = $param->{hash}; my $name = $hash->{NAME}; my $camname = $hash->{CAMNAME}; my $OpMode = $hash->{OPMODE}; my ($rectime,$data,$success); my ($error,$errorcode); my ($snapid,$camLiveMode,$update_time); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst); my ($deviceType,$camStatus); my ($patrolcnt,$patrolid,$patrolname,@patrolkeys,$patrollist); my ($recStatus,$exposuremode,$exposurecontrol); my ($userPriv,$verbose,$motdetsc); my ($sensitivity_camCap,$sensitivity_value,$sensitivity_ssCap); my ($threshold_camCap,$threshold_value,$threshold_ssCap); my ($percentage_camCap,$percentage_value,$percentage_ssCap); my ($objectSize_camCap,$objectSize_value,$objectSize_ssCap); if ($err ne "") { # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist Log3($name, 2, "$name - error while requesting ".$param->{url}." - $err"); readingsSingleUpdate($hash, "Error", $err, 1); # ausgeführte Funktion ist abgebrochen, Freigabe Funktionstoken $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } return; } elsif ($myjson ne "") { # wenn die Abfrage erfolgreich war ($data enthält die Ergebnisdaten des HTTP Aufrufes) # Evaluiere ob Daten im JSON-Format empfangen wurden ($hash, $success) = &evaljson($hash,$myjson,$param->{url}); unless ($success) { Log3($name, 4, "$name - Data returned: ".$myjson); # ausgeführte Funktion ist abgebrochen, Freigabe Funktionstoken $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } return; } $data = decode_json($myjson); # Logausgabe decodierte JSON Daten Log3($name, 5, "$name - JSON returned: ". Dumper $data); $success = $data->{'success'}; if ($success) { # Kameraoperation entsprechend "OpMode" war erfolgreich if ($OpMode eq "Start") { # Die Aufnahmezeit setzen # wird "set on [rectime]" verwendet -> dann [rectime] nutzen, # sonst Attribut "rectime" wenn es gesetzt ist, falls nicht -> "RECTIME_DEF" if (defined($hash->{HELPER}{RECTIME_TEMP})) { $rectime = delete $hash->{HELPER}{RECTIME_TEMP}; } else { if (defined($attr{$name}{rectime}) && AttrVal($name,"rectime", undef) == 0) { $rectime = 0; } else { $rectime = AttrVal($name, "rectime", undef) ? AttrVal($name, "rectime", undef) : $hash->{HELPER}{RECTIME_DEF}; } } if ($rectime == "0") { Log3($name, 3, "$name - Camera $camname endless Recording started - stop it by stop-command !"); } else { if (ReadingsVal("$name", "Record", "Stop") eq "Start") { # Aufnahme läuft schon und wird verlängert Log3($name, 3, "$name - running recording renewed to $rectime s"); } else { Log3($name, 3, "$name - Camera $camname Recording with Recordtime $rectime s started"); } } readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Record","Start"); readingsBulkUpdate($hash,"state","on"); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); if ($rectime != 0) { # Stop der Aufnahme nach Ablauf $rectime, wenn rectime = 0 -> endlose Aufnahme RemoveInternalTimer($hash, "camstoprec"); InternalTimer(gettimeofday()+$rectime, "camstoprec", $hash); } } elsif ($OpMode eq "Stop") { readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Record","Stop"); readingsBulkUpdate($hash,"state","off"); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe Log3($name, 3, "$name - Camera $camname Recording stopped"); # Aktualisierung Eventlist der letzten Aufnahme geteventlist($hash); } elsif ($OpMode eq "ExpMode") { readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe Log3($name, 3, "$name - Camera $camname exposure mode was set to \"$hash->{HELPER}{EXPMODE}\""); } elsif ($OpMode eq "MotDetSc") { readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe my $sensitivity; if ($hash->{HELPER}{MOTDETSC} eq "SVS" && keys %{$hash->{HELPER}{MOTDETOPTIONS}}) { # Optionen für "SVS" sind gesetzt $sensitivity = ($hash->{HELPER}{MOTDETOPTIONS}{SENSITIVITY}) ? ($hash->{HELPER}{MOTDETOPTIONS}{SENSITIVITY}) : "-"; my $threshold = ($hash->{HELPER}{MOTDETOPTIONS}{THRESHOLD}) ? ($hash->{HELPER}{MOTDETOPTIONS}{THRESHOLD}) : "-"; Log3($name, 3, "$name - Camera $camname motion detection source set to \"$hash->{HELPER}{MOTDETSC}\" with options sensitivity: $sensitivity, threshold: $threshold"); } elsif ($hash->{HELPER}{MOTDETSC} eq "camera" && keys %{$hash->{HELPER}{MOTDETOPTIONS}}) { # Optionen für "camera" sind gesetzt $sensitivity = ($hash->{HELPER}{MOTDETOPTIONS}{SENSITIVITY}) ? ($hash->{HELPER}{MOTDETOPTIONS}{SENSITIVITY}) : "-"; my $objectSize = ($hash->{HELPER}{MOTDETOPTIONS}{OBJECTSIZE}) ? ($hash->{HELPER}{MOTDETOPTIONS}{OBJECTSIZE}) : "-"; my $percentage = ($hash->{HELPER}{MOTDETOPTIONS}{PERCENTAGE}) ? ($hash->{HELPER}{MOTDETOPTIONS}{PERCENTAGE}) : "-"; Log3($name, 3, "$name - Camera $camname motion detection source set to \"$hash->{HELPER}{MOTDETSC}\" with options sensitivity: $sensitivity, objectSize: $objectSize, percentage: $percentage"); } else { # keine Optionen Bewegungserkennung wurden gesetzt Log3($name, 3, "$name - Camera $camname motion detection source set to \"$hash->{HELPER}{MOTDETSC}\" "); } } elsif ($OpMode eq "Snap") { # ein Schnapschuß wurde aufgenommen # 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); } $snapid = $data->{data}{'id'}; readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsBulkUpdate($hash,"LastSnapId",$snapid); readingsEndUpdate($hash, 1); # Logausgabe Log3($name, 3, "$name - Snapshot of Camera $camname has been done successfully"); # nach Snap Aufnahme Filename des Snaps ermitteln getsnapfilename($hash); } elsif ($OpMode eq "getsnapfilename") { # den Filenamen eines Schnapschusses ermitteln $snapid = ReadingsVal("$name", "LastSnapId", " "); readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsBulkUpdate($hash,"LastSnapFilename", $data->{'data'}{'data'}[0]{'fileName'}); readingsEndUpdate($hash, 1); # Logausgabe Log3($name, 4, "$name - Filename of Snap-ID $snapid is \"$data->{'data'}{'data'}[0]{'fileName'}\""); } elsif ($OpMode eq "gopreset") { # eine Presetposition wurde angefahren # 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 - Camera $camname has been moved to position \"$hash->{HELPER}{GOPRESETNAME}\""); } elsif ($OpMode eq "runpatrol") { # eine Tour wurde gestartet # 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 - Patrol \"$hash->{HELPER}{GOPATROLNAME}\" of camera $camname has been started successfully"); } elsif ($OpMode eq "goabsptz") { # eine absolute PTZ-Position wurde angefahren # 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 - Camera $camname has been moved to absolute position \"posX=$hash->{HELPER}{GOPTZPOSX}\" and \"posY=$hash->{HELPER}{GOPTZPOSY}\""); } elsif ($OpMode eq "movestart") { # ein "Move" in eine bestimmte Richtung wird durchgeführt readingsBeginUpdate($hash); readingsBulkUpdate($hash,"state","moving"); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe Log3($name, 3, "$name - Camera $camname started move to direction \"$hash->{HELPER}{GOMOVEDIR}\" with duration of $hash->{HELPER}{GOMOVETIME} s"); RemoveInternalTimer($hash, "movestop"); InternalTimer(gettimeofday()+($hash->{HELPER}{GOMOVETIME}), "movestop", $hash); } elsif ($OpMode eq "movestop") { # ein "Move" in eine bestimmte Richtung wurde durchgeführt # 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 - Camera $camname stopped move to direction \"$hash->{HELPER}{GOMOVEDIR}\""); } elsif ($OpMode eq "Enable") { # Kamera wurde aktiviert, sonst kann nichts laufen -> "off" readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Availability","enabled"); readingsBulkUpdate($hash,"state","off"); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe Log3($name, 3, "$name - Camera $camname has been enabled successfully"); } elsif ($OpMode eq "Disable") { # Kamera wurde deaktiviert readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Availability","disabled"); readingsBulkUpdate($hash,"state","disabled"); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe Log3($name, 3, "$name - Camera $camname has been disabled successfully"); } elsif ($OpMode eq "Getsvsinfo") { # Parse SVS-Infos $userPriv = $data->{'data'}{'userPriv'}; if (defined($userPriv)) { if ($userPriv eq "0") { $userPriv = "No Access"; } elsif ($userPriv eq "1") { $userPriv = "Admin"; } elsif ($userPriv eq "2") { $userPriv = "Manager"; } elsif ($userPriv eq "4") { $userPriv = "Viewer"; } } # "my" nicht am Anfang deklarieren, sonst wird Hash %version wieder geleert ! my %version = ( MAJOR => $data->{'data'}{'version'}{'major'}, MINOR => $data->{'data'}{'version'}{'minor'}, SMALL => $data->{'data'}{'version'}{'small'}, BUILD => $data->{'data'}{'version'}{'build'} ); # simulieren einer anderen SVS-Version if (AttrVal($name, "simu_SVSversion", undef)) { Log3($name, 4, "$name - another SVS-version ".AttrVal($name, "simu_SVSversion", undef)." will be simulated"); delete $version{"SMALL"} if ($version{"SMALL"}); my @vl = split (/\.|-/,AttrVal($name, "simu_SVSversion", "")); $version{"MAJOR"} = $vl[0]; $version{"MINOR"} = $vl[1]; $version{"BUILD"} = $vl[2]."-simu" if($vl[2]); } # Werte in $hash zur späteren Auswertung einfügen $hash->{HELPER}{SVSVERSION} = \%version; if (!exists($data->{'data'}{'customizedPortHttp'})) { delete $defs{$name}{READINGS}{SVScustomPortHttp}; } if (!exists($data->{'data'}{'customizedPortHttps'})) { delete $defs{$name}{READINGS}{SVScustomPortHttps}; } # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"SVScustomPortHttp",$data->{'data'}{'customizedPortHttp'}); readingsBulkUpdate($hash,"SVScustomPortHttps",$data->{'data'}{'customizedPortHttps'}); readingsBulkUpdate($hash,"SVSlicenseNumber",$data->{'data'}{'liscenseNumber'}); readingsBulkUpdate($hash,"SVSuserPriv",$userPriv); if($version{"SMALL"}) { readingsBulkUpdate($hash,"SVSversion",$version{"MAJOR"}.".".$version{"MINOR"}.".".$version{"SMALL"}."-".$version{"BUILD"}); } else { readingsBulkUpdate($hash,"SVSversion",$version{"MAJOR"}.".".$version{"MINOR"}."-".$version{"BUILD"}); } readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe Log3($name, 3, "$name - Informations related to Surveillance Station retrieved successfully"); } elsif ($OpMode eq "getStmUrlPath") { # Parse SVS-Infos my $camforcemcast = $data->{'data'}{'pathInfos'}[0]{'forceEnableMulticast'}; my $mjpegHttp = $data->{'data'}{'pathInfos'}[0]{'mjpegHttpPath'}; my $multicst = $data->{'data'}{'pathInfos'}[0]{'multicstPath'}; my $mxpegHttp = $data->{'data'}{'pathInfos'}[0]{'mxpegHttpPath'}; my $unicastOverHttp = $data->{'data'}{'pathInfos'}[0]{'unicastOverHttpPath'}; my $unicastPath = $data->{'data'}{'pathInfos'}[0]{'unicastPath'}; # Rewrite Url's falls livestreamprefix ist gesetzt if (AttrVal($name, "livestreamprefix", undef)) { my @mjh = split(/\//, $mjpegHttp, 4); $mjpegHttp = AttrVal($name, "livestreamprefix", undef)."/".$mjh[3]; my @mxh = split(/\//, $mxpegHttp, 4); $mxpegHttp = AttrVal($name, "livestreamprefix", undef)."/".$mxh[3]; my @ucp = split(/[@\|:]/, $unicastPath); my @lspf = split(/[\/\/\|:]/, AttrVal($name, "livestreamprefix", undef)); $unicastPath = $ucp[0].":".$ucp[1].":".$ucp[2]."@".$lspf[3].":".$ucp[4]; } # StmKey extrahieren my @sk = split(/&StmKey=/, $mjpegHttp); my $stmkey = $sk[1]; $stmkey =~ tr/"//d; # Readings löschen falls sie nicht angezeigt werden sollen (showStmInfoFull) if (!AttrVal($name, "showStmInfoFull", undef)) { delete($defs{$name}{READINGS}{StmKeymjpegHttp}) if ($defs{$name}{READINGS}{StmKeymjpegHttp}); delete($defs{$name}{READINGS}{StmKeyUnicst}) if ($defs{$name}{READINGS}{StmKeyUnicst}); } readingsBeginUpdate($hash); readingsBulkUpdate($hash,"CamForceEnableMulticast",$camforcemcast); readingsBulkUpdate($hash,"StmKey",$stmkey); readingsBulkUpdate($hash,"StmKeymjpegHttp",$mjpegHttp) if (AttrVal($name, "showStmInfoFull", undef)); # readingsBulkUpdate($hash,"StmKeymxpegHttp",$mxpegHttp); readingsBulkUpdate($hash,"StmKeyUnicst",$unicastPath) if (AttrVal($name, "showStmInfoFull", undef)); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe Log3($name, 4, "$name - Stream-URLs of $camname retrieved successfully"); } elsif ($OpMode eq "Getcaminfo") { # Parse Caminfos $camLiveMode = $data->{'data'}->{'cameras'}->[0]->{'camLiveMode'}; if ($camLiveMode eq "0") {$camLiveMode = "Liveview from DS";}elsif ($camLiveMode eq "1") {$camLiveMode = "Liveview from Camera";} # $update_time = $data->{'data'}->{'cameras'}->[0]->{'update_time'}; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; $update_time = sprintf "%02d.%02d.%04d / %02d:%02d:%02d" , $mday , $mon+=1 ,$year+=1900 , $hour , $min , $sec ; $deviceType = $data->{'data'}->{'cameras'}->[0]->{'deviceType'}; if ($deviceType eq "1") { $deviceType = "Camera"; } elsif ($deviceType eq "2") { $deviceType = "Video_Server"; } elsif ($deviceType eq "4") { $deviceType = "PTZ"; } elsif ($deviceType eq "8") { $deviceType = "Fisheye"; } $camStatus = $data->{'data'}->{'cameras'}->[0]->{'camStatus'}; if ($camStatus eq "1") { $camStatus = "enabled"; # 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); } } elsif ($camStatus eq "3") { $camStatus = "disconnected"; readingsSingleUpdate($hash,"state", "disconnected", 0); } elsif ($camStatus eq "7") { $camStatus = "disabled"; readingsSingleUpdate($hash,"state", "disabled", 0); } else { $camStatus = "other"; } $recStatus = $data->{'data'}->{'cameras'}->[0]->{'recStatus'}; if ($recStatus ne "0") { $recStatus = "Start"; } else { $recStatus = "Stop"; } $exposuremode = $data->{'data'}->{'cameras'}->[0]->{'exposure_mode'}; if ($exposuremode == 0) { $exposuremode = "Auto"; } elsif ($exposuremode == 1) { $exposuremode = "Day"; } elsif ($exposuremode == 2) { $exposuremode = "Night"; } elsif ($exposuremode == 3) { $exposuremode = "Schedule"; } elsif ($exposuremode == 4) { $exposuremode = "Unknown"; } $exposurecontrol = $data->{'data'}->{'cameras'}->[0]->{'exposure_control'}; if ($exposurecontrol == 0) { $exposurecontrol = "Auto"; } elsif ($exposurecontrol == 1) { $exposurecontrol = "50HZ"; } elsif ($exposurecontrol == 2) { $exposurecontrol = "60HZ"; } elsif ($exposurecontrol == 3) { $exposurecontrol = "Hold"; } elsif ($exposurecontrol == 4) { $exposurecontrol = "Outdoor"; } elsif ($exposurecontrol == 5) { $exposurecontrol = "None"; } elsif ($exposurecontrol == 6) { $exposurecontrol = "Unknown"; } # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"CamLiveMode",$camLiveMode); readingsBulkUpdate($hash,"CamExposureMode",$exposuremode); readingsBulkUpdate($hash,"CamExposureControl",$exposurecontrol); readingsBulkUpdate($hash,"CamModel",$data->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camModel'}); readingsBulkUpdate($hash,"CamRecShare",$data->{'data'}->{'cameras'}->[0]->{'camRecShare'}); readingsBulkUpdate($hash,"CamRecVolume",$data->{'data'}->{'cameras'}->[0]->{'camRecVolume'}); readingsBulkUpdate($hash,"CamIP",$data->{'data'}->{'cameras'}->[0]->{'host'}); readingsBulkUpdate($hash,"CamVendor",$data->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camVendor'}); readingsBulkUpdate($hash,"CamPreRecTime",$data->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camPreRecTime'}); readingsBulkUpdate($hash,"CamPort",$data->{'data'}->{'cameras'}->[0]->{'port'}); readingsBulkUpdate($hash,"CamPtSpeed",$data->{'data'}->{'cameras'}->[0]->{'ptSpeed'}); readingsBulkUpdate($hash,"CamblPresetSpeed",$data->{'data'}->{'cameras'}->[0]->{'blPresetSpeed'}); readingsBulkUpdate($hash,"CamVideoMirror",$data->{'data'}->{'cameras'}->[0]->{'video_mirror'}); readingsBulkUpdate($hash,"CamVideoFlip",$data->{'data'}->{'cameras'}->[0]->{'video_flip'}); readingsBulkUpdate($hash,"Availability",$camStatus); readingsBulkUpdate($hash,"DeviceType",$deviceType); readingsBulkUpdate($hash,"LastUpdateTime",$update_time); readingsBulkUpdate($hash,"Record",$recStatus); readingsBulkUpdate($hash,"UsedSpaceMB",$data->{'data'}->{'cameras'}->[0]->{'volume_space'}); readingsBulkUpdate($hash,"VideoFolder",AttrVal($name, "videofolderMap", undef) ? AttrVal($name, "videofolderMap", undef) : $data->{'data'}->{'cameras'}->[0]->{'folder'}); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe # wenn "pollnologging" = 1 -> logging nur bei Verbose=4, sonst 3 if (defined($attr{$name}{pollnologging}) and $attr{$name}{pollnologging} eq "1") { $verbose = 4; } else { $verbose = 3; } Log3($name, $verbose, "$name - Camera-Informations of $camname retrieved"); } elsif ($OpMode eq "geteventlist") { my $eventnum = $data->{'data'}{'total'}; my $lastrecord = $data->{'data'}{'events'}[0]{name}; $hash->{HELPER}{CAMLASTRECID} = $data->{'data'}{'events'}[0]{'eventId'}; my ($lastrecstarttime,$lastrecstoptime); if ($eventnum > 0) { $lastrecstarttime = $data->{'data'}{'events'}[0]{startTime}; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($lastrecstarttime); $lastrecstarttime = sprintf "%02d.%02d.%04d / %02d:%02d:%02d" , $mday , $mon+=1 ,$year+=1900 , $hour , $min , $sec ; $lastrecstoptime = $data->{'data'}{'events'}[0]{stopTime}; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($lastrecstoptime); $lastrecstoptime = sprintf "%02d:%02d:%02d" , $hour , $min , $sec ; } # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"CamEventNum",$eventnum); readingsBulkUpdate($hash,"CamLastRec",$lastrecord); if ($lastrecstarttime) {readingsBulkUpdate($hash,"CamLastRecTime",$lastrecstarttime." - ". $lastrecstoptime);} readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe # wenn "pollnologging" = 1 -> logging nur bei Verbose=4, sonst 3 if (defined($attr{$name}{pollnologging}) and $attr{$name}{pollnologging} eq "1") { $verbose = 4; } else { $verbose = 3; } Log3($name, $verbose, "$name - Query event list of $camname successfully done"); } elsif ($OpMode eq "getmotionenum") { $motdetsc = $data->{'data'}{'MDParam'}{'source'}; $sensitivity_camCap = $data->{'data'}{'MDParam'}{'sensitivity'}{'camCap'}; $sensitivity_value = $data->{'data'}{'MDParam'}{'sensitivity'}{'value'}; $sensitivity_ssCap = $data->{'data'}{'MDParam'}{'sensitivity'}{'ssCap'}; $threshold_camCap = $data->{'data'}{'MDParam'}{'threshold'}{'camCap'}; $threshold_value = $data->{'data'}{'MDParam'}{'threshold'}{'value'}; $threshold_ssCap = $data->{'data'}{'MDParam'}{'threshold'}{'ssCap'}; $percentage_camCap = $data->{'data'}{'MDParam'}{'percentage'}{'camCap'}; $percentage_value = $data->{'data'}{'MDParam'}{'percentage'}{'value'}; $percentage_ssCap = $data->{'data'}{'MDParam'}{'percentage'}{'ssCap'}; $objectSize_camCap = $data->{'data'}{'MDParam'}{'objectSize'}{'camCap'}; $objectSize_value = $data->{'data'}{'MDParam'}{'objectSize'}{'value'}; $objectSize_ssCap = $data->{'data'}{'MDParam'}{'objectSize'}{'ssCap'}; if ($motdetsc == -1) { $motdetsc = "disabled"; } elsif ($motdetsc == 0) { $motdetsc = "Camera"; if ($sensitivity_camCap) { $motdetsc .= ", sensitivity: $sensitivity_value"; } if ($threshold_camCap) { $motdetsc .= ", threshold: $threshold_value"; } if ($percentage_camCap) { $motdetsc .= ", percentage: $percentage_value"; } if ($objectSize_camCap) { $motdetsc .= ", objectSize: $objectSize_value"; } } elsif ($motdetsc == 1) { $motdetsc = "SVS"; if ($sensitivity_ssCap) { $motdetsc .= ", sensitivity: $sensitivity_value"; } if ($threshold_ssCap) { $motdetsc .= ", threshold: $threshold_value"; } if ($percentage_ssCap) { $motdetsc .= ", percentage: $percentage_value"; } if ($objectSize_ssCap) { $motdetsc .= ", objectSize: $objectSize_value"; } } # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"CamMotDetSc",$motdetsc); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe # wenn "pollnologging" = 1 -> logging nur bei Verbose=4, sonst 2 if (defined($attr{$name}{pollnologging}) and $attr{$name}{pollnologging} eq "1") { $verbose = 4; } else { $verbose = 3; } Log3($name, $verbose, "$name - Enumerate motion detection parameters of $camname successfully done"); } elsif ($OpMode eq "Getcapabilities") { # Parse Infos my $ptzfocus = $data->{'data'}{'ptzFocus'}; if ($ptzfocus eq "0") { $ptzfocus = "false"; } elsif ($ptzfocus eq "1") { $ptzfocus = "support step operation"; } elsif ($ptzfocus eq "2") { $ptzfocus = "support continuous operation"; } my $ptztilt = $data->{'data'}{'ptzTilt'}; if ($ptztilt eq "0") { $ptztilt = "false"; } elsif ($ptztilt eq "1") { $ptztilt = "support step operation"; } elsif ($ptztilt eq "2") { $ptztilt = "support continuous operation"; } my $ptzzoom = $data->{'data'}{'ptzZoom'}; if ($ptzzoom eq "0") { $ptzzoom = "false"; } elsif ($ptzzoom eq "1") { $ptzzoom = "support step operation"; } elsif ($ptzzoom eq "2") { $ptzzoom = "support continuous operation"; } my $ptzpan = $data->{'data'}{'ptzPan'}; if ($ptzpan eq "0") { $ptzpan = "false"; } elsif ($ptzpan eq "1") { $ptzpan = "support step operation"; } elsif ($ptzpan eq "2") { $ptzpan = "support continuous operation"; } my $ptziris = $data->{'data'}{'ptzIris'}; if ($ptziris eq "0") { $ptziris = "false"; } elsif ($ptziris eq "1") { $ptziris = "support step operation"; } elsif ($ptziris eq "2") { $ptziris = "support continuous operation"; } # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"CapPTZAutoFocus",$data->{'data'}{'ptzAutoFocus'}); readingsBulkUpdate($hash,"CapAudioOut",$data->{'data'}{'audioOut'}); readingsBulkUpdate($hash,"CapChangeSpeed",$data->{'data'}{'ptzSpeed'}); readingsBulkUpdate($hash,"CapPTZHome",$data->{'data'}{'ptzHome'}); readingsBulkUpdate($hash,"CapPTZAbs",$data->{'data'}{'ptzAbs'}); readingsBulkUpdate($hash,"CapPTZDirections",$data->{'data'}{'ptzDirection'}); readingsBulkUpdate($hash,"CapPTZFocus",$ptzfocus); readingsBulkUpdate($hash,"CapPTZIris",$ptziris); readingsBulkUpdate($hash,"CapPTZPan",$ptzpan); readingsBulkUpdate($hash,"CapPTZTilt",$ptztilt); readingsBulkUpdate($hash,"CapPTZZoom",$ptzzoom); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe # wenn "pollnologging" = 1 -> logging nur bei Verbose=4, sonst 2 if (defined(AttrVal($name, "pollnologging", undef)) and AttrVal($name, "pollnologging", undef) eq "1") { $verbose = 4; } else { $verbose = 3; } Log3($name, $verbose, "$name - Capabilities of Camera $camname retrieved"); } elsif ($OpMode eq "Getptzlistpreset") { # Parse PTZ-ListPresets my $presetcnt = $data->{'data'}->{'total'}; my $cnt = 0; # alle Presets der Kamera mit Id's in Assoziatives Array einlesen # "my" nicht am Anfang deklarieren, sonst wird Hash %allpresets wieder geleert ! my %allpresets; while ($cnt < $presetcnt) { # my $presid = $data->{'data'}->{'presets'}->[$cnt]->{'id'}; my $presid = $data->{'data'}->{'presets'}->[$cnt]->{'position'}; my $presname = $data->{'data'}->{'presets'}->[$cnt]->{'name'}; $allpresets{$presname} = "$presid"; $cnt += 1; } # Presethash in $hash einfügen $hash->{HELPER}{ALLPRESETS} = \%allpresets; my @preskeys = sort(keys(%allpresets)); my $presetlist = join(",",@preskeys); # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Presets",$presetlist); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe # wenn "pollnologging" = 1 -> logging nur bei Verbose=4, sonst 2 if (defined(AttrVal($name, "pollnologging", undef)) and AttrVal($name, "pollnologging", undef) eq "1") { $verbose = 4; } else { $verbose = 3; } Log3($name, $verbose, "$name - PTZ Presets of $camname retrieved"); } elsif ($OpMode eq "Getptzlistpatrol") { # Parse PTZ-ListPatrols $patrolcnt = $data->{'data'}->{'total'}; my $cnt = 0; # alle Patrols der Kamera mit Id's in Assoziatives Array einlesen # "my" nicht am Anfang deklarieren, sonst wird Hash %allpatrols wieder geleert ! my %allpatrols = (); while ($cnt < $patrolcnt) { $patrolid = $data->{'data'}->{'patrols'}->[$cnt]->{'id'}; $patrolname = $data->{'data'}->{'patrols'}->[$cnt]->{'name'}; $allpatrols{$patrolname} = $patrolid; $cnt += 1; } # Presethash in $hash einfügen $hash->{HELPER}{ALLPATROLS} = \%allpatrols; @patrolkeys = sort(keys(%allpatrols)); $patrollist = join(",",@patrolkeys); # print "ID von Tour1 ist : ". %allpatrols->{Tour1}; # print "aus Hash: ".$hash->{HELPER}{ALLPRESETS}{Tour1}; readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Patrols",$patrollist); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe # wenn "pollnologging" = 1 -> logging nur bei Verbose=4, sonst 2 if (defined(AttrVal($name, "pollnologging", undef)) and AttrVal($name, "pollnologging", undef) eq "1") { $verbose = 4; } else { $verbose = 3; } Log3($name, $verbose, "$name - PTZ Patrols of $camname retrieved"); } } else { # die API-Operation war fehlerhaft # Errorcode aus JSON ermitteln $errorcode = $data->{'error'}->{'code'}; # Fehlertext zum Errorcode ermitteln $error = experror($hash,$errorcode); if ($errorcode =~ /(105|401)/) { Log3($name, 2, "$name - ERROR - $errorcode - $error in operation $OpMode -> try new login"); return sscam_login($hash,'sscam_getapisites'); } # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode",$errorcode); readingsBulkUpdate($hash,"Error",$error); readingsEndUpdate($hash, 1); # Logausgabe Log3($name, 2, "$name - ERROR - Operation $OpMode of Camera $camname was not successful. Errorcode: $errorcode - $error"); } } $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } return; } ############################################################################################################################# ######### Ende Kameraoperationen mit NonblockingGet (nicht blockierender HTTP-Call) ############# ############################################################################################################################# ############################################################################################################################# ######### Hilfsroutinen ############# ############################################################################################################################# #################################################################################### # Login in SVS wenn kein oder ungültige Session-ID vorhanden ist sub sscam_login ($;$$) { my ($hash,$fret) = @_; my $name = $hash->{NAME}; my $serveraddr = $hash->{SERVERADDR}; my $serverport = $hash->{SERVERPORT}; my $apiauth = $hash->{HELPER}{APIAUTH}; my $apiauthpath = $hash->{HELPER}{APIAUTHPATH}; my $apiauthmaxver = $hash->{HELPER}{APIAUTHMAXVER}; my $lrt = AttrVal($name,"loginRetries",3); my ($url,$param); delete $hash->{HELPER}{SID} if($hash->{HELPER}{SID}); # Login und SID ermitteln Log3($name, 4, "$name - --- Begin Function sscam_login ---"); # Credentials abrufen my ($success, $username, $password) = getcredentials($hash,0); unless ($success) { Log3($name, 2, "$name - Credentials couldn't be retrieved successfully - make sure you've set it with \"set $name credentials \""); $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } return; } if($hash->{HELPER}{LOGINRETRIES} >= $lrt) { # login wird abgebrochen, Freigabe Funktionstoken $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } Log3($name, 2, "$name - ERROR - Login of User $username unsuccessful"); return; } my $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4"; Log3($name, 5, "$name - HTTP-Call login will be done with httptimeout-Value: $httptimeout s"); my $urlwopw; # nur zur Anzeige bei verbose >= 4 und "showPassInLog" == 0 # sid in Quotes einschliessen oder nicht -> bei Problemen mit 402 - Permission denied my $sid = AttrVal($name, "noQuotesForSID", "0") == 1 ? "sid" : "\"sid\""; if (defined($attr{$name}{session}) and $attr{$name}{session} eq "SurveillanceStation") { $url = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Login&account=$username&passwd=$password&session=SurveillanceStation&format=$sid"; $urlwopw = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Login&account=$username&passwd=*****&session=SurveillanceStation&format=$sid"; } else { $url = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Login&account=$username&passwd=$password&format=$sid"; $urlwopw = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Login&account=$username&passwd=*****&format=$sid"; } AttrVal($name, "showPassInLog", "0") == 1 ? Log3($name, 4, "$name - Call-Out now: $url") : Log3($name, 4, "$name - Call-Out now: $urlwopw"); $hash->{HELPER}{LOGINRETRIES}++; $param = { url => $url, timeout => $httptimeout, hash => $hash, user => $username, funcret => $fret, method => "GET", header => "Accept: application/json", callback => \&sscam_login_return }; HttpUtils_NonblockingGet ($param); } sub sscam_login_return ($) { my ($param, $err, $myjson) = @_; my $hash = $param->{hash}; my $name = $hash->{NAME}; my $username = $param->{user}; my $fret = $param->{funcret}; my $subref = \&$fret if($fret); my $success; # Verarbeitung der asynchronen Rückkehrdaten aus sub "login_nonbl" if ($err ne "") { # ein Fehler bei der HTTP Abfrage ist aufgetreten Log3($name, 2, "$name - error while requesting ".$param->{url}." - $err"); readingsSingleUpdate($hash, "Error", $err, 1); return sscam_login($hash); } elsif ($myjson ne "") { # wenn die Abfrage erfolgreich war ($data enthält die Ergebnisdaten des HTTP Aufrufes) # Evaluiere ob Daten im JSON-Format empfangen wurden ($hash, $success) = evaljson($hash,$myjson,$param->{url}); unless ($success) { Log3($name, 4, "$name - no JSON-Data returned: ".$myjson); $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } return; } my $data = decode_json($myjson); # Logausgabe decodierte JSON Daten Log3($name, 5, "$name - JSON decoded: ". Dumper $data); $success = $data->{'success'}; if ($success) { # login war erfolgreich my $sid = $data->{'data'}->{'sid'}; # Session ID in hash eintragen $hash->{HELPER}{SID} = $sid; # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","none"); readingsEndUpdate($hash, 1); # Logausgabe Log3($name, 4, "$name - Login of User $username successful - SID: $sid"); } else { # Errorcode aus JSON ermitteln my $errorcode = $data->{'error'}->{'code'}; # Fehlertext zum Errorcode ermitteln my $error = experrorauth($hash,$errorcode); # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode",$errorcode); readingsBulkUpdate($hash,"Error",$error); readingsEndUpdate($hash, 1); # Logausgabe Log3($name, 3, "$name - Login of User $username unsuccessful. Code: $errorcode - $error - try again"); return sscam_login($hash,$fret) if($fret); return sscam_login($hash); } } return &$subref($hash); } ################################################################################### # Funktion logout sub logout_nonbl ($) { my ($hash) = @_; my $name = $hash->{NAME}; my $serveraddr = $hash->{SERVERADDR}; my $serverport = $hash->{SERVERPORT}; my $apiauth = $hash->{HELPER}{APIAUTH}; my $apiauthpath = $hash->{HELPER}{APIAUTHPATH}; my $apiauthmaxver = $hash->{HELPER}{APIAUTHMAXVER}; my $sid = $hash->{HELPER}{SID}; my $url; my $param; my $httptimeout; # logout wird ausgeführt, Rückkehr wird mit "logoutret_nonbl" verarbeitet Log3($name, 4, "$name - --- Begin Function logout nonblocking ---"); $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4"; Log3($name, 5, "$name - HTTP-Call will be done with httptimeout-Value: $httptimeout s"); if (defined($attr{$name}{session}) and $attr{$name}{session} eq "SurveillanceStation") { $url = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Logout&session=SurveillanceStation&_sid=$sid"; } else { $url = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Logout&_sid=$sid"; } $param = { url => $url, timeout => $httptimeout, hash => $hash, method => "GET", header => "Accept: application/json", callback => \&logout_return }; HttpUtils_NonblockingGet ($param); } sub logout_return ($) { my ($param, $err, $myjson) = @_; my $hash = $param->{hash}; my $name = $hash->{NAME}; my $sid = $hash->{HELPER}{SID}; my ($success, $username) = getcredentials($hash,0); my $OpMode = $hash->{OPMODE}; my $data; my $error; my $errorcode; if($err ne "") { # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist Log3($name, 2, "$name - error while requesting ".$param->{url}." - $err"); readingsSingleUpdate($hash, "Error", $err, 1); } elsif($myjson ne "") { # wenn die Abfrage erfolgreich war ($data enthält die Ergebnisdaten des HTTP Aufrufes) Log3($name, 4, "$name - URL-Call: ".$param->{url}); # Evaluiere ob Daten im JSON-Format empfangen wurden ($hash, $success) = &evaljson($hash,$myjson,$param->{url}); unless ($success) { Log3($name, 4, "$name - Data returned: ".$myjson); $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } return; } $data = decode_json($myjson); # Logausgabe decodierte JSON Daten Log3($name, 4, "$name - JSON returned: ". Dumper $data); $success = $data->{'success'}; if ($success) { # die Logout-URL konnte erfolgreich aufgerufen werden # Session-ID aus Helper-hash löschen delete $hash->{HELPER}{SID}; # Logausgabe Log3($name, 4, "$name - Session of User $username has ended - SID: $sid has been deleted"); } else { # Errorcode aus JSON ermitteln $errorcode = $data->{'error'}->{'code'}; # Fehlertext zum Errorcode ermitteln $error = &experrorauth($hash,$errorcode); # Logausgabe Log3($name, 2, "$name - ERROR - Logout of User $username was not successful. Errorcode: $errorcode - $error"); } } # ausgeführte Funktion ist erledigt (auch wenn logout nicht erfolgreich), Freigabe Funktionstoken $hash->{HELPER}{ACTIVE} = "off"; if ($attr{$name}{debugactivetoken}) { Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}"); } return; } ############################################################################### # Test ob JSON-String empfangen wurde sub evaljson { my ($hash,$myjson,$url)= @_; my $success = 1; my $e; eval {decode_json($myjson)} or do { $success = 0; $e = $@; # Setreading readingsBeginUpdate($hash); readingsBulkUpdate($hash,"Errorcode","none"); readingsBulkUpdate($hash,"Error","malformed JSON string received"); readingsEndUpdate($hash, 1); }; return($hash,$success); } ############################################################################## # Auflösung Errorcodes bei Login / Logout sub experrorauth { # Übernahmewerte sind $hash, $errorcode my ($hash,@errorcode) = @_; my $device = $hash->{NAME}; my $errorcode = shift @errorcode; my $error; unless (exists($SSCam_errauthlist{"$errorcode"})) {$error = "Message of errorcode \"$errorcode\" not found. Please turn to Synology Web API-Guide."; return ($error);} # Fehlertext aus Hash-Tabelle %errorauthlist ermitteln $error = $SSCam_errauthlist{"$errorcode"}; return ($error); } ############################################################################## # Auflösung Errorcodes SVS API sub experror { # Übernahmewerte sind $hash, $errorcode my ($hash,@errorcode) = @_; my $device = $hash->{NAME}; my $errorcode = shift @errorcode; my $error; unless (exists($SSCam_errlist{"$errorcode"})) {$error = "Message of errorcode $errorcode not found. Please turn to Synology Web API-Guide."; return ($error);} # Fehlertext aus Hash-Tabelle %errorlist ermitteln $error = $SSCam_errlist{"$errorcode"}; return ($error); } 1; =pod =item summary operates surveillance cameras defined in Synology Surveillance Station =item summary_DE steuert Kameras welche der Synology Surveillance Station =begin html

SSCam

    Using this Module you are able to operate cameras which are defined in Synology Surveillance Station (SVS).
    At present the following functions are available:

      • Start a Recording
      • Stop a Recording (using command or automatically after the <RecordTime> period
      • Trigger a Snapshot
      • Deaktivate a Camera in Synology Surveillance Station
      • Activate a Camera in Synology Surveillance Station
      • Control of the exposure modes day, night and automatic
      • switchover the motion detection by camera, by SVS or to deactivate
      • control of motion detection parameters sensitivity, threshold, object size and percentage for release
      • Retrieval of Camera Properties (also by Polling) as well as informations about the installed SVS-package
      • Move to a predefined Preset-position (at PTZ-cameras)
      • Start a predefined Patrol (at PTZ-cameras)
      • Positioning of PTZ-cameras to absolute X/Y-coordinates
      • continuous moving of PTZ-camera lense
      • trigger of external events 1-10 (action rules in SVS)
      • start and stop of camera livestreams
      • fetch of livestream-Url's with key (login not needed in that case)
      • playback of last recording

    The recordings and snapshots will be stored in Synology Surveillance Station (SVS) and are managed like the other (normal) recordings / snapshots defined by Surveillance Station rules.
    For example the recordings are stored for a defined time in Surveillance Station and will be deleted after that period.

    If you like to discuss or help to improve this module please use FHEM-Forum with link:
    49_SSCam: Fragen, Hinweise, Neuigkeiten und mehr rund um dieses Modul.

    Prerequisites

    This module uses the CPAN-module JSON. Please consider to install this package (Debian: libjson-perl).
    SSCam is completely using the nonblocking functions of HttpUtils respectively HttpUtils_NonblockingGet.
    In DSM respectively in Synology Surveillance Station an User has to be created. The login credentials are needed later when using a set-command to assign the login-data to a device.
    Further informations could be find among Credentials.

    Overview which Perl-modules SSCam is using:

    JSON
    Data::Dumper
    MIME::Base64
    Time::HiRes
    HttpUtils (FHEM-module)

    Define

      define <name> SSCAM <Cameraname in SVS> <ServerAddr> [Port]

      Defines a new camera device for SSCam. At first the devices have to be set up and operable in Synology Surveillance Station 7.0 and above.

      The Modul SSCam ist based on functions of Synology Surveillance Station API.
      Please refer the Web API Guide.

      Currently only HTTP-protocol is supported to call Synology DS.

      The parameters are in detail:

      name: the name of the new device to use in FHEM
      Cameraname: Cameraname as defined in Synology Surveillance Station, Spaces are not allowed in Cameraname !
      ServerAddr: IP-address of Synology Surveillance Station Host. Note: avoid using hostnames because of DNS-Calls are not unblocking in FHEM
      Port: optional - the port of synology surveillance station, if not set the default of 5000 (HTTP only) is used


      Example:
            define CamCP SSCAM Carport 192.168.2.20 [5000]  
          
      When a new Camera is defined, as a start the recordingtime of 15 seconds will be assigned to the device.
      Using the attribute "rectime" you can adapt the recordingtime for every camera individually.
      The value of "0" for rectime will lead to an endless recording which has to be stopped by a "set <name> off" command.
      Due to a Log-Entry with a hint to that circumstance will be written.

      If the attribute "rectime" would be deleted again, the default-value for recording-time (15s) become active.

      With command "set <name> on [rectime]" a temporary recordingtime is determinded which would overwrite the dafault-value of recordingtime
      and the attribute "rectime" (if it is set) uniquely.

      In that case the command "set <name> on 0" leads also to an endless recording as well.

      If you have specified a pre-recording time in SVS it will be considered too.


      Credentials

      After a camera-device is defined, firstly it is needed to save the credentials. This will be done with command:
       
           set <name> credentials <username> <password>
          
      The operator can, dependend on what functions are planned to execute, create an user in DSM respectively in Synology Surveillance Station as well.
      If the user is member of admin-group, he has access to all module functions. Without this membership the user can only execute functions with lower need of rights.
      The required minimum rights to execute functions are listed in a table further down.
      Alternatively to DSM-user a user created in SVS can be used. Also in that case a user of type "manager" has the right to execute all functions,
      whereat the access to particular cameras can be restricted by the privilege profile (please see help function in SVS for details).
      As best practice it is proposed to create an user in DSM as well as in SVS too:

      • DSM-User as member of admin group: unrestricted test of all module functions -> session: DSM
      • SVS-User as Manager or observer: adjusted privilege profile -> session: SurveillanceStation

      Using the Attribute "session" can be selected, if the session should be established to DSM or the SVS instead.
      If the session will be established to DSM, SVS Web-API methods are available as well as further API methods of other API's what possibly needed for processing.

      After device definition the default is "login to DSM", that means credentials with admin rights can be used to test all camera-functions firstly.
      After this the credentials can be switched to a SVS-session with a restricted privilege profile as needed on dependency what module functions are want to be executed.

      The following list shows the minimum rights what the particular module function needs.

      • set ... on
      • session: ServeillanceStation - observer with enhanced privilege "manual recording"
      • set ... off
      • session: ServeillanceStation - observer with enhanced privilege "manual recording"
      • set ... snap
      • session: ServeillanceStation - observer
      • set ... disable
      • session: ServeillanceStation - manager
      • set ... enable
      • session: ServeillanceStation - manager
      • set ... expmode
      • session: ServeillanceStation - manager
      • set ... motdetsc
      • session: ServeillanceStation - manager
      • set ... goPreset
      • session: ServeillanceStation - observer with privilege objective control of camera
      • set ... runPatrol
      • session: ServeillanceStation - observer with privilege objective control of camera
      • 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 ... extevent
      • session: DSM - user as member of admin-group
      • set ... stopView
      • -
      • set ... credentials
      • -
      • get ... caminfoall
      • session: ServeillanceStation - observer
      • get ... eventlist
      • session: ServeillanceStation - observer
      • get ... scanVirgin
      • session: ServeillanceStation - observer
      • get ... svsinfo
      • session: ServeillanceStation - observer
      • get ... snapfileinfo
      • session: ServeillanceStation - observer
      • get ... stmUrlPath
      • session: ServeillanceStation - observer


      HTTP-Timeout Settings

      All functions of SSCam use HTTP-calls to SVS Web API.
      The default-value of HTTP-Timeout amounts 4 seconds. You can set the attribute "httptimeout" > 0 to adjust the value as needed in your technical environment.



    Set
      Currently there are the following options for "Set <name> ..." :

      "on [rectime]": starts a recording. The recording will be stopped automatically after a period of [rectime]
      if [rectime] = 0 an endless recording will be started
      "off" : stopps a running recording manually or using other events (e.g. with at, notify)
      "snap": triggers a snapshot of the relevant camera and store it into Synology Surveillance Station
      "disable": deactivates a camera in Synology Surveillance Station
      "enable": activates a camera in Synology Surveillance Station
      "credentials <username> <password>": save a set of credentils
      "expmode [ day | night | auto ]": set the exposure mode to day, night or auto
      "extevent [ 1-10 ]": triggers the external event 1-10 (see actionrule editor in SVS)
      "motdetsc [ camera | SVS | disable ]": set motion detection to the desired mode
      "goPreset <Presetname>": moves a PTZ-camera to a predefinied Preset-position
      "runPatrol <Patrolname>": starts a predefinied patrol (PTZ-cameras)
      "goAbsPTZ [ X Y | up | down | left | right ]": moves a PTZ-camera to a absolute X/Y-coordinate or to direction up/down/left/right
      "move [ up | down | left | right | dir_X ]": starts a continuous move of PTZ-camera to direction up/down/left/right or dir_X
      "runView [image | lastrec | lastrec_open | link | link_open <room> ]": starts a livestream as embedded image or link
      "stopView": stops a camera livestream


      • set <name> [on] [off]

      • The command "set <name> on" starts a recording. The default recording time takes 15 seconds. It can be changed by the attribute "rectime" individualy. With the attribute (respectively the default value) provided recording time can be overwritten once by "set <name> on [rectime]". The recording will be stopped after processing time "rectime"automatically.
        A special case is the start using "set <name> on 0" respectively the attribute value "rectime = 0". In that case a endless-recording will be started. One have to stop this recording by command "set <name> off" explicitely.
        The recording behavior can be impacted with attribute "recextend" furthermore as explained as follows.

        Attribute "recextend = 0" or not set (default):

        • if, for example, a recording with rectimeme=22 is started, no other startcommand (for a recording) will be accepted until this started recording is finished. A hint will be logged in case of verboselevel = 3.

        Attribute "recextend = 1" is set:

        • a before started recording will be extend by the recording time "rectime" if a new start command is received. That means, the timer for the automatic stop-command will be renewed to "rectime" given bei the command, attribute or default value. This procedure will be repeated every time a new start command for recording is received. Therefore a running recording will be extended until no start command will be get.
        • a before started endless-recording will be stopped after recordingtime 2rectime" if a new "set on"-command is received (new set of timer). If it is unwanted make sure you don't set the attribute "recextend" in case of endless-recordings.

        Examples for simple Start/Stop a Recording:

        set <name> on [rectime] starts a recording of camera <name>, stops automatically after [rectime] (default 15s or defined by attribute)
        set <name> off stops the recording of camera <name>


      • set <name> snap

      • A snapshot can be triggered with:
         
             set <name> snap 
          
        Subsequent some Examples for taking snapshots:

        If a serial of snapshots should be released, it can be done using the following notify command. For the example a serial of snapshots are to be triggerd if the recording of a camera starts.
        When the recording of camera "CamHE1" starts (Attribut event-on-change-reading -> "Record" has to be set), then 3 snapshots at intervals of 2 seconds are triggered.
             define he1_snap_3 notify CamHE1:Record.*on define h3 at +*{3}00:00:02 set CamHE1 snap 
          
        Release of 2 Snapshots of camera "CamHE1" at intervals of 6 seconds after the motion sensor "MelderHE1" has sent an event,
        can be done e.g. with following notify-command:
             define he1_snap_2 notify MelderHE1:on.* define h2 at +*{2}00:00:06 set CamHE1 snap 
          
        The ID and the filename of the last snapshot will be displayed as value of variable "LastSnapId" respectively "LastSnapFilename" in the device-Readings.



      • set <name> [enable] [disable]

      • For deactivating / activating a list of cameras or all cameras by Regex-expression, subsequent two examples using "at":
             define a13 at 21:46 set CamCP1,CamFL,CamHE1,CamTER disable (enable)
             define a14 at 21:46 set Cam.* disable (enable)
          
        A bit more convenient is it to use a dummy-device for enable/disable all available cameras in Surveillance Station.
        At first the Dummy will be created.
             define allcams dummy
             attr allcams eventMap on:enable off:disable
             attr allcams room Cams
             attr allcams webCmd enable:disable
          
        With combination of two created notifies, respectively one for "enable" and one for "diasble", you are able to switch all cameras into "enable" or "disable" state at the same time if you set the dummy to "enable" or "disable".
             define all_cams_disable notify allcams:.*off set CamCP1,CamFL,CamHE1,CamTER disable
             attr all_cams_disable room Cams
        
             define all_cams_enable notify allcams:on set CamCP1,CamFL,CamHE1,CamTER enable
             attr all_cams_enable room Cams
          


      • set <name> expmode [day] [night] [auto]

      • With this command you are able to control the exposure mode and can set it to day, night or automatic mode. Thereby, for example, the behavior of camera LED's will be suitable controlled. The successful switch will be reported by the reading CamExposureMode (command "get ... caminfoall").

        Note:
        The successfully execution of this function depends on if SVS supports that functionality of the connected camera. Is the field for the Day/Night-mode shown greyed in SVS -> IP-camera -> optimization -> exposure mode, this function will be probably unsupported.


      • set <name> motdetsc [camera] [SVS] [disable]

      • The command "motdetsc" (stands for "motion detection source") switchover the motion detection to the desired mode. If motion detection will be done by camera / SVS without any parameters, the original camera motion detection settings are kept. The successful execution of that opreration one can retrace by the state in SVS -> IP-camera -> event detection -> motion.

        For the motion detection further parameter can be specified. The available options for motion detection by SVS are "sensitivity" and "threshold".

          set motdetsc SVS [sensitivity] [threshold] # command pattern
          set motdetsc SVS 91 30 # set the sensitivity to 91 and threshold to 30
          set motdetsc SVS 0 40 # keep the old value of sensitivity, set threshold to 40
          set motdetsc SVS 15 # set the sensitivity to 15, threshold keep unchanged


        If the motion detection is used by camera, there are the options "sensitivity", "object size", "percentage for release" available.

          set motdetsc camera [sensitivity] [threshold] [percentage] # command pattern
          set motdetsc camera 89 0 20 # set the sensitivity to 89, percentage to 20
          set motdetsc camera 0 40 10 # keep old value for sensitivity, set threshold to 40, percentage to 10
          set motdetsc camera 30 # set the sensitivity to 30, other values keep unchanged


        Please consider always the sequence of parameters. Unwanted options have to be set to "0" if further options which have to be changed are follow (see example above). The numerical values are between 1 - 99 (except special case "0").

        The each available options are dependend of camera type respectively the supported functions by SVS. Only the options can be used they are available in SVS -> edit camera -> motion detection. Further informations please read in SVS online help.

        With the command "get ... caminfoall" the Reading "CamMotDetSc" also will be updated which documents the current setup of motion detection. Only the parameters and parameter values supported by SVS at present will be shown. The camera itself may offer further options to adjust.

        Example:
           CamMotDetSc    SVS, sensitivity: 76, threshold: 55
          


      • set <name> goPreset <Preset>

      • Using this command you can move PTZ-cameras to a predefined position.
        The Preset-positions have to be defined first of all in the Synology Surveillance Station. This usually happens in the PTZ-control of IP-camera setup in SVS. The Presets will be read ito FHEM with command "get <name> caminfoall" (happens automatically when FHEM restarts). The import process can be repeated regular by camera polling. A long polling interval is recommendable in this case because of the Presets are only will be changed if the user change it in the IP-camera setup itself.

        Here it is an example of a PTZ-control depended on IR-motiondetector event:
            define CamFL.Preset.Wandschrank notify MelderTER:on.* set CamFL goPreset Wandschrank, ;; define CamFL.Preset.record at +00:00:10 set CamFL on 5 ;;;; define s3 at +*{3}00:00:05 set CamFL snap ;; define CamFL.Preset.back at +00:00:30 set CamFL goPreset Home
          
        Operating Mode:
        The IR-motiondetector registers a motion. Hereupon the camera "CamFL" moves to Preset-posion "Wandschrank". A recording with the length of 5 seconds starts 10 seconds later. Because of the prerecording time of the camera is set to 10 seconds (cf. Reading "CamPreRecTime"), the effectice recording starts when the camera move begins.
        When the recording starts 3 snapshots with an interval of 5 seconds will be taken as well.
        After a time of 30 seconds in position "Wandschrank" the camera moves back to postion "Home".

        An extract of the log illustrates the process:
          
           2016.02.04 15:02:14 2: CamFL - Camera Flur_Vorderhaus has moved to position "Wandschrank"
           2016.02.04 15:02:24 2: CamFL - Camera Flur_Vorderhaus Recording with Recordtime 5s started
           2016.02.04 15:02:29 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
           2016.02.04 15:02:30 2: CamFL - Camera Flur_Vorderhaus Recording stopped
           2016.02.04 15:02:34 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
           2016.02.04 15:02:39 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
           2016.02.04 15:02:44 2: CamFL - Camera Flur_Vorderhaus has moved to position "Home"
          


      • set <name> runPatrol <Patrolname>

      • This commans starts a predefined patrol (tour) of a PTZ-camera.
        At first the patrol has to be predefined in the Synology Surveillance Station. It can be done in the PTZ-control of IP-Kamera Setup -> PTZ-control -> patrol. The patrol tours will be read with command "get <name> caminfoall" which is be executed automatically when FHEM restarts. The import process can be repeated regular by camera polling. A long polling interval is recommendable in this case because of the patrols are only will be changed if the user change it in the IP-camera setup itself. Further informations for creating patrols you can get in the online-help of Surveillance Station.


      • set <name> goAbsPTZ [ X Y | up | down | left | right ]

      • This command can be used to move a PTZ-camera to an arbitrary absolute X/Y-coordinate, or to absolute position using up/down/left/right. The option is only available for cameras which are having the Reading "CapPTZAbs=true". The property of a camera can be requested with "get <name> caminfoall" .

        Example for a control to absolute X/Y-coordinates:
            set <name> goAbsPTZ 120 450
          
        In this example the camera lense moves to position X=120 und Y=450.
        The valuation is:
            X = 0 - 640      (0 - 319 moves lense left, 321 - 640 moves lense right, 320 don't move lense)
            Y = 0 - 480      (0 - 239 moves lense down, 241 - 480 moves lense up, 240 don't move lense) 
          
        The lense can be moved in smallest steps to very large steps into the desired direction. If necessary the procedure has to be repeated to bring the lense into the desired position.

        If the motion should be done with the largest possible increment the following command can be used for simplification:
           set <name> goAbsPTZ up [down ] [left] [right]
          
        In this case the lense will be moved with largest possible increment into the given absolute position. Also in this case the procedure has to be repeated to bring the lense into the desired position if necessary.


      • set <name> move [ up | down | left | right | dir_X ] [seconds]

      • With this command a continuous move of a PTZ-camera will be started. In addition to the four basic directions up/down/left/right is it possible to use angular dimensions "dir_X". The grain size of graduation depends on properties of the camera and can be identified by the Reading "CapPTZDirections".

        The radian measure of 360 degrees will be devided by the value of "CapPTZDirections" and describes the move drections starting with "0=right" counterclockwise. That means, if a camera Reading is "CapPTZDirections = 8" it starts with dir_0 = right, dir_2 = top, dir_4 = left, dir_6 = bottom and respectively dir_1, dir_3, dir_5 and dir_7 the appropriate directions between. The possible moving directions of cameras with "CapPTZDirections = 32" are correspondingly divided into smaller sections.

        In opposite to the "set <name> goAbsPTZ"-command starts "set <name> move" a continuous move until a stop-command will be received. The stop-command will be generated after the optional assignable time of [seconds]. If that retention period wouldn't be set by the command, a time of 1 second will be set implicit.

        Examples:
            set <name> move up 0.5      : moves PTZ 0,5 Sek. (plus processing time) to the top
            set <name> move dir_1 1.5   : moves PTZ 1,5 Sek. (plus processing time) to top-right 
            set <name> move dir_20 0.7  : moves PTZ 1,5 Sek. (plus processing time) to left-bottom ("CapPTZDirections = 32)"
          


      • set <name> runView live_fw | live_link | live_open [<room>] | lastrec_fw | lastrec_open [<room>]

      • With "live_fw, live_link, live_open" a livestream (mjpeg-stream) of a camera will be started, either as embedded image or as a generated link.
        The option "live_open" starts a new browser window. If the optional <room> was set, the window will only be started if the specified room is currently opend in a browser session.

        Access to the last recording of a camera can be done using "lastrec_fw" respectively "lastrec_open". The recording will be opened in iFrame. So there are some control elements available, e.g. to increase/descrease reproduce speed.
        The art of windows in FHEMWEB can be affected by HTML-tags in attribute "htmlattr".

        Examples:
            attr <name> htmlattr target=_blank width="500" height="375"
            attr <name> htmlattr target=_blank width=500,height=375
            attr <name> htmlattr width=700,height=525,top=200,left=300
          
        With these attribute values a streaming link will be opened (by click on) in a new browser tab or windows. If the stream will be started as an image, the size changes appropriately the values of width and hight.
        The command "set <name> runView live_open" starts the stream immediately in a new browser window (longpoll=1 must be set for WEB). A browser window will be initiated to open for every FHEM session which is active. If you want to change this behavior, you can use command "set <name> runView live_open <room>". It initiates open a browser window in that FHEM session which has just opend the room <room>. The settings of attribute "livestreamprefix" overwrites the data for protocol, servername and port in reading "LiveStreamUrl". By "livestreamprefix" the LivestreamURL (is shown if attribute "showStmInfoFull" is set) can be modified and used for distribution and external access to SVS livestream.

        Example:
            attr <name> livestreamprefix https://<Servername>:<Port>
          
        The livestream can be stopped again by command "set <name> stopView".


      • set <name> extevent [ 1-10 ]

      • This command triggers an external event (1-10) in SVS. The actions which will are used have to be defined in the actionrule editor of SVS at first. There are the events 1-10 possible. In the message application of SVS you may select Email, SMS or Mobil (DS-Cam) messages to release if an external event has been triggerd. Further informations can be found in the online help of the actionrule editor. The used user needs to be a member of the admin-group and DSM-session is needed too.



    Get
      With SSCam the properties of SVS and defined Cameras could be retrieved. Actually it could be done by following commands:
            get <name> caminfoall
            get <name> eventlist
            get <name> scanVirgin
            get <name> stmUrlPath
            get <name> svsinfo
            get <name> snapfileinfo
        
      With command "get <name> caminfoall" dependend of the type of Camera (e.g. Fix- or PTZ-Camera) the available properties will be retrieved and provided as Readings.
      For example the Reading "Availability" will be set to "disconnected" if the Camera would be disconnected from Synology Surveillance Station and can be used for further processing like creating events.
      By command "get <name> eventlist" the Reading "CamEventNum" and "CamLastRecord" will be refreshed which containes the total number of in SVS registered camera events and the path / name of the last recording. This command will be implicit executed when "get ... caminfoall" is running.
      The attribute "videofolderMap" replaces the content of reading "VideoFolder". You can use it for example if you have mounted the videofolder of SVS under another name or path and want to access by your local pc. Using "get <name> snapfileinfo" the filename of the last snapshot will be retrieved. This command will be executed with "get <name> snap" automatically.
      The command "get <name> svsinfo" is not really dependend on a camera, but rather a command to determine common informations about the installed SVS-version and other properties.
      The functions "caminfoall" and "svsinfo" will be executed automatically once-only after FHEM restarts to collect some relevant informations for camera control.
      Please consider to save the credentials what will be used for login to DSM or SVS !

      • get <name> scanVirgin

      • This command is similar to get caminfoall, informations relating to SVS and the camera will be retrieved. In difference to caminfoall in either case a new session ID will be generated (do a new login), the camera ID will be new identified and all necessary API-parameters will be new investigated.


      • get <name> stmUrlPath

      • This command is to fetch the streamkey information and streamurl using that streamkey. The reading "StmKey" will be filled when this command will be executed and can be used to send it and run by your own application like a browser (see example). If the attribute "showStmInfoFull" is set, additional stream readings like "StmKeyUnicst", "StmKeymjpegHttp" will be shown and can be used to run the appropriate livestream without session id. Is the attribute "livestreamprefix" (usage: "http(s)://<hostname><port>) used, the servername / port will be replaced if necessary. The strUrlPath function will be included automatically if polling is used.

        Example to create an http-call to a livestream using StmKey:
             http(s)://<hostname><port>/webapi/entry.cgi?api=SYNO.SurveillanceStation.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=5&StmKey="31fd87279976d89bb98409728cced890"
          
        cameraId (INTERNAL), StmKey has to be replaced by valid values.

        Note:
        If you use the stream-call from external and replace hostname / port with valid values and open your router ip ports, please make shure that no unauthorized person could get this sensible data !

      Polling of Camera-Properties:

        Retrieval of Camera-Properties can be done automatically if the attribute "pollcaminfoall" will be set to a value > 10.
        As default that attribute "pollcaminfoall" isn't be set and the automatic polling isn't be active.
        The value of that attribute determines the interval of property-retrieval in seconds. If that attribute isn't be set or < 10 the automatic polling won't be started
        respectively stopped when the value was set to > 10 before.

        The attribute "pollcaminfoall" is monitored by a watchdog-timer. Changes of the attribute-value will be checked every 90 seconds and transact corresponding.
        Changes of the pollingstate and pollinginterval will be reported in FHEM-Logfile. The reporting can be switched off by setting the attribute "pollnologging=1".
        Thereby the needless growing of the logfile can be avoided. But if verbose level is set to 4 or above even though the attribute "pollnologging" is set as well, the polling
        will be actived due to analysis purposes.

        If FHEM will be restarted, the first data retrieval will be done within 60 seconds after start.

        The state of automatic polling will be displayed by reading "PollState":

        • PollState = Active - automatic polling will be executed with interval correspondig value of attribute "pollcaminfoall"
        • PollState = Inactive - automatic polling won't be executed

        The readings are described here.

        Notes:

        If polling is used, the interval should be adjusted only as short as needed due to the detected camera values are predominantly static.
        A feasible guide value for attribute "pollcaminfoall" could be between 600 - 1800 (s).
        Per polling call and camera approximately 10 - 20 Http-calls will are stepped against Surveillance Station.
        Because of that if HTTP-Timeout (pls. refer Attribut "httptimeout") is set to 4 seconds, the theoretical processing time couldn't be higher than 80 seconds.
        Considering a safety margin, in that example you shouldn't set the polling interval lower than 160 seconds.

        If several Cameras are defined in SSCam, attribute "pollcaminfoall" of every Cameras shouldn't be set exactly to the same value to avoid processing bottlenecks
        and thereby caused potential source of errors during request Synology Surveillance Station.
        A marginal difference between the polling intervals of the defined cameras, e.g. 1 second, can already be faced as sufficient value.

    Internals

      The meaning of used Internals is depicted in following list:

      • CAMID - the ID of camera defined in SVS, the value will be retrieved automatically on the basis of SVS-cameraname
      • CAMNAME - the name of the camera in SVS
      • CREDENTIALS - the value is "Set" if Credentials are set
      • NAME - the cameraname in FHEM
      • OPMODE - the last executed operation of the module
      • SERVERADDR - IP-Address of SVS Host
      • SERVERPORT - SVS-Port


    Readings

      Using the polling mechanism or retrieval by "get"-call readings are provieded, The meaning of the readings are listed in subsequent table:
      The transfered Readings can be deversified dependend on the type of camera.

      • Availability
      • - Availability of Camera (disabled, enabled, disconnected, other)
      • CamEventNum
      • - delivers the total number of in SVS registered events of the camera
      • CamExposureControl
      • - indicating type of exposure control
      • CamExposureMode
      • - current exposure mode (Day, Night, Auto, Schedule, Unknown)
      • CamForceEnableMulticast
      • - Is the camera forced to enable multicast.
      • CamIP
      • - IP-Address of Camera
      • CamLastRec
      • - Path / name of the last recording
      • CamLastRecTime
      • - date / starttime / endtime of the last recording
      • CamLiveMode
      • - Source of Live-View (DS, Camera)
      • CamModel
      • - Model of camera
      • CamMotDetSc
      • - state of motion detection source (disabled, by camera, by SVS) and their parameter
      • CamPort
      • - IP-Port of Camera
      • CamPreRecTime
      • - Duration of Pre-Recording (in seconds) adjusted in SVS
      • CamRecShare
      • - shared folder on disk station for recordings
      • CamRecVolume
      • - Volume on disk station for recordings
      • CamVendor
      • - Identifier of camera producer
      • CamVideoFlip
      • - Is the video flip
      • CamVideoMirror
      • - Is the video mirror
      • CapAudioOut
      • - Capability to Audio Out over Surveillance Station (false/true)
      • CapChangeSpeed
      • - Capability to various motion speed
      • CapPTZAbs
      • - Capability to perform absolute PTZ action
      • CapPTZAutoFocus
      • - Capability to perform auto focus action
      • CapPTZDirections
      • - the PTZ directions that camera support
      • CapPTZFocus
      • - mode of support for focus action
      • CapPTZHome
      • - Capability to perform home action
      • CapPTZIris
      • - mode of support for iris action
      • CapPTZPan
      • - Capability to perform pan action
      • CapPTZTilt
      • - mode of support for tilt action
      • CapPTZZoom
      • - Capability to perform zoom action
      • DeviceType
      • - device type (Camera, Video_Server, PTZ, Fisheye)
      • Error
      • - message text of last error
      • Errorcode
      • - error code of last error
      • LastSnapFilename
      • - the filename of the last snapshot
      • LastSnapId
      • - the ID of the last snapshot
      • LastUpdateTime
      • - date / time the last update of readings by "caminfoall"
      • 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
      • 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
      • StmKeyUnicst
      • - Uni-cast stream path of the camera. (attribute "showStmInfoFull" has to be set)
      • StmKeymjpegHttp
      • - Mjpeg stream path(over http) of the camera (attribute "showStmInfoFull" has to be set)
      • SVScustomPortHttp
      • - Customized port of Surveillance Station (HTTP) (to get with "svsinfo")
      • SVScustomPortHttps
      • - Customized port of Surveillance Station (HTTPS) (to get with "svsinfo")
      • SVSlicenseNumber
      • - The total number of installed licenses (to get with "svsinfo")
      • SVSuserPriv
      • - The effective rights of the user used for log in (to get with "svsinfo")
      • SVSversion
      • - package version of the installed Surveillance Station (to get with "svsinfo")
      • UsedSpaceMB
      • - used disk space of recordings by Camera
      • VideoFolder
      • - Path to the recorded video


    Attributes

      • debugactivetoken
        if set the state of active token will be logged - only for debugging, don't use it in normal operation !

      • disable
        deactivates the module (device definition)

      • httptimeout
        Timeout-Value of HTTP-Calls to Synology Surveillance Station, Default: 4 seconds (if httptimeout = "0" or not set)

      • htmlattr
        additional specifications to livestream-Url to manipulate the behavior of stream, e.g. size of the image

        • Example:
          attr <name> htmlattr width=500 height=325 top=200 left=300

      • livestreamprefix
        overwrites the specifications of protocol, servername and port for further use of the livestream address, e.g. as an link to external use. It has to be specified as "http(s)://<servername>:<port>"

      • loginRetries
        set the amount of login-repetitions in case of failure (default = 1)

      • noQuotesForSID
        this attribute may be helpfull in some cases to avoid errormessage "402 - permission denied" and makes login possible.

      • pollcaminfoall
        Interval of automatic polling the Camera properties (if < 10: no polling, if > 10: polling with interval)

      • pollnologging
        "0" resp. not set = Logging device polling active (default), "1" = Logging device polling inactive

      • rectime
        determines the recordtime when a recording starts. If rectime = 0 an endless recording will be started. If it isn't defined, the default recordtime of 15s is activated

      • recextend
        "rectime" of a started recording will be set new. Thereby the recording time of the running recording will be extended

      • session
        selection of login-Session. Not set or set to "DSM" -> session will be established to DSM (Sdefault). "SurveillanceStation" -> session will be established to SVS

      • simu_SVSversion
        simulates another SVS version. (only a lower version than the installed one is possible !)

      • showStmInfoFull
        additional stream informations like LiveStreamUrl, StmKeyUnicst, StmKeymjpegHttp will be created

      • showPassInLog
        if set the used password will be shown in logfile with verbose 4. (default = 0)

      • videofolderMap
        replaces the content of reading "VideoFolder", Usage if e.g. folders are mountet with different names than original (SVS)

      • verbose

        • Different Verbose-Level are supported.
          Those are in detail:
          0 - Start/Stop-Event will be logged
          1 - Error messages will be logged
          2 - messages according to important events were logged
          3 - sended commands will be logged
          4 - sended and received informations will be logged
          5 - all outputs will be logged for error-analyses. Caution: a lot of data could be written into logfile !

      • readingFnAttributes


=end html =begin html_DE

SSCam

    Mit diesem Modul können Operationen von in der Synology Surveillance Station (SVS) definierten Kameras ausgeführt werden.
    Zur Zeit werden folgende Funktionen unterstützt:

      • Start einer Aufnahme
      • Stop einer Aufnahme (per Befehl bzw. automatisch nach Ablauf der Aufnahmedauer)
      • Aufnehmen eines Schnappschusses und Ablage in der Synology Surveillance Station
      • Deaktivieren einer Kamera in Synology Surveillance Station
      • Aktivieren einer Kamera in Synology Surveillance Station
      • Steuerung der Belichtungsmodi Tag, Nacht bzw. Automatisch
      • Umschaltung der Ereigniserkennung durch Kamera, durch SVS oder deaktiviert
      • steuern der Erkennungsparameterwerte Empfindlichkeit, Schwellwert, Objektgröße und Prozentsatz für Auslösung
      • Abfrage von Kameraeigenschaften (auch mit Polling) sowie den Eigenschaften des installierten SVS-Paketes
      • Bewegen an eine vordefinierte Preset-Position (bei PTZ-Kameras)
      • Start einer vordefinierten Überwachungstour (bei PTZ-Kameras)
      • Positionieren von PTZ-Kameras zu absoluten X/Y-Koordinaten
      • kontinuierliche Bewegung von PTZ-Kameras
      • auslösen externer Ereignisse 1-10 (Aktionsregel SVS)
      • starten und beenden von Kamera-Livestreams
      • Abruf und Ausgabe der Kamera Streamkeys sowie Stream-Urls (Nutzung von Kamera-Livestreams ohne Session Id)
      • abspielen der letzten Aufnahme

    Die Aufnahmen stehen in der Synology Surveillance Station (SVS) zur Verfügung und unterliegen, wie jede andere Aufnahme, den in der Synology Surveillance Station eingestellten Regeln.
    So werden zum Beispiel die Aufnahmen entsprechend ihrer Archivierungsfrist gespeichert und dann gelöscht.

    Wenn sie über dieses Modul diskutieren oder zur Verbesserung des Moduls beitragen möchten, ist im FHEM-Forum ein Sammelplatz unter:
    49_SSCam: Fragen, Hinweise, Neuigkeiten und mehr rund um dieses Modul.

    Weitere Infomationen zum Modul sind im FHEM-Wiki zu finden:
    SSCAM - Steuerung von Kameras in Synology Surveillance Station.

    Vorbereitung

    Dieses Modul nutzt das CPAN Module JSON. Bitte darauf achten dieses Paket zu installieren. (Debian: libjson-perl).
    Das Modul verwendet für HTTP-Calls die nichtblockierenden Funktionen von HttpUtils bzw. HttpUtils_NonblockingGet.
    Im DSM bzw. der Synology Surveillance Station muß ein Nutzer angelegt sein. Die Zugangsdaten werden später über ein Set-Kommando dem angelegten Gerät zugewiesen.
    Nähere Informationen dazu unter Credentials

    Überblick über die Perl-Module welche von SSCam genutzt werden:

    JSON
    Data::Dumper
    MIME::Base64
    Time::HiRes
    HttpUtils (FHEM-Modul)

    Definition

      define <name> SSCAM <Kameraname in SVS> <ServerAddr> [Port]

      Definiert eine neue Kamera für SSCam. Zunächst muß diese Kamera in der Synology Surveillance Station 7.0 oder höher eingebunden sein und entsprechend funktionieren.

      Das Modul SSCam basiert auf Funktionen der Synology Surveillance Station API.
      Weitere Informationen unter: Web API Guide.

      Momentan wird nur das HTTP-Protokoll unterstützt um die Web-Services der Synology DS aufzurufen.

      Die Parameter beschreiben im Einzelnen:

      name: der Name des neuen Gerätes in FHEM
      Kameraname: Kameraname wie er in der Synology Surveillance Station angegeben ist. Leerzeichen im Namen sind nicht erlaubt !
      ServerAddr: die IP-Addresse des Synology Surveillance Station Host. Hinweis: Es sollte kein Servername verwendet werden weil DNS-Aufrufe in FHEM blockierend sind.
      Port: optional - der Port der Synology Surveillance Station. Wenn nicht angegeben wird der Default-Port 5000 (nur HTTP) gesetzt


      Beispiel:
            define CamCP SSCAM Carport 192.168.2.20 [5000]      
           
      Wird eine neue Kamera definiert, wird diesem Device zunächst eine Standardaufnahmedauer von 15 zugewiesen.
      Über das Attribut "rectime" kann die Aufnahmedauer für jede Kamera individuell angepasst werden. Der Wert "0" für "rectime" führt zu einer Endlosaufnahme, die durch "set <name> off" wieder gestoppt werden muß.
      Ein Logeintrag mit einem entsprechenden Hinweis auf diesen Umstand wird geschrieben.

      Wird das Attribut "rectime" gelöscht, greift wieder der Default-Wert (15s) für die Aufnahmedauer.

      Mit dem Befehl "set <name> on [rectime]" wird die Aufnahmedauer temporär festgelegt und überschreibt einmalig sowohl den Defaultwert als auch den Wert des gesetzten Attributs "rectime".
      Auch in diesem Fall führt "set <name> on 0" zu einer Daueraufnahme.

      Eine eventuell in der SVS eingestellte Dauer der Voraufzeichnung wird weiterhin berücksichtigt.


      Credentials

      Nach dem Definieren des Gerätes müssen zuerst die Zugangsparameter gespeichert werden. Das geschieht mit dem Befehl:
       
           set <name> credentials <Username> <Passwort>
          
      Der Anwender kann in Abhängigkeit der beabsichtigten einzusetzenden Funktionen einen Nutzer im DSM bzw. in der Surveillance Station einrichten.
      Ist der DSM-Nutzer der Gruppe Administratoren zugeordnet, hat er auf alle Funktionen Zugriff. Ohne diese Gruppenzugehörigkeit können nur Funktionen mit niedrigeren
      Rechtebedarf ausgeführt werden. Die benötigten Mindestrechte der Funktionen sind in der Tabelle weiter unten aufgeführt.
      Alternativ zum DSM-Nutzer kann ein in der SVS angelegter Nutzer verwendet werden. Auch in diesem Fall hat ein Nutzer vom Typ Manager das Recht alle Funktionen
      auszuführen, wobei der Zugriff auf bestimmte Kameras/ im Privilegienprofil beschränkt werden kann (siehe Hilfefunktion in SVS).
      Als Best Practice wird vorgeschlagen jeweils einen User im DSM und einen in der SVS anzulegen:

      • DSM-User als Mitglied der Admin-Gruppe: uneingeschränkter Test aller Modulfunktionen -> session:DSM
      • SVS-User als Manager oder Betrachter: angepasstes Privilegienprofil -> session: SurveillanceStation

      Über das Attribut "session" kann ausgewählt werden, ob die Session mit dem DSM oder der SVS augebaut werden soll.
      Erfolgt der Session-Aufbau mit dem DSM, stehen neben der SVS Web-API auch darüber hinaus gehende API-Zugriffe zur Verfügung die unter Umständen zur Verarbeitung benötigt werden.

      Nach der Gerätedefinition ist die Grundeinstellung "Login in das DSM", d.h. es können Credentials mit Admin-Berechtigungen genutzt werden um zunächst alle
      Funktionen der Kameras testen zu können. Danach können die Credentials z.B. in Abhängigkeit der benötigten Funktionen auf eine SVS-Session mit entsprechend beschränkten Privilegienprofil umgestellt werden.

      Die nachfolgende Aufstellung zeigt die Mindestanforderungen der jeweiligen Modulfunktionen an die Nutzerrechte.

      • set ... on
      • session: ServeillanceStation - Betrachter mit erweiterten Privileg "manuelle Aufnahme"
      • set ... off
      • session: ServeillanceStation - Betrachter mit erweiterten Privileg "manuelle Aufnahme"
      • set ... snap
      • session: ServeillanceStation - Betrachter
      • set ... disable
      • session: ServeillanceStation - Manager
      • set ... enable
      • session: ServeillanceStation - Manager
      • set ... expmode
      • session: ServeillanceStation - Manager
      • set ... motdetsc
      • session: ServeillanceStation - Manager
      • set ... goPreset
      • session: ServeillanceStation - Betrachter mit Privileg Objektivsteuerung der Kamera
      • set ... runPatrol
      • session: ServeillanceStation - Betrachter mit Privileg Objektivsteuerung der Kamera
      • set ... goAbsPTZ
      • session: ServeillanceStation - Betrachter mit Privileg Objektivsteuerung der Kamera
      • set ... move
      • session: ServeillanceStation - Betrachter mit Privileg Objektivsteuerung der Kamera
      • set ... runView
      • session: ServeillanceStation - Betrachter mit Privileg Liveansicht für Kamera
      • set ... stopView
      • -
      • set ... credentials
      • -
      • set ... extevent
      • session: DSM - Nutzer Mitglied von Admin-Gruppe
      • get ... caminfoall
      • session: ServeillanceStation - Betrachter
      • get ... eventlist
      • session: ServeillanceStation - Betrachter
      • get ... scanVirgin
      • session: ServeillanceStation - Betrachter
      • get ... svsinfo
      • session: ServeillanceStation - Betrachter
      • get ... snapfileinfo
      • session: ServeillanceStation - Betrachter
      • get ... stmUrlPath
      • session: ServeillanceStation - Betrachter


      HTTP-Timeout setzen

      Alle Funktionen dieses Moduls verwenden HTTP-Aufrufe gegenüber der SVS Web API.
      Der Standardwert für den HTTP-Timeout beträgt 4 Sekunden. Durch Setzen des Attributes "httptimeout" > 0 kann dieser Wert bei Bedarf entsprechend den technischen Gegebenheiten angepasst werden.



    Set
      Es gibt zur Zeit folgende Optionen für "set <name> ...":

      "on [rectime]": startet eine Aufnahme. Die Aufnahme wird automatisch nach Ablauf der Zeit [rectime] gestoppt.
      Mit rectime = 0 wird eine Daueraufnahme gestartet die durch "set <name> off" wieder gestoppt werden muß.
      "off" : stoppt eine laufende Aufnahme manuell oder durch die Nutzung anderer Events (z.B. über at, notify)
      "snap": löst einen Schnappschuß der entsprechenden Kamera aus und speichert ihn in der Synology Surveillance Station
      "disable": deaktiviert eine Kamera in der Synology Surveillance Station
      "enable": aktiviert eine Kamera in der Synology Surveillance Station
      "credentials <username> <password>": speichert die Zugangsinformationen
      "expmode [ day | night | auto ]": aktiviert den Belichtungsmodus Tag, Nacht oder Automatisch
      "extevent [ 1-10 ]": löst das externe Ereignis 1-10 aus (Aktionsregel in SVS)
      "motdetsc [ camera | SVS | disable ]": schaltet die Bewegungserkennung in den gewünschten Modus (durch Kamera, SVS, oder deaktiviert)
      "goPreset <Presetname>": bewegt eine PTZ-Kamera zu einer vordefinierten Preset-Position
      "runPatrol <Patrolname>": startet eine vordefinierte Überwachungstour einer PTZ-Kamera
      "goAbsPTZ [ X Y | up | down | left | right ]": positioniert eine PTZ-camera zu einer absoluten X/Y-Koordinate oder maximalen up/down/left/right-position
      "move [ up | down | left | right | dir_X ]": startet kontinuerliche Bewegung einer PTZ-Kamera in Richtung up/down/left/right bzw. dir_X
      "runView live_fw | live_link | live_open [<room>] | lastrec_fw | lastrec_open [<room>]": startet einen Livestream als eingbettetes Image, IFrame bzw. Link
      "stopView": stoppt einen Kamera-Livestream


      • set <name> [on] [off]

      • Der Befehl "set <name> on" startet eine Aufnahme. Die Standardaufnahmedauer beträgt 15 Sekunden. Sie kann mit dem Attribut "rectime" individuell festgelegt werden. Die im Attribut (bzw. im Standard) hinterlegte Aufnahmedauer kann einmalig mit "set <name> on [rectime]" überschrieben werden. Die Aufnahme stoppt automatisch nach Ablauf der Zeit "rectime".
        Ein Sonderfall ist der Start einer Daueraufnahme mit "set <name> on 0" bzw. dem Attributwert "rectime = 0". In diesem Fall wird eine Daueraufnahme gestartet die explizit wieder mit dem Befehl "set <name> off" gestoppt werden muß.
        Das Aufnahmeverhalten kann weiterhin mit dem Attribut "recextend" wie folgt beeinflusst werden.

        Attribut "recextend = 0" bzw. nicht gesetzt (Standard):

        • wird eine Aufnahme mit z.B. rectime=22 gestartet, wird kein weiterer Startbefehl für eine Aufnahme akzeptiert bis diese gestartete Aufnahme nach 22 Sekunden beendet ist. Ein Hinweis wird bei verbose=3 im Logfile protokolliert.

        Attribut "recextend = 1" gesetzt:
        • eine zuvor gestartete Aufnahme wird bei einem erneuten "set on" -Befehl um die Aufnahmezeit "rectime" verlängert. Das bedeutet, dass der Timer für den automatischen Stop auf den Wert "rectime" neu gesetzt wird. Dieser Vorgang wiederholt sich mit jedem Start-Befehl. Dadurch verlängert sich eine laufende Aufnahme bis kein Start-Inpuls mehr registriert wird.
        • eine zuvor gestartete Endlos-Aufnahme wird mit einem erneuten "set on"-Befehl nach der Aufnahmezeit "rectime" gestoppt (Timerneustart). Ist dies nicht gewünscht, ist darauf zu achten dass bei der Verwendung einer Endlos-Aufnahme das Attribut "recextend" nicht verwendet wird.

        Beispiele für einfachen Start/Stop einer Aufnahme:

        set <name> on [rectime] startet die Aufnahme der Kamera <name>, automatischer Stop der Aufnahme nach Ablauf der Zeit [rectime] (default 15s oder wie im Attribut "rectime" angegeben)
        set <name> off stoppt die Aufnahme der Kamera <name>


      • set <name> snap

      • Ein Schnappschuß kann ausgelöst werden mit:
         
             set <name> snap 
          
        Nachfolgend einige Beispiele für die Auslösung von Schnappschüssen.

        Soll eine Reihe von Schnappschüssen ausgelöst werden wenn eine Aufnahme startet, kann das z.B. durch folgendes notify geschehen.
        Sobald der Start der Kamera CamHE1 ausgelöst wird (Attribut event-on-change-reading -> "Record" setzen), werden abhängig davon 3 Snapshots im Abstand von 2 Sekunden getriggert.
             define he1_snap_3 notify CamHE1:Record.*Start define h3 at +*{3}00:00:02 set CamHE1 snap
          
        Triggern von 2 Schnappschüssen der Kamera "CamHE1" im Abstand von 6 Sekunden nachdem der Bewegungsmelder "MelderHE1" einen Event gesendet hat,
        kann z.B. mit folgendem notify geschehen:
             define he1_snap_2 notify MelderHE1:on.* define h2 at +*{2}00:00:06 set CamHE1 snap 
          
        Es wird die ID und der Filename des letzten Snapshots als Wert der Variable "LastSnapId" bzw. "LastSnapFilename" in den Readings der Kamera ausgegeben.



      • set <name> [enable] [disable]

      • Um eine Liste von Kameras oder alle Kameras (mit Regex) zum Beispiel um 21:46 zu deaktivieren / zu aktivieren zwei Beispiele mit at:
             define a13 at 21:46 set CamCP1,CamFL,CamHE1,CamTER disable (enable)
             define a14 at 21:46 set Cam.* disable (enable)
          
        Etwas komfortabler gelingt das Schalten aller Kameras über einen Dummy. Zunächst wird der Dummy angelegt:
             define allcams dummy
             attr allcams eventMap on:enable off:disable
             attr allcams room Cams
             attr allcams webCmd enable:disable
          
        Durch Verknüpfung mit zwei angelegten notify, jeweils ein notify für "enable" und "disable", kann man durch Schalten des Dummys auf "enable" bzw. "disable" alle Kameras auf einmal aktivieren bzw. deaktivieren.
             define all_cams_disable notify allcams:.*off set CamCP1,CamFL,CamHE1,CamTER disable
             attr all_cams_disable room Cams
        
             define all_cams_enable notify allcams:on set CamCP1,CamFL,CamHE1,CamTER enable
             attr all_cams_enable room Cams
          


      • set <name> expmode [day] [night] [auto]

      • Mit diesem Befehl kann der Belichtungsmodus der Kameras gesetzt werden. Dadurch wird z.B. das Verhalten der Kamera-LED's entsprechend gesteuert. Die erfolgreiche Umschaltung wird durch das Reading CamExposureMode ("get ... caminfoall") reportet.

        Hinweis:
        Die erfolgreiche Ausführung dieser Funktion ist davon abhängig ob die SVS diese Funktionalität der Kamera unterstützt. Ist in SVS -> IP-Kamera -> Optimierung -> Belichtungsmodus das Feld für den Tag/Nachtmodus grau hinterlegt, ist nicht von einer lauffähigen Unterstützung dieser Funktion auszugehen.


        set <name> motdetsc [camera] [SVS] [disable]
        Der Befehl "motdetsc" (steht für motion detection source) schaltet die Bewegungserkennung in den gewünschten Modus. Wird die Bewegungserkennung durch die Kamera / SVS ohne weitere Optionen eingestellt, werden die momentan gültigen Bewegungserkennungsparameter der Kamera / SVS beibehalten. Die erfolgreiche Ausführung der Operation lässt sich u.a. anhand des Status von SVS -> IP-Kamera -> Ereigniserkennung -> Bewegung nachvollziehen.

        Für die Bewegungserkennung durch SVS bzw. durch Kamera können weitere Optionen angegeben werden. Die verfügbaren Optionen bezüglich der Bewegungserkennung durch SVS sind "Empfindlichkeit" und "Schwellwert".

          set motdetsc SVS [Empfindlichkeit] [Schwellwert] # Befehlsmuster
          set motdetsc SVS 91 30 # setzt die Empfindlichkeit auf 91 und den Schwellwert auf 30
          set motdetsc SVS 0 40 # behält gesetzten Wert für Empfindlichkeit bei, setzt Schwellwert auf 40
          set motdetsc SVS 15 # setzt die Empfindlichkeit auf 15, Schwellwert bleibt unverändert


        Wird die Bewegungserkennung durch die Kamera genutzt, stehen die Optionen "Empfindlichkeit", "Objektgröße" und "Prozentsatz für Auslösung" zur Verfügung.

          set motdetsc camera [Empfindlichkeit] [Schwellwert] [Prozentsatz] # Befehlsmuster
          set motdetsc camera 89 0 20 # setzt die Empfindlichkeit auf 89, Prozentsatz auf 20
          set motdetsc camera 0 40 10 # behält gesetzten Wert für Empfindlichkeit bei, setzt Schwellwert auf 40, Prozentsatz auf 10
          set motdetsc camera 30 # setzt die Empfindlichkeit auf 30, andere Werte bleiben unverändert


      Es ist immer die Reihenfolge der Optionswerte zu beachten. Nicht gewünschte Optionen sind mit "0" zu besetzen sofern danach Optionen folgen deren Werte verändert werden sollen (siehe Beispiele oben). Der Zahlenwert der Optionen beträgt 1 - 99 (außer Sonderfall "0").

      Die jeweils verfügbaren Optionen unterliegen der Funktion der Kamera und der Unterstützung durch die SVS. Es können jeweils nur die Optionen genutzt werden die in SVS -> Kamera bearbeiten -> Ereigniserkennung zur Verfügung stehen. Weitere Infos sind der Online-Hilfe zur SVS zu entnehmen.

      Über den Befehl "get ... caminfoall" wird auch das Reading "CamMotDetSc" aktualisiert welches die gegenwärtige Einstellung der Bewegungserkennung dokumentiert. Es werden nur die Parameter und Parameterwerte angezeigt, welche die SVS aktiv unterstützt. Die Kamera selbst kann weiterführende Einstellmöglichkeiten besitzen.

      Beipiel:
        CamMotDetSc    SVS, sensitivity: 76, threshold: 55
        


      • set <name> goPreset <Preset>

      • Mit diesem Kommando können PTZ-Kameras in eine vordefininierte Position bewegt werden.
        Die Preset-Positionen müssen dazu zunächst in der Synology Surveillance Station angelegt worden sein. Das geschieht in der PTZ-Steuerung im IP-Kamera Setup. Die Presets werden über das Kommando "get <name> caminfoall" eingelesen (geschieht bei restart von FHEM automatisch). Der Einlesevorgang kann durch ein Kamerapolling regelmäßig wiederholt werden. Ein langes Pollingintervall ist in diesem Fall empfehlenswert, da sich die Presetpositionen nur im Fall der Neuanlage bzw. Änderung verändern werden.

        Hier ein Beispiel einer PTZ-Steuerung in Abhängigkeit eines IR-Melder Events:
            define CamFL.Preset.Wandschrank notify MelderTER:on.* set CamFL goPreset Wandschrank, ;; define CamFL.Preset.record at +00:00:10 set CamFL on 5 ;;;; define s3 at +*{3}00:00:05 set CamFL snap ;; define CamFL.Preset.back at +00:00:30 set CamFL goPreset Home
          
        Funktionsweise:
        Der IR-Melder "MelderTER" registriert eine Bewegung. Daraufhin wird die Kamera CamFL in die Preset-Position "Wandschrank" gebracht. Eine Aufnahme mit Dauer von 5 Sekunden startet 10 Sekunden später. Da die Voraufnahmezeit der Kamera 10s beträgt (vgl. Reading "CamPreRecTime"), startet die effektive Aufnahme wenn der Kameraschwenk beginnt.
        Mit dem Start der Aufnahme werden drei Schnappschüsse im Abstand von 5 Sekunden angefertigt.
        Nach einer Zeit von 30 Sekunden fährt die Kamera wieder zurück in die "Home"-Position.

        Ein Auszug aus dem Log verdeutlicht den Ablauf:
          
           2016.02.04 15:02:14 2: CamFL - Camera Flur_Vorderhaus has moved to position "Wandschrank"
           2016.02.04 15:02:24 2: CamFL - Camera Flur_Vorderhaus Recording with Recordtime 5s started
           2016.02.04 15:02:29 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
           2016.02.04 15:02:30 2: CamFL - Camera Flur_Vorderhaus Recording stopped
           2016.02.04 15:02:34 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
           2016.02.04 15:02:39 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
           2016.02.04 15:02:44 2: CamFL - Camera Flur_Vorderhaus has moved to position "Home"
          


      • set <name> runPatrol <Patrolname>

      • Dieses Kommando startet die vordefinierterte Überwachungstour einer PTZ-Kamera.
        Die Überwachungstouren müssen dazu zunächst in der Synology Surveillance Station angelegt worden sein. Das geschieht in der PTZ-Steuerung im IP-Kamera Setup -> PTZ-Steuerung -> Überwachung. Die Überwachungstouren (Patrols) werden über das Kommando "get <name> caminfoall" eingelesen, welches beim Restart von FHEM automatisch abgearbeitet wird. Der Einlesevorgang kann durch ein Kamerapolling regelmäßig wiederholt werden. Ein langes Pollingintervall ist in diesem Fall empfehlenswert, da sich die Überwachungstouren nur im Fall der Neuanlage bzw. Änderung verändern werden. Nähere Informationen zur Anlage von Überwachungstouren sind in der Hilfe zur Surveillance Station enthalten.


      • set <name> goAbsPTZ [ X Y | up | down | left | right ]

      • Mit diesem Kommando wird eine PTZ-Kamera in Richtung einer wählbaren absoluten X/Y-Koordinate bewegt, oder zur maximalen Absolutposition in Richtung up/down/left/right. Die Option ist nur für Kameras verfügbar die das Reading "CapPTZAbs=true" (die Fähigkeit für PTZAbs-Aktionen) besitzen. Die Eigenschaften der Kamera kann mit "get <name> caminfoall" abgefragt werden.

        Beispiel für Ansteuerung absoluter X/Y-Koordinaten:
            set <name> goAbsPTZ 120 450
          
        Dieses Beispiel bewegt die Kameralinse in die Position X=120 und Y=450.
        Der Wertebereich ist dabei:
            X = 0 - 640      (0 - 319 bewegt nach links, 321 - 640 bewegt nach rechts, 320 bewegt die Linse nicht)
            Y = 0 - 480      (0 - 239 bewegt nach unten, 241 - 480 bewegt nach oben, 240 bewegt die Linse nicht) 
          
        Die Linse kann damit in kleinsten bis sehr großen Schritten in die gewünschte Richtung bewegt werden. Dieser Vorgang muß ggf. mehrfach wiederholt werden um die Kameralinse in die gewünschte Position zu bringen.

        Soll die Bewegung mit der maximalen Schrittweite erfolgen, kann zur Vereinfachung der Befehl:
           set <name> goAbsPTZ up [down ] [left] [right]
          
        verwendet werden. Die Optik wird in diesem Fall mit der größt möglichen Schrittweite zur Absolutposition in der angegebenen Richtung bewegt. Auch in diesem Fall muß der Vorgang ggf. mehrfach wiederholt werden um die Kameralinse in die gewünschte Position zu bringen.


      • set <name> move [ up | down | left | right | dir_X ] [Sekunden]

      • Mit diesem Kommando wird eine kontinuierliche Bewegung der PTZ-Kamera gestartet. Neben den vier Grundrichtungen up/down/left/right stehen auch Zwischenwinkelmaße "dir_X" zur Verfügung. Die Feinheit dieser Graduierung ist von der Kamera abhängig und kann dem Reading "CapPTZDirections" entnommen werden.

        Das Bogenmaß von 360 Grad teilt sich durch den Wert von "CapPTZDirections" und beschreibt die Bewegungsrichtungen beginnend mit "0=rechts" entgegen dem Uhrzeigersinn. D.h. bei einer Kamera mit "CapPTZDirections = 8" bedeutet dir_0 = rechts, dir_2 = oben, dir_4 = links, dir_6 = unten bzw. dir_1, dir_3, dir_5 und dir_7 die entsprechenden Zwischenrichtungen. Die möglichen Bewegungsrichtungen bei Kameras mit "CapPTZDirections = 32" sind dementsprechend kleinteiliger.

        Im Gegensatz zum "set <name> goAbsPTZ"-Befehl startet der Befehl "set <name> move" eine kontinuierliche Bewegung bis ein Stop-Kommando empfangen wird. Das Stop-Kommando wird nach Ablauf der optional anzugebenden Zeit [Sekunden] ausgelöst. Wird diese Laufzeit nicht angegeben, wird implizit Sekunde = 1 gesetzt.

        Beispiele:
         
            set <name> move up 0.5      : bewegt PTZ 0,5 Sek. (zzgl. Prozesszeit) nach oben
            set <name> move dir_1 1.5   : bewegt PTZ 1,5 Sek. (zzgl. Prozesszeit) nach rechts-oben 
            set <name> move dir_20 0.7  : bewegt PTZ 1,5 Sek. (zzgl. Prozesszeit) nach links-unten ("CapPTZDirections = 32)"
          


      • set <name> runView live_fw | live_link | live_open [<room>] | lastrec_fw | lastrec_open [<room>]

      • Mit "live_fw, live_link, live_open" wird ein Livestream (mjpeg-Stream) der Kamera, entweder als eingebettetes Image oder als generierter Link, gestartet.
        Die Option "live_open" startet ein separates Browserfenster mit dem Lifestream. Wird dabei optional der Raum mit angegeben, wird das Browserfenster nur gestartet wenn dieser Raum aktuell im Browser geöffnet ist.

        Der Zugriff auf die letzte Aufnahme einer Kamera kann über die Optionen "lastrec_fw" bzw. "lastrec_open" erfolgen. Bei Verwendung von "lastrec_fw" wird die letzte Aufnahme als eingebettetes iFrame-Objekt abgespielt. Es stehen entsprechende Steuerungselemente zur Wiedergabegeschwindigkeit usw. zur Verfügung.
        Durch Angabe des optionalen Raumes bei "lastrec_open" erfolgt die gleiche Einschränkung wie bei "live_open".

        Die Gestaltung der Fenster im FHEMWEB kann durch HTML-Tags im Attribut "htmlattr" beeinflusst werden.

        Beispiel:
            attr <name> htmlattr target=_blank width="500" height="375"
            attr <name> htmlattr target=_blank width=500,height=375
            attr <name> htmlattr width=700,height=525,top=200,left=300
          
        Mit diesen Attributwerten öffnet der Link (mit Klick) als weiteres Fenster/Browsertab. Wird der Stream als live_fw gestartet, ändert sich die Größe entsprechend der Angaben von Width und Hight.
        Das Kommando "set <name> runView live_open" startet den Livestreamlink sofort in einem neuen Browserfenster (longpoll=1 muß für WEB gesetzt sein). Dabei wird für jede aktive FHEM-Session eine Fensteröffnung initiiert. Soll dieses Verhalten geändert werden, kann "set <name> runView live_open <room>" verwendet werden um das Öffnen des Browserwindows in einem beliebigen, in einer FHEM-Session angezeigten Raum <room>, zu initiieren.
        Das gesetzte Attribut "livestreamprefix" überschreibt im Reading "LiveStreamUrl" die Angaben für Protokoll, Servername und Port. Damit kann z.B. die LiveStreamUrl für den Versand und externen Zugriff auf die SVS modifiziert werden.

        Beispiel:
            attr <name> livestreamprefix https://<Servername>:<Port>
          
        Der Livestream wird über das Kommando "set <name> stopView" wieder beendet.


      • set <name> extevent [ 1-10 ]

      • Dieses Kommando triggert ein externes Ereignis (1-10) in der SVS. Die Aktionen, die dieses Ereignis auslöst, sind zuvor in dem Aktionsregeleditor der SVS einzustellen. Es stehen die Ereignisse 1-10 zur Verfügung. In der Banchrichtigungs-App der SVS können auch Email, SMS oder Mobil (DS-Cam) Nachrichten ausgegeben werden wenn ein externes Ereignis ausgelöst wurde. Nähere Informationen dazu sind in der Hilfe zum Aktionsregeleditor zu finden. Der verwendete User benötigt Admin-Rechte in einer DSM-Session.



    Get
      Mit SSCam können die Eigenschaften der Surveillance Station und der Kameras abgefragt werden. Zur Zeit stehen dazu folgende Befehle zur Verfügung:
            get <name> caminfoall
            get <name> eventlist
            get <name> scanVirgin
            get <name> stmUrlPath
            get <name> svsinfo
            get <name> snapfileinfo
        
      Mit dem Befehl "get <name> caminfoall" werden abhängig von der Art der Kamera (z.B. Fix- oder PTZ-Kamera) die verfügbaren Eigenschaften ermittelt und als Readings zur Verfügung gestellt.
      So wird zum Beispiel das Reading "Availability" auf "disconnected" gesetzt falls die Kamera von der Surveillance Station getrennt wird und kann für weitere Verarbeitungen genutzt werden.
      Durch "get <name> eventlist" wird das Reading "CamEventNum" und "CamLastRec" aktualisiert, welches die Gesamtanzahl der registrierten Kameraevents und den Pfad / Namen der letzten Aufnahme enthält. Dieser Befehl wird implizit mit "get ... caminfoall" ausgeführt.
      Mit dem Attribut "videofolderMap" kann der Inhalt des Readings "VideoFolder" überschrieben werden. Dies kann von Vortel sein wenn das Surveillance-Verzeichnis der SVS an dem lokalen PC unter anderem Pfadnamen gemountet ist und darüber der Zugriff auf die Aufnahmen erfolgen soll (z.B. Verwendung Email-Versand).

      Ein DOIF-Beispiel für den Email-Versand von Snapshot und Aufnahmelink per Non-blocking sendmail:
           define CamHE1.snap.email DOIF ([CamHE1:"LastSnapFilename"]) 
           ({DebianMailnbl ('Recipient@Domain','Bewegungsalarm CamHE1','Eine Bewegung wurde an der Haustür registriert. Aufnahmelink: \  
           \[CamHE1:VideoFolder]\[CamHE1:CamLastRec]','/media/sf_surveillance/@Snapshot/[CamHE1:LastSnapFilename]')})
        
      Mit "get <name> snapfileinfo" wird der Filename des letzten Schnapschusses ermittelt. Der Befehl wird implizit mit "get <name> snap" ausgeführt.
      Der Befehl "get <name> svsinfo" ist eigentlich nicht von der Kamera abhängig, sondern ermittelt vielmehr allgemeine Informationen zur installierten SVS-Version und andere Eigenschaften.
      Die Funktionen "caminfoall" und "svsinfo" werden einmalig automatisch beim Start von FHEM ausgeführt um steuerungsrelevante Informationen zu sammeln.
      Es ist darauf zu achten dass die Credentials gespeichert wurden !

      • get <name> scanVirgin

      • Wie mit get caminfoall werden alle Informationen der SVS und Kamera abgerufen. Allerdings wird in jedem Fall eine neue Session ID generiert (neues Login), die Kamera-ID neu ermittelt und es werden alle notwendigen API-Parameter neu eingelesen.


      • get <name> stmUrlPath

      • Mit diesem Kommando wird der aktuelle Streamkey der Kamera abgerufen und das Reading mit dem Key-Wert gefüllt. Dieser Streamkey kann verwendet werden um eigene Aufrufe eines Livestreams aufzubauen (siehe Beispiel). Wenn das Attribut "showStmInfoFull" gesetzt ist, werden zusaätzliche Stream-Informationen wie "StmKeyUnicst", "StmKeymjpegHttp" ausgegeben. Diese Readings enthalten die gültigen Stream-Pfade zu einem Livestream und können z.B. versendet und von einer entsprechenden Anwendung ohne session Id geöffnet werden. Wenn das Attribut "livestreamprefix" (Format: "http(s)://<hostname><port>) gesetzt ist, wird der Servername und Port überschrieben soweit es sinnvoll ist. Wird Polling der Kameraeigenschaften genutzt, wird die stmUrlPath-Funktion automatisch mit ausgeführt.

        Beispiel für den Aufbau eines Http-Calls zu einem Livestream mit StmKey:
            http(s)://<hostname><port>/webapi/entry.cgi?api=SYNO.SurveillanceStation.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=5&StmKey="31fd87279976d89bb98409728cced890"
          
        cameraId (INTERNAL), StmKey müssen durch gültige Werte ersetzt werden.

        Hinweis:
        Falls der Stream-Aufruf versendet und von extern genutzt wird sowie hostname / port durch gültige Werte ersetzt und die Routerports entsprechend geöffnet werden, ist darauf zu achten dass diese sensiblen Daten nicht durch unauthorisierte Personen für den Zugriff genutzt werden können !




      Polling der Kameraeigenschaften:

      Die Abfrage der Kameraeigenschaften erfolgt automatisch, wenn das Attribut "pollcaminfoall" (siehe Attribute) mit einem Wert > 10 gesetzt wird.
      Per Default ist das Attribut "pollcaminfoall" nicht gesetzt und das automatische Polling nicht aktiv.
      Der Wert dieses Attributes legt das Intervall der Abfrage in Sekunden fest. Ist das Attribut nicht gesetzt oder < 10 wird kein automatisches Polling
      gestartet bzw. gestoppt wenn vorher der Wert > 10 gesetzt war.

      Das Attribut "pollcaminfoall" wird durch einen Watchdog-Timer überwacht. Änderungen des Attributwertes werden alle 90 Sekunden ausgewertet und entsprechend umgesetzt.
      Eine Änderung des Pollingstatus / Pollingintervalls wird im FHEM-Logfile protokolliert. Diese Protokollierung kann durch Setzen des Attributes "pollnologging=1" abgeschaltet werden.
      Dadurch kann ein unnötiges Anwachsen des Logs vermieden werden. Ab verbose=4 wird allerdings trotz gesetzten "pollnologging"-Attribut ein Log des Pollings
      zu Analysezwecken aktiviert.

      Wird FHEM neu gestartet, wird bei aktivierten Polling der ersten Datenabruf innerhalb 60s nach dem Start ausgeführt.

      Der Status des automatischen Pollings wird durch das Reading "PollState" signalisiert:

      • PollState = Active - automatisches Polling wird mit Intervall entsprechend "pollcaminfoall" ausgeführt
      • PollState = Inactive - automatisches Polling wird nicht ausgeführt

      Die Bedeutung der Readingwerte ist unter Readings beschrieben.

      Hinweise:

      Wird Polling eingesetzt, sollte das Intervall nur so kurz wie benötigt eingestellt werden da die ermittelten Werte überwiegend statisch sind.
      Das eingestellte Intervall sollte nicht kleiner sein als die Summe aller HTTP-Verarbeitungszeiten. Pro Pollingaufruf und Kamera werden ca. 10 - 20 Http-Calls gegen die Surveillance Station abgesetzt.

      Bei einem eingestellten HTTP-Timeout (siehe Attribut) "httptimeout") von 4 Sekunden kann die theoretische Verarbeitungszeit nicht höher als 80 Sekunden betragen.
      In dem Beispiel sollte man das Pollingintervall mit einem Sicherheitszuschlag auf nicht weniger 160 Sekunden setzen.
      Ein praktikabler Richtwert könnte zwischen 600 - 1800 (s) liegen.
      Sind mehrere Kameras in SSCam definiert, sollte "pollcaminfoall" nicht bei allen Kameras auf exakt den gleichen Wert gesetzt werden um Verarbeitungsengpässe
      und dadurch versursachte potentielle Fehlerquellen bei der Abfrage der Synology Surveillance Station zu vermeiden.
      Ein geringfügiger Unterschied zwischen den Pollingintervallen der definierten Kameras von z.B. 1s kann bereits als ausreichend angesehen werden.

    Internals

      Die Bedeutung der verwendeten Internals stellt die nachfolgende Liste dar:

      • CAMID - die ID der Kamera in der SVS, der Wert wird automatisch anhand des SVS-Kameranamens ermittelt.
      • CAMNAME - der Name der Kamera in der SVS
      • CREDENTIALS - der Wert ist "Set" wenn die Credentials gesetzt wurden
      • NAME - der Kameraname in FHEM
      • OPMODE - die zuletzt ausgeführte Operation des Moduls
      • SERVERADDR - IP-Adresse des SVS Hostes
      • SERVERPORT - der SVS-Port


    Readings

      Über den Pollingmechanismus bzw. durch Abfrage mit "Get" werden Readings bereitgestellt, deren Bedeutung in der nachfolgenden Tabelle dargestellt sind.
      Die übermittelten Readings können in Abhängigkeit des Kameratyps variieren.

      • Availability
      • - Verfügbarkeit der Kamera (disabled, enabled, disconnected, other)
      • CamEventNum
      • - liefert die Gesamtanzahl der in SVS registrierten Events der Kamera
      • CamExposureControl
      • - zeigt den aktuell eingestellten Typ der Belichtungssteuerung
      • CamExposureMode
      • - aktueller Belichtungsmodus (Day, Night, Auto, Schedule, Unknown)
      • CamForceEnableMulticast
      • - sagt aus ob die Kamera verpflichet ist Multicast einzuschalten.
      • CamIP
      • - IP-Adresse der Kamera
      • CamLastRec
      • - Pfad / Name der letzten Aufnahme
      • CamLastRecTime
      • - Datum / Startzeit - Stopzeit der letzten Aufnahme
      • CamLiveMode
      • - Quelle für Live-Ansicht (DS, Camera)
      • CamModel
      • - Kameramodell
      • CamMotDetSc
      • - Status der Bewegungserkennung (disabled, durch Kamera, durch SVS) und deren Parameter
      • CamPort
      • - IP-Port der Kamera
      • CamPreRecTime
      • - Dauer der der Voraufzeichnung in Sekunden (Einstellung in SVS)
      • CamRecShare
      • - gemeinsamer Ordner auf der DS für Aufnahmen
      • CamRecVolume
      • - Volume auf der DS für Aufnahmen
      • CamVendor
      • - Kamerahersteller Bezeichnung
      • CamVideoFlip
      • - Ist das Video gedreht
      • CamVideoMirror
      • - Ist das Video gespiegelt
      • CapAudioOut
      • - Fähigkeit der Kamera zur Audioausgabe über Surveillance Station (false/true)
      • CapChangeSpeed
      • - Fähigkeit der Kamera verschiedene Bewegungsgeschwindigkeiten auszuführen
      • CapPTZAbs
      • - Fähigkeit der Kamera für absolute PTZ-Aktionen
      • CapPTZAutoFocus
      • - Fähigkeit der Kamera für Autofokus Aktionen
      • CapPTZDirections
      • - die verfügbaren PTZ-Richtungen der Kamera
      • CapPTZFocus
      • - Art der Kameraunterstützung für Fokussierung
      • CapPTZHome
      • - Unterstützung der Kamera für Home-Position
      • CapPTZIris
      • - Unterstützung der Kamera für Iris-Aktion
      • CapPTZPan
      • - Unterstützung der Kamera für Pan-Aktion
      • CapPTZTilt
      • - Unterstützung der Kamera für Tilt-Aktion
      • CapPTZZoom
      • - Unterstützung der Kamera für Zoom-Aktion
      • DeviceType
      • - Kameratyp (Camera, Video_Server, PTZ, Fisheye)
      • Error
      • - Meldungstext des letzten Fehlers
      • Errorcode
      • - Fehlercode des letzten Fehlers
      • LastSnapFilename
      • - der Filename des letzten Schnapschusses
      • LastSnapId
      • - die ID des letzten Schnapschusses
      • 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
      • 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.
      • StmKeyUnicst
      • - Uni-cast Stream Pfad der Kamera. (Attribut "showStmInfoFull" muss gesetzt sein)
      • StmKeymjpegHttp
      • - Mjpeg Stream Pfad (über http) der Kamera. (Attribut "showStmInfoFull" muss gesetzt sein)
      • SVScustomPortHttp
      • - benutzerdefinierter Port der Surveillance Station (HTTP) im DSM-Anwendungsportal (get mit "svsinfo")
      • SVScustomPortHttps
      • - benutzerdefinierter Port der Surveillance Station (HTTPS) im DSM-Anwendungsportal (get mit "svsinfo")
      • SVSlicenseNumber
      • - die Anzahl der installierten Kameralizenzen (get mit "svsinfo")
      • SVSuserPriv
      • - die effektiven Rechte des verwendeten Users nach dem Login (get mit "svsinfo")
      • SVSversion
      • - die Paketversion der installierten Surveillance Station (get mit "svsinfo")
      • UsedSpaceMB
      • - durch Aufnahmen der Kamera belegter Plattenplatz auf dem Volume
      • VideoFolder
      • - Pfad zu den aufgenommenen Videos


    Attribute

      • debugactivetoken
        wenn gesetzt wird der Status des Active-Tokens gelogged - nur für Debugging, nicht im normalen Betrieb benutzen !

      • disable
        deaktiviert das Gerätemodul bzw. die Gerätedefinition

      • httptimeout
        Timeout-Wert für HTTP-Aufrufe zur Synology Surveillance Station, Default: 4 Sekunden (wenn httptimeout = "0" oder nicht gesetzt)

      • htmlattr
        ergänzende Angaben zur Livestream-Url um das Verhalten wie Bildgröße zu beeinflussen

          Beispiel:
          attr <name> htmlattr width=500 height=325 top=200 left=300

      • livestreamprefix
        überschreibt die Angaben zu Protokoll, Servernamen und Port zur Weiterverwendung der Livestreamadresse als z.B. externer Link. Anzugeben in der Form "http(s)://<servername>:<port>"

      • loginRetries
        setzt die Anzahl der Login-Wiederholungen im Fehlerfall (default = 1)

      • noQuotesForSID
        dieses Attribut kann in bestimmten Fällen die Fehlermeldung "402 - permission denied" vermeiden und ein login ermöglichen.

      • pollcaminfoall
        Intervall der automatischen Eigenschaftsabfrage (Polling) einer Kamera (kleiner 10: kein Polling, größer 10: Polling mit Intervall)

      • pollnologging
        "0" bzw. nicht gesetzt = Logging Gerätepolling aktiv (default), "1" = Logging Gerätepolling inaktiv

      • rectime
        festgelegte Aufnahmezeit wenn eine Aufnahme gestartet wird. Mit rectime = 0 wird eine Endlosaufnahme gestartet. Ist "rectime" nicht gesetzt, wird der Defaultwert von 15s verwendet.

      • recextend
        "rectime" einer gestarteten Aufnahme wird neu gesetzt. Dadurch verlängert sich die Aufnahemzeit einer laufenden Aufnahme

      • session
        Auswahl der Login-Session. Nicht gesetzt oder "DSM" -> session wird mit DSM aufgebaut (Standard). "SurveillanceStation" -> Session-Aufbau erfolgt mit SVS

      • simu_SVSversion
        simuliert eine andere SVS-Version. (es ist nur eine niedrigere als die installierte SVS Version möglich !)

      • showStmInfoFull
        zusaätzliche Streaminformationen wie LiveStreamUrl, StmKeyUnicst, StmKeymjpegHttp werden ausgegeben

      • showPassInLog
        wenn gesetzt wird das verwendete Passwort im Logfile (verbose 4) angezeigt. (default = 0)

      • videofolderMap
        ersetzt den Inhalt des Readings "VideoFolder", Verwendung z.B. bei gemounteten Verzeichnissen

      • verbose

        • Es werden verschiedene Verbose-Level unterstützt. Dies sind im Einzelnen:
          0 - Start/Stop-Ereignisse werden geloggt
          1 - Fehlermeldungen werden geloggt
          2 - Meldungen über wichtige Ereignisse oder Alarme
          3 - gesendete Kommandos werden geloggt
          4 - gesendete und empfangene Daten werden geloggt
          5 - alle Ausgaben zur Fehleranalyse werden geloggt. ACHTUNG: möglicherweise werden sehr viele Daten in das Logfile geschrieben!

      • readingFnAttributes


=end html_DE =cut