Enable/disable one of the camera from shell

All questions/comments regarding the Surveillance Station using IP Cameras may be placed here
Forum rules
We've moved! Head over to Synology Community (community.synology.com) to meet up with our team and other Synology enthusiasts!
boxx
I'm New!
I'm New!
Posts: 5
Joined: Mon Sep 17, 2012 7:03 pm

Re: Enable/disable one of the camera from shell

Unread post by boxx » Mon Sep 17, 2012 7:41 pm

cant make it work on version 4.1 and ss6

can someone please make a guide to make the script and to use it with openremote

boxx
I'm New!
I'm New!
Posts: 5
Joined: Mon Sep 17, 2012 7:03 pm

Re: Enable/disable one of the camera from shell

Unread post by boxx » Tue Sep 18, 2012 9:51 am

Problem solved. Now have a button ther turns camera on and off. If anyone want help with this please let me know.

Install Openremote on Synology (http://pcloadletter.co.uk/2011/10/25/op ... -synology/)

Then make 2 .sh files.

1. Cam_on.sh

Code: Select all

wget --keep-session-cookies --save-cookies /volume1/public/syno-cookies.txt -O /volume1/public/syno-output4.txt --post-data "username=admin&passwd=PASSWORD&submit=submit" "http://diskstation:5000/webman/login.cgi"
wget --load-cookies /volume1/public/syno-cookies.txt -O /volume1/public/syno-output5.txt "http://diskstation:5000/webman/3rdparty/SurveillanceStation/cgi/index.cgi"
wget --load-cookies /volume1/public/syno-cookies.txt -O /volume1/public/syno-output6.txt "http://diskstation:5000/webman/3rdparty/SurveillanceStation/cgi/camera.cgi?_dc=1334307710115&action=cameraEnable&idList=1"
2. Cam_off.sh

Code: Select all

wget --keep-session-cookies --save-cookies /volume1/public/syno-cookies.txt -O /volume1/public/syno-output1.txt --post-data "username=admin&passwd=PASSWORD&submit=submit" "http://diskstation:5000/webman/login.cgi"
wget --load-cookies /volume1/public/syno-cookies.txt -O /volume1/public/syno-output2.txt "http://diskstation:5000/webman/3rdparty/SurveillanceStation/cgi/index.cgi"
wget --load-cookies /volume1/public/syno-cookies.txt -O /volume1/public/syno-output3.txt "http://diskstation:5000/webman/3rdparty/SurveillanceStation/cgi/camera.cgi?_dc=1334307710115&action=cameraDisable&idList=1"
uploade the files to public folder.

use openremote to make buttons to turn on off cam.

create command, and use "Shell execution protocol", in path write /bin/sh, in Command param write /volume1/public/Cam_on or Cam_off.

then you are set to go.

dsuser0815
I'm New!
I'm New!
Posts: 4
Joined: Mon Nov 05, 2012 12:19 pm

Re: Enable/disable one of the camera from shell

Unread post by dsuser0815 » Sat Nov 24, 2012 6:41 pm

Hi,

Logon procudure has changed in DSM 4.1, however this is how I got it working:

http://tencopies.blogspot.de/2012/11/en ... meras.html

dsuser0815
I'm New!
I'm New!
Posts: 4
Joined: Mon Nov 05, 2012 12:19 pm

Re: Enable/disable one of the camera from shell

Unread post by dsuser0815 » Sat Nov 24, 2012 7:50 pm

Synology changed the logon process in DSM 4.1, however this works for me now, using the new CGI API to login, then after accessing "index.cgi" once I can enable / disable the cameras again:

wget --keep-session-cookies --save-cookies syno-cookies.txt -O- "http://DISKSTATION:9900/webapi/auth.cgi ... d=PASSWORD"

wget --load-cookies syno-cookies.txt -O- "http://DISKSTATION:9900/webman/3rdparty ... /index.cgi"

wget --load-cookies syno-cookies.txt -O- "http://DISKSTATION:9900/webman/3rdparty ... 4&idList=1"

wget wget --load-cookies syno-cookies.txt -O- "http://DISKSTATION:9900/webman/3rdparty ... 4&idList=2"

http://tencopies.blogspot.de/2012/11/en ... meras.html

Roelio
Trainee
Trainee
Posts: 14
Joined: Mon Jul 30, 2012 7:52 am

Re: Enable/disable one of the camera from shell

Unread post by Roelio » Fri Dec 07, 2012 11:01 pm

Is there a easy way for us to make it work with the latest patch?

I have placed a new topic about a iPhone app with the feature to turn it on and off.

http://forum.synology.com/enu/viewtopic ... 13&start=0

pat31
I'm New!
I'm New!
Posts: 5
Joined: Thu May 21, 2009 1:14 pm

Re: Enable/disable one of the camera from shell

Unread post by pat31 » Sun Feb 22, 2015 9:57 pm

In case some people are interested here is a copy of the script I built for the new Synology Surveillance Station 7.0-3742

This script can be run from local or remote Linux server and use the Synology API.

You can enable or disable camera, go to preset, start or stop recording, trigger an external event (new in version 7 of Surveillance Station), switch email notification for motion detection on or off

You just give all the commands you want to do in parameters and start with -login and stop with -logout. -clean will delete all log file for the current logid (generated randomly)

If you want to print result add -verbose after -logout but before -clean

Example to enable cam 1 and start recording and disable cam 2 at same time:

cameracmd -login -camera=1 -enable -recordon -camera=2 -disable -logout -verbose -clean

For list of cmd : cameracmd -help

Hope this will help...

Patrick

Save following to cameracmd file or download it here : http://www.weblink.fr/camera-cmd

Code: Select all

#!/bin/sh
ID="$RANDOM"
VER="1"
PASS="mypass"
SERVEUR="192.168.0.100:5000"
while [ $# -gt 0 ]
do
  key="$1"
  case $key in
    -l|-login)
       echo "Login">/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --keep-session-cookies --save-cookies /tmp/syno-cookies-${ID}.txt -O- "http://${SERVEUR}/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=${VER}&account=admin&passwd=${PASS}">>/tmp/camres-${ID}.txt
       ;;
    -logout)
       echo "Logout">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O- "http://${SERVEUR}/webapi/auth.cgi?api=SYNO.API.Auth&method=Logout&version=${VER}">>/tmp/camres-${ID}.txt
       rm /tmp/syno-cookies-${ID}.txt
       ;;
    -clean)
       rm /tmp/camres-${ID}.txt
       ;;
    -v|-verbose)
       cat /tmp/camres-${ID}.txt
       ;;
    -i=*|-id=*)
       ID="${1#*=}"
       ;;
    -p|-printid)
       echo "${ID}"
       ;;   
    -c=*|-camera=*)
       CAM="${1#*=}"
       ;;
    -e|-enable)
       echo "Enable">>/tmp/camres-${ID}.txt 
       VER="3"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Enable&version=${VER}&cameraIds=${CAM}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -d|-disable)
       echo "Disable">>/tmp/camres-${ID}.txt 
       VER="3"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Disable&version=${VER}&cameraIds=${CAM}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -notify=*)
       EID="${1#*=}"
       echo "Notify">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.Notification.Filter&method=Set&5=${EID}&version=${VER}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -event=*)
       EID="${1#*=}"
       echo "Event">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.ExternalEvent&method=Trigger&eventId=${EID}&version=${VER}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -preset=*)
       PID="${1#*=}"
       echo "Preset">>/tmp/camres-${ID}.txt 
       VER="1"
        wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webman/3rdparty/SurveillanceStation/cgi/cameraPreset.cgi?action=presetExecute&camId=${CAM}&position=${PID}&speed=3&isPreview=1">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -recordon)
       echo "recordon">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.ExternalRecording&method=Record&action=start&version=${VER}&cameraId=${CAM}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -recordoff)
       echo "recordoff">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.ExternalRecording&method=Record&action=stop&version=${VER}&cameraId=${CAM}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -h|-help)
       echo "[-camera=camid] [-enable] [-disable] [-recordon] [-recordoff] [-preset=prstid] [-notify=0|1] [-printid] [-id=logid] [-login] [-logout] [-verbose] [-clean]"
       ;;
    *)
       echo "unknown:$1"
       ;;
  esac
  shift
