From 1b155ce4d165b8b7e5bf245fb24c70de76a93714 Mon Sep 17 00:00:00 2001 From: nasseeder1 <> Date: Mon, 15 Feb 2016 20:53:55 +0000 Subject: [PATCH] 49_SSCAM: control of exposure mode day, night & auto is possible now git-svn-id: https://svn.fhem.de/fhem/trunk@10859 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 + fhem/FHEM/49_SSCam.pm | 167 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 160 insertions(+), 9 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index f3d0afdd8..275a15c0f 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature 49_SSCAM: control of exposure mode day, night & auto is + possible now - bugfix: 74_HOMBOT: some set commands not work - feature: 32_mailcheck: added set active/inactive commands - feature: 02_RSS: new attribute urlOverride diff --git a/fhem/FHEM/49_SSCam.pm b/fhem/FHEM/49_SSCam.pm index 0be0b22f2..4f958acfe 100644 --- a/fhem/FHEM/49_SSCam.pm +++ b/fhem/FHEM/49_SSCam.pm @@ -1,4 +1,4 @@ - ########################################################################################################## + ########################################################################################################## # $Id$ ########################################################################################################## # 49_SSCam.pm @@ -27,7 +27,8 @@ ########################################################################################################## # Versions History: # -# 1.14 the port in DEF-String is optional now, +# 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, @@ -131,7 +132,7 @@ sub SSCam_Define { my @a = split("[ \t][ \t]*", $def); if(int(@a) < 4) { - return "You need to specify more parameters.\n". "Format: define SSCAM "; + return "You need to specify more parameters.\n". "Format: define SSCAM [Port]"; } my $camname = $a[2]; @@ -150,6 +151,7 @@ sub SSCam_Define { $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"; # Startwerte setzen $attr{$name}{webCmd} = "on:off:snap:enable:disable"; # initiale Webkommandos setzen @@ -230,9 +232,10 @@ sub SSCam_Set { $setlist = "Unknown argument $opt, choose one of ". "credentials ". - # "expmode ". + "expmode:auto,day,night ". "on ". "off ". + # "motdetsc:disable,by_camera,by_SVS ". "snap ". "enable ". "disable ". @@ -271,6 +274,14 @@ sub SSCam_Set { if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} camdisable($hash); } + elsif ($opt eq "motdetsc") + { + 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: disable, by_camera, by_SVS !";} + + $hash->{HELPER}{MOTDETSC} = $prop; + cammotdetsc($hash); + } elsif ($opt eq "credentials") { return "Credentials are incomplete, use username password" if (!$prop || !$prop1); @@ -281,6 +292,9 @@ sub SSCam_Set { elsif ($opt eq "expmode") { 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") @@ -775,6 +789,61 @@ sub camexpmode ($) { } +############################################################################### +### Art der Bewegungserkennung setzen + +sub cammotdetsc ($) { + my ($hash) = @_; + my $camname = $hash->{CAMNAME}; + my $name = $hash->{NAME}; + my $logstr; + my $errorcode; + my $error; + + 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); + + $logstr = "ERROR - Setting of motion detection source of Camera $camname can't be executed - $error" ; + &printlog($hash,$logstr,"1"); + return; + } + + if ($hash->{HELPER}{ACTIVE} eq "off") { + + $logstr = "Setting of motion detection source of Camera $camname will be started now"; + &printlog($hash,$logstr,"4"); + + $hash->{OPMODE} = "MotDetSc"; + $hash->{HELPER}{ACTIVE} = "on"; + + if ($attr{$name}{debugactivetoken}) { + $logstr = "Active-Token was set by OPMODE: $hash->{OPMODE}" ; + &printlog($hash,$logstr,"3"); + } + + &getapisites_nonbl($hash); + } + else + { + InternalTimer(gettimeofday()+0.14, "cammotdetsc", $hash, 0); + } +} + + ############################################################################### ### Kamera Schappschuß aufnehmen @@ -1299,6 +1368,7 @@ sub getapisites_nonbl { my $apitakesnap = $hash->{HELPER}{APISNAPSHOT}; my $apiptz = $hash->{HELPER}{APIPTZ}; my $apisvsinfo = $hash->{HELPER}{APISVSINFO}; + my $apicamevent = $hash->{HELPER}{APICAMEVENT}; my $logstr; my $url; my $param; @@ -1315,7 +1385,7 @@ sub getapisites_nonbl { &printlog($hash,$logstr,"5"); # 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"; + $url = "http://$serveraddr:$serverport/webapi/query.cgi?api=$apiinfo&method=Query&version=1&query=$apiauth,$apiextrec,$apicam,$apitakesnap,$apiptz,$apisvsinfo,$apicamevent"; $logstr = "Call-Out now: $url"; &printlog($hash,$logstr,"4"); @@ -1351,6 +1421,7 @@ sub login_nonbl ($) { my $apitakesnap = $hash->{HELPER}{APISNAPSHOT}; my $apiptz = $hash->{HELPER}{APIPTZ}; my $apisvsinfo = $hash->{HELPER}{APISVSINFO}; + my $apicamevent = $hash->{HELPER}{APICAMEVENT}; my $data; my $logstr; my $url; @@ -1366,7 +1437,9 @@ sub login_nonbl ($) { my $apiptzpath; my $apiptzmaxver; my $apisvsinfopath; - my $apisvsinfomaxver; + my $apisvsinfomaxver; + my $apicameventpath; + my $apicameventmaxver; my $error; my $httptimeout; @@ -1488,6 +1561,18 @@ sub login_nonbl ($) { &printlog($hash, $logstr,"4"); $logstr = defined($apisvsinfomaxver) ? "MaxVersion of $apisvsinfo: $apisvsinfomaxver" : "MaxVersion of $apisvsinfo undefined - Surveillance Station may be stopped"; &printlog($hash, $logstr,"4"); + + # Pfad und Maxversion von "SYNO.Surveillance.Camera.Event" ermitteln + + $apicameventpath = $data->{'data'}->{$apicamevent}->{'path'}; + # Unterstriche im Ergebnis z.B. "_______entry.cgi" eleminieren + $apicameventpath =~ tr/_//d if (defined($apicameventpath)); + $apicameventmaxver = $data->{'data'}->{$apicamevent}->{'maxVersion'}; + + $logstr = defined($apicameventpath) ? "Path of $apicamevent selected: $apicameventpath" : "Path of $apicamevent undefined - Surveillance Station may be stopped"; + &printlog($hash, $logstr,"4"); + $logstr = defined($apicameventmaxver) ? "MaxVersion of $apicamevent: $apicameventmaxver" : "MaxVersion of $apicamevent undefined - Surveillance Station may be stopped"; + &printlog($hash, $logstr,"4"); # ermittelte Werte in $hash einfügen $hash->{HELPER}{APIAUTHPATH} = $apiauthpath; @@ -1502,6 +1587,8 @@ sub login_nonbl ($) { $hash->{HELPER}{APIPTZMAXVER} = $apiptzmaxver; $hash->{HELPER}{APISVSINFOPATH} = $apisvsinfopath; $hash->{HELPER}{APISVSINFOMAXVER} = $apisvsinfomaxver; + $hash->{HELPER}{APICAMEVENTPATH} = $apicameventpath; + $hash->{HELPER}{APICAMEVENTMAXVER} = $apicameventmaxver; # Setreading readingsBeginUpdate($hash); @@ -1773,6 +1860,9 @@ sub camop_nonbl ($) { 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 $sid = $hash->{HELPER}{SID}; my $OpMode = $hash->{OPMODE}; my $url; @@ -1789,6 +1879,8 @@ sub camop_nonbl ($) { my $n; my $id; my $httptimeout; + my $expmode; + my $motdetsc; # Verarbeitung der asynchronen Rückkehrdaten aus sub "getcamid_nonbl" if ($err ne "") # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist @@ -1978,7 +2070,30 @@ sub camop_nonbl ($) { } elsif ($OpMode eq "ExpMode") { - $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&version=\"$apicammaxver\"&method=\"SaveOptimizeParam\"&cameraIds=\"$camid\"&expMode=2&camParamChkList=1&_sid=\"$sid\""; + 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") + { + if ($hash->{HELPER}{MOTDETSC} eq "disable") { + $motdetsc = "-1"; + } + elsif ($hash->{HELPER}{MOTDETSC} eq "by_camera") { + $motdetsc = "0"; + } + elsif ($hash->{HELPER}{MOTDETSC} eq "by_SVS") { + $motdetsc = "1"; + } + + $url = "http://$serveraddr:$serverport/webapi/$apicameventpath?api=\"$apicamevent\"&version=\"$apicameventmaxver\"&method=\"ADParamSave\"&camId=\"$camid\"&source=$motdetsc&keep=true&_sid=\"$sid\""; } $logstr = "Call-Out now: $url"; @@ -2130,7 +2245,21 @@ sub camret_nonbl ($) { readingsEndUpdate($hash, 1); # Logausgabe - $logstr = "Camera $camname exposure mode was set"; + $logstr = "Camera $camname exposure mode was set to \"$hash->{HELPER}{EXPMODE}\""; + &printlog($hash,$logstr,"3"); + $logstr = "--- End Function cam: $OpMode nonblocking ---"; + &printlog($hash,$logstr,"4"); + } + elsif ($OpMode eq "MotDetSc") + { + # Setreading + readingsBeginUpdate($hash); + readingsBulkUpdate($hash,"Errorcode","none"); + readingsBulkUpdate($hash,"Error","none"); + readingsEndUpdate($hash, 1); + + # Logausgabe + $logstr = "Camera $camname motion detection source was set to \"$hash->{HELPER}{MOTDETSC}\""; &printlog($hash,$logstr,"3"); $logstr = "--- End Function cam: $OpMode nonblocking ---"; &printlog($hash,$logstr,"4"); @@ -2979,6 +3108,7 @@ return;
  • 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
  • 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)
  • Positioning of PTZ-cameras to absolute X/Y-coordinates
  • @@ -3084,6 +3214,7 @@ return;
  • set ... snap session: ServeillanceStation - observer
  • set ... disable session: ServeillanceStation - manager
  • set ... enable session: ServeillanceStation - manager
  • +
  • set ... expmode session: ServeillanceStation - manager
  • set ... goPreset 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
  • @@ -3120,6 +3251,7 @@ return; "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 "goPreset <Preset>": moves a PTZ-camera to a predefinied Preset-position "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 @@ -3190,7 +3322,15 @@ return; 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"). +

    + "set <name> goPreset <Preset>"

    Using this command you can move PTZ-c ameras to a predefined position.
    @@ -3474,6 +3614,7 @@ return;
  • 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
  • Abfrage von Kameraeigenschaften (auch mit Polling) sowie den Eigenschaften des installierten SVS-Paketes
  • Bewegen an eine vordefinierte Preset-Position (bei PTZ-Kameras)
  • Positionieren von PTZ-Kameras zu absoluten X/Y-Koordinaten
  • @@ -3575,6 +3716,7 @@ return;
  • set ... snap session: ServeillanceStation - Betrachter
  • set ... disable session: ServeillanceStation - Manager
  • set ... enable session: ServeillanceStation - Manager
  • +
  • set ... expmode session: ServeillanceStation - Manager
  • set ... goPreset 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
  • @@ -3612,6 +3754,7 @@ return; "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 "goPreset <Preset>": bewegt eine PTZ-Kamera zu einer vordefinierten Preset-Position "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 @@ -3683,6 +3826,12 @@ return;

    + "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. +

    + "set <name> goPreset <Preset>"

    Mit diesem Kommando können PTZ-Kameras in eine vordefininierte Position bewegt werden.