Close

Automation: Enabling cameras from the command-line

Learn how to turn an Android phone into an IP camera security system with Sighthound, download automation scripts & more.

Moderator: Staff

User avatar
harrison
 
Posts: 1
Joined: Thu Jul 10, 2014 5:18 pm

Automation: Enabling cameras from the command-line

by harrison » Thu Jul 10, 2014 5:36 pm

This morning I spent some time watching headers/responses in my browser's console, decided to see if I could control Sighthound from the command-line.

Created this file named test.xml:

Code: Select all
<?xml version="1.0"?><methodCall>
<methodName>enableCamera</methodName>
<params>
<param>
<value>
<string>MY_CAMERA_NAME</string>
</value>
</param>
<param>
<value>
<boolean>1</boolean>
</value>
</param>
</params>
</methodCall>


Ran http://curl.haxx.se/ (substituting MY_CAMERA_NAME above and USERNAME, PASSWORD, HOSTNAME and PORT below with the appropriate values):

Code: Select all
curl --user USERNAME:PASSWORD --header "Content-Type: application/xml" -X POST -d@test.xml 'http://HOSTNAME:PORT/xmlrpc/'


Server replies with:

Code: Select all
<?xml version='1.0'?>
<methodResponse>
<params>
<param>
<value><nil/></value></param>
</params>
</methodResponse>


...and it works, the camera is now on!

Is the API set in stone? Sometimes I forget to enable/disable the cameras. In lieu of an AppleScript interface this might be a nice way to control the application through cron.

no avatar
nomaam
 
Posts: 7
Joined: Sat Mar 28, 2015 2:24 am

Re: Automation: Enabling cameras from the command-line

by nomaam » Sat Mar 28, 2015 3:19 pm

Hey this is great! I, too, have been looking at ways to enable/disable the whole thing or even just certain rules based on an event.. ie - me leaving my house. I am thinking of this scenario:
  • Something polls my cell phone over my wifi (its a static IP) and waits for it to no longer be there (I left my house)
  • Kill (maybe gracefully) shuts down the Sighthound application
  • Script/piece of code somewhere enables the camera recording rule I have by replacing the *.rule file in the app data folder (windows 7) with another almost identical .rule file that has the checkbox enabled. (Attached two files to this message to see the difference) For anyone curious, you can go there and open those files in notepad. Enable your rule in Sighthound and go look at the file (somewhere around line 17 or 18). There is a "S01" or a "S00" that is always two lines below the line that says "sS'_isEnabled'". S00 = Disabled, S01 = Enabled. Rather than get fancy and writing code to change this line, I just have copies of both files (one with it enabled, one with it disabled) and toggle copying them back and forth on this step.
  • Fire up the Sighthound app again

A similar thing happens when returning. It notices I am back online and turns the rule(s) back off again in similar fashion

    Two things to think about:
  • Maybe have a timeout threshhold for if my cell phone is simply rebooting or is momentarily hiccuping on the network. Say a minute or two before deciding that I am, indeed, not home. Make it configurable.
  • Maybe have it not stop recording as soon as you pull up in your driveway and it sees your phone again. You might want it to continue for several minutes so the camera can catch the bad guys robbing you when you walk in, right?

What do you guys think? Any other ideas?
Attachments
2015-03-28 14_08_44-People in Home - EMAIL ALERT.rule - Notepad.png
The rule IS NOT enabled
(37.22 KiB) Downloaded 1220 times
2015-03-28 14_08_31-People in Home - EMAIL ALERT.rule - Notepad.png
The rule IS enabled
(37.23 KiB) Downloaded 1220 times

no avatar
erikvg01
 
Posts: 1
Joined: Sun Apr 05, 2015 11:01 am

Re: Automation: Enabling cameras from the command-line

by erikvg01 » Sun Apr 05, 2015 11:06 am

I was playing around with this suggestion, and with a TCPDump found that the method of enabling/disabling individual RULES is the same process as manipulating the camera on/off mode.

Here is an example of the xml file I call in the curl:

<?xml version="1.0"?><methodCall>
<methodName>remoteEnableRule</methodName>
<params>
<param>
<value>
<string>NAMEOFRULE</string>
</value>
</param>
<param>
<value>
<boolean>0</boolean>
</value>
</param>
</params>
</methodCall>

Simply replace NAMEOFRULE with the exact name of the rule, spaces are supported here. A bool 1 turns it on, bool 0 turns it off.

This has allowed me to ensure I alert on events ONLY while I am home.

no avatar
rprobst
 
Posts: 19
Joined: Sun Apr 27, 2014 5:16 pm

Re: Automation: Enabling cameras from the command-line

by rprobst » Tue Apr 14, 2015 12:09 am

Thanks, this worked great. just fyi for others trying it, the names of the cameras appears to be case sensitive.

no avatar
Vulcan
 
Posts: 3
Joined: Thu Jan 15, 2015 7:45 pm

Re: Automation: Enabling cameras from the command-line

by Vulcan » Tue Apr 28, 2015 5:12 pm

Hi guys
Could you explain how to do this automation so a normal person can learn to do it :-)

I would love to be able to turn of and on the camera with my iPhone.

You make an xml script. How to do that?
How to execute the xml script in my iPhone?

Sorry for my bad knowledge in programming

no avatar
303
 
Posts: 44
Joined: Sat May 03, 2014 4:02 am
Location: Palo Alto, CA

Re: Automation: Enabling cameras from the command-line

by 303 » Tue Sep 08, 2015 3:58 am

Is this still working for you guys? No longer works for me under https.

edit: nevermind :) works once you figure out the auth

no avatar
hepcat72
 
Posts: 7
Joined: Wed Jun 18, 2014 7:52 pm

Re: Automation: Enabling cameras from the command-line

by hepcat72 » Wed Jun 14, 2017 3:51 pm

I have tried the suggestion for enabling/disabling rules, but the response I get is 301 moved permanently. I don't think I have the latest sighthound. Is the address for curl different for different versions? I have 3.0.2.

erikvg01 wrote:I was playing around with this suggestion, and with a TCPDump found that the method of enabling/disabling individual RULES is the same process as manipulating the camera on/off mode....

User avatar
ryan
 
Posts: 1015
Joined: Wed Aug 25, 2010 2:52 pm
Location: Palo Alto, California

Re: Automation: Enabling cameras from the command-line

by ryan » Wed Jun 14, 2017 4:25 pm

The original post is from SV2 where remote access ran over http, did you update the command to use https?
Learn more about Sighthound Video in our support pages - Reference Guide | All Articles
Are you a developer? Check out our cloud APIs - Demo | Docs

no avatar
hepcat72
 
Posts: 7
Joined: Wed Jun 18, 2014 7:52 pm

Re: Automation: Enabling cameras from the command-line

by hepcat72 » Thu Jun 15, 2017 4:11 pm

I worked out a solution that works for me to enable/disable camera rules in Sighthound Video. Thought I would share:

http://bit.ly/2t73Sms

no avatar
jmwhooper
 
Posts: 5
Joined: Fri Jul 27, 2018 5:53 pm

Re: Automation: Enabling cameras from the command-line

by jmwhooper » Fri Jul 27, 2018 6:00 pm

I know this is an old thread but it's really helped me get the remote enabling of rules working. The one thing I want to do though is to enable and disable multiple rules in one curl command. I've got an xml file I post via curl to the local server and it can enable or disable a single rule at a time.

I've no idea if I can specify more than one xml file in the curl request or can have more than one rule with a boolean on / off in a single xml file, or if it can be done at all!

Any help would be most appreciated!


Return to Hacker's Corner