done

erocm123
I'm New!
I'm New!
Posts: 4
Joined: Fri Dec 06, 2013 6:44 pm

Re: Enable/disable one of the camera from shell

Unread post by erocm123 » Wed Mar 04, 2015 9:28 pm

Wow, thanks for the code! It works great and saved me a lot of time figuring it out on my own. I did add an additional case for creating a snapshot if anyone else wants to use it:

Code: Select all

    -snapshot)
       echo "Snapshot">>/tmp/camres-${ID}.txt
       VER="2"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O picture-${ID}.jpg "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=GetSnapshot&version=${VER}&cameraId=${CAM}">>/tmp/camres-${ID}.txt
       ;;
pat31 wrote:In case some people are interested here is a copy of the script I built for the new Synology Surveillance Station 7.0-3742

This script can be run from local or remote Linux server and use the Synology API.

You can enable or disable camera, go to preset, start or stop recording, trigger an external event (new in version 7 of Surveillance Station), switch email notification for motion detection on or off

You just give all the commands you want to do in parameters and start with -login and stop with -logout. -clean will delete all log file for the current logid (generated randomly)

If you want to print result add -verbose after -logout but before -clean

Example to enable cam 1 and start recording and disable cam 2 at same time:

cameracmd -login -camera=1 -enable -recordon -camera=2 -disable -logout -verbose -clean

For list of cmd : cameracmd -help

Hope this will help...

Patrick

Save following to cameracmd file or download it here : http://www.weblink.fr/camera-cmd

Code: Select all

#!/bin/sh
ID="$RANDOM"
VER="1"
PASS="mypass"
SERVEUR="192.168.0.100:5000"
while [ $# -gt 0 ]
do
  key="$1"
  case $key in
    -l|-login)
       echo "Login">/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --keep-session-cookies --save-cookies /tmp/syno-cookies-${ID}.txt -O- "http://${SERVEUR}/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=${VER}&account=admin&passwd=${PASS}">>/tmp/camres-${ID}.txt
       ;;
    -logout)
       echo "Logout">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O- "http://${SERVEUR}/webapi/auth.cgi?api=SYNO.API.Auth&method=Logout&version=${VER}">>/tmp/camres-${ID}.txt
       rm /tmp/syno-cookies-${ID}.txt
       ;;
    -clean)
       rm /tmp/camres-${ID}.txt
       ;;
    -v|-verbose)
       cat /tmp/camres-${ID}.txt
       ;;
    -i=*|-id=*)
       ID="${1#*=}"
       ;;
    -p|-printid)
       echo "${ID}"
       ;;   
    -c=*|-camera=*)
       CAM="${1#*=}"
       ;;
    -e|-enable)
       echo "Enable">>/tmp/camres-${ID}.txt 
       VER="3"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Enable&version=${VER}&cameraIds=${CAM}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -d|-disable)
       echo "Disable">>/tmp/camres-${ID}.txt 
       VER="3"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Disable&version=${VER}&cameraIds=${CAM}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -notify=*)
       EID="${1#*=}"
       echo "Notify">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.Notification.Filter&method=Set&5=${EID}&version=${VER}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -event=*)
       EID="${1#*=}"
       echo "Event">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.ExternalEvent&method=Trigger&eventId=${EID}&version=${VER}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -preset=*)
       PID="${1#*=}"
       echo "Preset">>/tmp/camres-${ID}.txt 
       VER="1"
        wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webman/3rdparty/SurveillanceStation/cgi/cameraPreset.cgi?action=presetExecute&camId=${CAM}&position=${PID}&speed=3&isPreview=1">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -recordon)
       echo "recordon">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.ExternalRecording&method=Record&action=start&version=${VER}&cameraId=${CAM}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -recordoff)
       echo "recordoff">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.ExternalRecording&method=Record&action=stop&version=${VER}&cameraId=${CAM}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -h|-help)
       echo "[-camera=camid] [-enable] [-disable] [-recordon] [-recordoff] [-preset=prstid] [-notify=0|1] [-printid] [-id=logid] [-login] [-logout] [-verbose] [-clean]"
       ;;
    *)
       echo "unknown:$1"
       ;;
  esac
  shift
done

tehnoinstyle
Rookie
Rookie
Posts: 37
Joined: Wed May 27, 2015 8:21 am

Re: Enable/disable one of the camera from shell

Unread post by tehnoinstyle » Thu Jul 02, 2015 9:33 am

pat31 wrote:In case some people are interested here is a copy of the script I built for the new Synology Surveillance Station 7.0-3742

This script can be run from local or remote Linux server and use the Synology API.

You can enable or disable camera, go to preset, start or stop recording, trigger an external event (new in version 7 of Surveillance Station), switch email notification for motion detection on or off

You just give all the commands you want to do in parameters and start with -login and stop with -logout. -clean will delete all log file for the current logid (generated randomly)

If you want to print result add -verbose after -logout but before -clean

Example to enable cam 1 and start recording and disable cam 2 at same time:

cameracmd -login -camera=1 -enable -recordon -camera=2 -disable -logout -verbose -clean

For list of cmd : cameracmd -help

Hope this will help...

Patrick

Save following to cameracmd file or download it here : http://www.weblink.fr/camera-cmd

Code: Select all

#!/bin/sh
ID="$RANDOM"
VER="1"
PASS="mypass"
SERVEUR="192.168.0.100:5000"
while [ $# -gt 0 ]
do
  key="$1"
  case $key in
    -l|-login)
       echo "Login">/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --keep-session-cookies --save-cookies /tmp/syno-cookies-${ID}.txt -O- "http://${SERVEUR}/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=${VER}&account=admin&passwd=${PASS}">>/tmp/camres-${ID}.txt
       ;;
    -logout)
       echo "Logout">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O- "http://${SERVEUR}/webapi/auth.cgi?api=SYNO.API.Auth&method=Logout&version=${VER}">>/tmp/camres-${ID}.txt
       rm /tmp/syno-cookies-${ID}.txt
       ;;
    -clean)
       rm /tmp/camres-${ID}.txt
       ;;
    -v|-verbose)
       cat /tmp/camres-${ID}.txt
       ;;
    -i=*|-id=*)
       ID="${1#*=}"
       ;;
    -p|-printid)
       echo "${ID}"
       ;;   
    -c=*|-camera=*)
       CAM="${1#*=}"
       ;;
    -e|-enable)
       echo "Enable">>/tmp/camres-${ID}.txt 
       VER="3"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Enable&version=${VER}&cameraIds=${CAM}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -d|-disable)
       echo "Disable">>/tmp/camres-${ID}.txt 
       VER="3"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=Disable&version=${VER}&cameraIds=${CAM}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -notify=*)
       EID="${1#*=}"
       echo "Notify">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.Notification.Filter&method=Set&5=${EID}&version=${VER}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -event=*)
       EID="${1#*=}"
       echo "Event">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.ExternalEvent&method=Trigger&eventId=${EID}&version=${VER}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -preset=*)
       PID="${1#*=}"
       echo "Preset">>/tmp/camres-${ID}.txt 
       VER="1"
        wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webman/3rdparty/SurveillanceStation/cgi/cameraPreset.cgi?action=presetExecute&camId=${CAM}&position=${PID}&speed=3&isPreview=1">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -recordon)
       echo "recordon">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.ExternalRecording&method=Record&action=start&version=${VER}&cameraId=${CAM}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -recordoff)
       echo "recordoff">>/tmp/camres-${ID}.txt 
       VER="1"
       wget -q --load-cookies /tmp/syno-cookies-${ID}.txt -O-  "http://${SERVEUR}/webapi/entry.cgi?api=SYNO.SurveillanceStation.ExternalRecording&method=Record&action=stop&version=${VER}&cameraId=${CAM}">>/tmp/camres-${ID}.txt
       echo "">>/tmp/camres-${ID}.txt 
       ;;
    -h|-help)
       echo "[-camera=camid] [-enable] [-disable] [-recordon] [-recordoff] [-preset=prstid] [-notify=0|1] [-printid] [-id=logid] [-login] [-logout] [-verbose] [-clean]"
       ;;
    *)
       echo "unknown:$1"
       ;;
  esac
  shift
done
Hi.
Can you help me make a script to control Audio Station? (I have a little knowledge)
I have OpenRemote running on Synology, and I want to create the following commands:

Code: Select all

Auth = "http://192.168.1.7:5000/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=admin&passwd=12345&session=AudioStation&format=cookie"
Logout = "http://192.168.1.7:5000/webapi/auth.cgi?api=SYNO.API.Auth&version=1&method=logout&session=AudioStation"
Play = "http://192.168.1.7:5000/webapi/AudioStation/remote_player.cgi?api=SYNO.AudioStation.RemotePlayer&method=control&action=play&id=__SYNO_USB_PLAYER__&version=2"
Start song = "http://192.168.1.7:5000/webapi/AudioStation/remote_player.cgi?api=SYNO.AudioStation.RemotePlayer&method=control&action=play&id=__SYNO_USB_PLAYER__&value=music_14&version=2"
Start PlayList = "http://192.168.1.7:5000/webapi/AudioStation/remote_player.cgi?api=SYNO.AudioStation.RemotePlayer&method=control&action=play&id=__SYNO_USB_PLAYER__&value=playlist_shared_normal/1&version=2"
Pause = "http://192.168.1.7:5000/webapi/AudioStation/remote_player.cgi?api=SYNO.AudioStation.RemotePlayer&method=control&action=pause&id=__SYNO_USB_PLAYER__&version=2"
Stop = "http://192.168.1.7:5000/webapi/AudioStation/remote_player.cgi?api=SYNO.AudioStation.RemotePlayer&method=control&action=stop&id=__SYNO_USB_PLAYER__&version=2"
Next = "http://192.168.1.7:5000/webapi/AudioStation/remote_player.cgi?api=SYNO.AudioStation.RemotePlayer&method=control&action=next&id=__SYNO_USB_PLAYER__&version=2"
Prev = "http://192.168.1.7:5000/webapi/AudioStation/remote_player.cgi?api=SYNO.AudioStation.RemotePlayer&method=control&action=prev&id=__SYNO_USB_PLAYER__&version=2"
and be able to run Playback is this song or playlist.
Thankyou.

wickey
I'm New!
I'm New!
Posts: 2
Joined: Mon Aug 24, 2015 8:46 am

Re: Enable/disable one of the camera from shell

Unread post by wickey » Mon Aug 24, 2015 9:20 am

Is there any way to check randomly whether motion is detected or not.
through web API i couldn't see any url. Is there any SSH,telnet or web API command for that.

I want to trigger some action from outside the SS when motion detected.

Please help.

mariengb
Trainee
Trainee
Posts: 11
Joined: Tue Apr 28, 2015 7:56 am

Re: Enable/disable one of the camera from shell

Unread post by mariengb » Mon Nov 16, 2015 7:39 pm

Bonjour Pat31,

Bon malgré le fait que nous soyons tous les deux Français je continuerais en Anglais pour faciliter le partage.

I'm very interested by your script especially to be able to start and stop my cameras from a remote system (here a basic curl on Nabaztag)

Here with my basic knowledge I understand that it's run through a server as a script.

First of all I'm quite sure that it's possible to "trigger/action" this script through a http/php request. But do you think it would be possible to code it directly in php in order to avoid one extra step?

Thanks :) it would help me q lot with the WAF

ravedog
Rookie
Rookie
Posts: 37
Joined: Sun Sep 22, 2013 8:30 am

Re: Enable/disable one of the camera from shell

Unread post by ravedog » Sat Dec 26, 2015 9:11 am

pat31 wrote:In case some people are interested here is a copy of the script I built for the new Synology Surveillance Station 7.0-3742

This script can be run from local or remote Linux server and use the Synology API.

You can enable or disable camera, go to preset, start or stop recording, trigger an external event (new in version 7 of Surveillance Station), switch email notification for motion detection on or off

You just give all the commands you want to do in parameters and start with -login and stop with -logout. -clean will delete all log file for the current logid (generated randomly)

I tried the script from my Mac and I got some errors. The command I issued was

Code: Select all

./cameracmd.sh -login -camera=1 -enable -recordon -camera=2 -disable -logout -verbose -clean
The result was:

Code: Select all

Login
{"success":true}
Enable
{"error":{"code":100,"errors":{"param1":"","param2":"","success":false}},"success":false}
recordon
{"error":{"code":401},"success":false}
Disable
{"error":{"code":100,"errors":{"param1":"","param2":"","success":false}},"success":false}
Logout
{"success":true}
Any ideas?
_________________________
Synology: 415+ running DSM 5.2-5644 Update 5
Packages: Surveillance Station 7.1.x, VPN 1.2.x.
Clients: Macs on 10.11.x and iOS devices on 10.x
Physical Network: Cat6/Cat5e on 2 Gigabit switches (CCTV on one). IP's thru static & MAC assigned IP's.
Wireless/Router: Eero, Ubiquiti Uni-Fi AC AP & Ubiquiti NanoStation M5/Loco M5 (gate IP Cameras).

lilo
I'm New!
I'm New!
Posts: 7
Joined: Sun Jan 22, 2012 9:20 pm

Re: Enable/disable one of the camera from shell

Unread post by lilo » Mon Jan 04, 2016 12:19 pm

I've adapted pat31 scripts to the latest API - it currently runs sucessfully with SurveillanceStation 6.3 - as soon as I've cleaned it up I'll post it to this forum.

Basically I have implemented the official API found at: https://global.download.synology.com/do ... I_v2.0.pdf

Example also at
http://forum.synology.com/enu/viewtopic ... 23&t=88555

My target is to have my OpenWrt router detect the MAC-address of my mobile's WLAN and disable the cameras or the motion detection.

Give me another 24-48 hours to show you the results...

lilo
I'm New!
I'm New!
Posts: 7
Joined: Sun Jan 22, 2012 9:20 pm

Re: Enable/disable one of the camera from shell

Unread post by lilo » Tue Jan 05, 2016 12:05 am

So I've written 3 scripts from the scratch to fit my purpose - provided AS-IS no warranty whatsoever - therefore and more I license the scripts under MIT (https://opensource.org/licenses/MIT)

Scripts run on a SurveillanceStation 6.3

1. syno-disable-cameras.sh

Code: Select all

#!/bin/bash
#The MIT License (MIT)
#
#Copyright (c) 2015 oliver.retzl
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
##########################################################################################################################################
#Scriptname:    syno-disable-cameras.sh
#Purpose:       disables cameras on surveillance station
#Author:        Oliver Retzl
#License:       https://opensource.org/licenses/MIT
#Prerequisites: 1. add user directly with manager profile in surveillance station (no DSM account required)
#               2. change User, Passwd, URL and cameraIds in the section below
#               3. script requires GNU wget 1.16+ (run opkg update; opkg upgrade wget on your router)
#               4. script requires GNU bash 4.3+
#Usage:         /bin/bash <path>/syno-disable-camera.sh
#References:
#       -Offical Synology-API: https://global.download.synology.com/download/Document/DeveloperGuide/Surveillance_Station_Web_API_v2.0.pdf
#       -Forumthread: http://forum.synology.com/enu/viewtopic.php?f=82&t=47074&start=15
#       -Thanks to pat31 for his example-script: http://www.weblink.fr/camera-cmd

######## Configuration
SYNO_SS_USER=""
SYNO_SS_PASS=""
SYNO_URL="192.168.0.100:5000"
SYNO_CAMERAIDS="1,2"

######### Internal variables ############
COOKIESFILE="$0-cookies-$ID"
ID="$RANDOM"

###### Functions
#Check HTTP Response
function _cleanupCookies ()
{
 rm $COOKIESFILE
}

function _checkSynoResponse () 
{
  if [ $1 != '{"success":true}' ]
  then
        echo "$2 failed: "$RESPONSE
        _cleanupCookies
        exit -1
  fi
}

####### 1.step login
VER=1
METHOD="Login"
RESPONSE=`wget -q --keep-session-cookies --save-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/auth.cgi?api=SYNO.API.Auth&method=$METHOD&version=${VER}&account=${SYNO_SS_USER}&passwd=${SYNO_SS_PASS}&session=SurveillanceStation"`
_checkSynoResponse $RESPONSE $METHOD;

######## 2.step disable camera
VER=3
METHOD="Disable"
RESPONSE=`wget -q --load-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/SurveillanceStation/camera.cgi?api=SYNO.SurveillanceStation.Camera&method=$METHOD&version=$VER&cameraIds=$SYNO_CAMERAIDS"`
_checkSynoResponse $RESPONSE $METHOD;

######## 3.step logout
VER=1
METHOD="Logout"
RESPONSE=`wget -q --load-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/auth.cgi?api=SYNO.API.Auth&method=$METHOD&version=${VER}"`
_checkSynoResponse $RESPONSE $METHOD;

###### Cleanup
_cleanupCookies
exit
2.syno-enable-cameras.sh

Code: Select all

#!/bin/bash
#The MIT License (MIT)
#
#Copyright (c) 2015 oliver.retzl
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
##########################################################################################################################################
#Scriptname:    syno-enable-camera.sh
#Purpose:       enables cameras on surveillance station
#Author:        Oliver Retzl
#License:       https://opensource.org/licenses/MIT
#Prerequisites: 1. add user directly with manager profile in surveillance station (no DSM account required)
#               2. change User, Passwd, URL and cameraIds in the section below
#               3. script requires GNU wget 1.16+ (run opkg update; opkg upgrade wget on your router)
#               4. script requires GNU bash 4.3+
#Usage:         /bin/bash <path>/syno-disable-camera.sh
#References:
#       -Offical Synology-API: https://global.download.synology.com/download/Document/DeveloperGuide/Surveillance_Station_Web_API_v2.0.pdf
#       -Forumthread: http://forum.synology.com/enu/viewtopic.php?f=82&t=47074&start=15
#       -Thanks to pat31 for his example-script: http://www.weblink.fr/camera-cmd

######## Configuration
SYNO_SS_USER=""
SYNO_SS_PASS=""
SYNO_URL="192.168.0.100:5000"
SYNO_CAMERAIDS="1,2"

######### Internal variables ############
COOKIESFILE="$0-cookies-$ID"
ID="$RANDOM"

###### Functions
#Check HTTP Response
function _cleanupCookies ()
{
 rm $COOKIESFILE
}

function _checkSynoResponse () 
{
  if [ $1 != '{"success":true}' ]
  then
        echo "$2 failed: "$RESPONSE
        _cleanupCookies
        exit -1
  fi
}

####### 1.step login
VER=1
METHOD="Login"
RESPONSE=`wget -q --keep-session-cookies --save-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/auth.cgi?api=SYNO.API.Auth&method=$METHOD&version=${VER}&account=${SYNO_SS_USER}&passwd=${SYNO_SS_PASS}&session=SurveillanceStation"`
_checkSynoResponse $RESPONSE $METHOD;

######## 2.step enable camera
VER=3
METHOD="Enable"
RESPONSE=`wget -q --load-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/SurveillanceStation/camera.cgi?api=SYNO.SurveillanceStation.Camera&method=$METHOD&version=$VER&cameraIds=$SYNO_CAMERAIDS"`
_checkSynoResponse $RESPONSE $METHOD;

######## 3.step logout
VER=1
METHOD="Logout"
RESPONSE=`wget -q --load-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/auth.cgi?api=SYNO.API.Auth&method=$METHOD&version=${VER}"`
_checkSynoResponse $RESPONSE $METHOD;

###### Cleanup
_cleanupCookies
exit
3.syno-list-cameras.sh

Code: Select all

#!/bin/bash
#The MIT License (MIT)
#
#Copyright (c) 2015 oliver.retzl
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
##########################################################################################################################################
#Scriptname:    syno-list-camera.sh
#Purpose:       list cameras on surveillance station
#Author:        Oliver Retzl
#License:       https://opensource.org/licenses/MIT
#Prerequisites: 1. add user directly with manager profile in surveillance station (no DSM account required)
#               2. change User, Passwd, URL and cameraIds in the section below
#               3. script requires GNU wget 1.16+ (run opkg update; opkg upgrade wget on your router)
#               4. script requires GNU bash 4.3+
#Usage:         /bin/bash <path>/syno-disable-camera.sh
#References:
#       -Offical Synology-API: https://global.download.synology.com/download/Document/DeveloperGuide/Surveillance_Station_Web_API_v2.0.pdf
#       -Forumthread: http://forum.synology.com/enu/viewtopic.php?f=82&t=47074&start=15
#       -Thanks to pat31 for his example-script: http://www.weblink.fr/camera-cmd

######## Configuration
SYNO_SS_USER=""
SYNO_SS_PASS=""
SYNO_URL="192.168.0.100:5000"
SYNO_CAMERAIDS="1,2"

######### Internal variables ############
COOKIESFILE="$0-cookies-$ID"
ID="$RANDOM" 
  
###### Functions
#Check HTTP Response
function _cleanupCookies ()
{ 
 rm $COOKIESFILE
}

function _checkSynoResponse () 
{
  if [ $1 != '{"success":true}' ]
  then
        echo "$2 failed: "$RESPONSE
        _cleanupCookies
        exit -1
  fi
}

####### 1.step login
VER=1
METHOD="Login"
RESPONSE=`wget -q --keep-session-cookies --save-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/auth.cgi?api=SYNO.API.Auth&method=$METHOD&version=${VER}&account=${SYNO_SS_USER}&passwd=${SYNO_SS_PASS}&session=SurveillanceStation"`
_checkSynoResponse $RESPONSE $METHOD; 

######## 2.step list cameras
VER=3
METHOD="List"
RESPONSE=`wget -q --load-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/SurveillanceStation/camera.cgi?api=SYNO.SurveillanceStation.Camera&method=$METHOD&version=$VER&start=0&limit=99"`
echo "List-Reponse:"
echo $RESPONSE

######## 3.step logout
VER=1
METHOD="Logout"
RESPONSE=`wget -q --load-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/auth.cgi?api=SYNO.API.Auth&method=$METHOD&version=${VER}"`
_checkSynoResponse $RESPONSE $METHOD;

###### Cleanup
_cleanupCookies
exit
4.Trigger based on MAC-address of my mobile

Code: Select all

#!/bin/bash
#The MIT License (MIT)
#
#Copyright (c) 2015 oliver.retzl
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
##########################################################################################################################################
#Scriptname:    wlan-trigger.sh 
#Purpose:       script monitors wlan0 and triggers script when specific MAC-adress connects or disconnects to the router
#Author:        Oliver Retzl
#License:       https://opensource.org/licenses/MIT
#Prerequisites: 1. OpenWRT or other busybox/shell enabled router
#               2. script requires "iw dev"
#               3. script requires GNU bash 4.3+
#Usage:         - run automatically by adding "nohup /bin/wlan-trigger.sh &" to "/etc/rc.local"
#               - run manually in shell and stop it with ctrl-c
#References:
#       -Thanks to dir2cas for his example-script: https://forum.openwrt.org/viewtopic.php?id=29075

############################# SCRIPT GLOBAL VARIABLES #########
#Debug Settings
DEBUG_MODE=true

#if you want to DEBUG with finite Loop - change comments at while loop
LOOPCYCLE=0
LOOPLIMIT=10

#Monitoring Settings
# MAC-Adress to be detected
WLAN_CLIENTMAC="12:34:56:78:90:AB"

#Start Scripts if MAC is in/out of range
RUN_SCRIPT_IN_RANGE='/bin/echo "MAC entered the building"'
RUN_SCRIPT_OUT_RANGE='/bin/echo "MAC left the buildling"'

#RUN_SCRIPT_IN_RANGE='/bin/bash /bin/disable-something.sh'
#RUN_SCRIPT_OUT_RANGE='/bin/bash /bin/enable-something.sh'

SLEEPTIME=3
##############################################################
#Internal Status-Flag
WLAN_CLIENTMAC_IS_ONLINE=0

#Finite Loop for debugging
#while [ "$LOOPCYCLE" -lt "$LOOPLIMIT" ]

while [ true ]
do
  HITS=`iw dev wlan0 station dump | grep "$WLAN_CLIENTMAC" | wc -l`

if [ $DEBUG_MODE = "true" ]
  then
  echo -n "Cycle: $LOOPCYCLE "        # -n suppresses newline.
  echo ""
  #DEBUG iw dev wlan0 station dump |grep Station
  echo "hits: $HITS"
fi

  if [ "$HITS" -gt 0 ]
   then
    if [ "$WLAN_CLIENTMAC_IS_ONLINE" -eq 0 ]
      then
        $RUN_SCRIPT_IN_RANGE
        WLAN_CLIENTMAC_IS_ONLINE=1
    fi
  else
    if [ "$WLAN_CLIENTMAC_IS_ONLINE" -eq 1 ]
      then
        $RUN_SCRIPT_OUT_RANGE
        WLAN_CLIENTMAC_IS_ONLINE=0
     fi
  fi

  sleep $SLEEPTIME

#  LOOPCYCLE=`expr $LOOPCYCLE + 1`   
done

exit


Let me know if you can use them or if you need any further extensions

ravedog
Rookie
Rookie
Posts: 37
Joined: Sun Sep 22, 2013 8:30 am

Re: Enable/disable one of the camera from shell

Unread post by ravedog » Thu Jan 07, 2016 11:12 pm

This is amazing. Great code. Heavily documented. Awesome. Will try it next couple days.

Had another question.

I am installing some PIR's in some locations to detect movement. My raspberry Pi will handle the detection. Once it does it will issue a command to the SS to start recording. That part works. I can issue a command after detection stops to stop recording.

My question: I have the cameras currently to pre roll and post roll certain amounts based on movement from the cameras (and a couple using the SS for detection). If I disable motion from cameras and the SS and trigger recording thru my Pi using my scripts, will it still use the pre roll and post roll. If it does, when I issue a stop recording command will it post roll after the stop is issued?

Thank you so much for your help!!!
_________________________
Synology: 415+ running DSM 5.2-5644 Update 5
Packages: Surveillance Station 7.1.x, VPN 1.2.x.
Clients: Macs on 10.11.x and iOS devices on 10.x
Physical Network: Cat6/Cat5e on 2 Gigabit switches (CCTV on one). IP's thru static & MAC assigned IP's.
Wireless/Router: Eero, Ubiquiti Uni-Fi AC AP & Ubiquiti NanoStation M5/Loco M5 (gate IP Cameras).

lilo
I'm New!
I'm New!
Posts: 7
Joined: Sun Jan 22, 2012 9:20 pm

Re: Enable/disable one of the camera from shell

Unread post by lilo » Sun Jan 17, 2016 3:57 pm

@ravedoc:
My question: I have the cameras currently to pre roll and post roll certain amounts based on movement from the cameras (and a couple using the SS for detection). If I disable motion from cameras and the SS and trigger recording thru my Pi using my scripts, will it still use the pre roll and post roll. If it does, when I issue a stop recording command will it post roll after the stop is issued?
You may take a look at the offical API-documentation: https://global.download.synology.com/do ... I_v2.0.pdf

According to chapter 2.3.8.1 - settings "camPreRecTime/ camPostRecTime" it is possible to configure pre- and post-roll times on a per camera base within Surveillance Station.

This is also possible within the "Edit Camera" dialog inside the SS-GUI - I keep checking the API-doc first before looking into the GUI - I don't know why....

So as long as you are starting the recording via the SS-API (you may take a look at the scripts from above), the recording should consider this pre-/postroll configuration.

Could you try and confirm this?

Cheers o

PS: May I ask you to give us a glimpse on your camera-setup/ configuration?

Locked

Return to “Surveillance Station”