Vera VistaCam PT Control

Shell scripts, etc., that do interesting things.
NewfD90
Posts: 61
Joined: Fri Mar 17, 2017 10:18 am

Vera VistaCam PT Control

Post by NewfD90 »

Recent Vera refugee here. Transition went remarkably smoothly. Some things were harder; others easier. Regardless, I couldn't find a way to control the Pan and Tilt controls on my old Vera IP camera, so I fired up WireShark and figured out the controls. Below is a simple bash shell script that implements all those controls. Attached is a screen cap of a control screen that implements some of these functions.

Code: Select all

#!/bin/sh
IP_ADDR="userid:pass@192.168.1.1:PortNum"

case "$1" in
        left)
                curl http://$IP_ADDR/decoder_control.cgi?command=4
                sleep 1
                curl http://$IP_ADDR/decoder_control.cgi?command=1
                ;;
        right)
                curl http://$IP_ADDR/decoder_control.cgi?command=6
                sleep 1
                curl http://$IP_ADDR/decoder_control.cgi?command=1
                ;;
        up)
                curl http://$IP_ADDR/decoder_control.cgi?command=0
                sleep 1
                curl http://$IP_ADDR/decoder_control.cgi?command=1
                ;;
        down)
                curl http://$IP_ADDR/decoder_control.cgi?command=2
                sleep 1
                curl http://$IP_ADDR/decoder_control.cgi?command=1
                ;;
        upleft)
                curl http://$IP_ADDR/decoder_control.cgi?command=90
                sleep 1
                curl http://$IP_ADDR/decoder_control.cgi?command=1
                ;;
        upright)
                curl http://$IP_ADDR/decoder_control.cgi?command=91
                sleep 1
                curl http://$IP_ADDR/decoder_control.cgi?command=1
                ;;
        downleft)
                curl http://$IP_ADDR/decoder_control.cgi?command=92
                sleep 1
                curl http://$IP_ADDR/decoder_control.cgi?command=1
                ;;
        downright)
                curl http://$IP_ADDR/decoder_control.cgi?command=93
                sleep 1
                curl http://$IP_ADDR/decoder_control.cgi?command=1
                ;;
        vpatrol)
                curl http://$IP_ADDR/decoder_control.cgi?command=26
                ;;
        stopvpatrol)
                curl http://$IP_ADDR/decoder_control.cgi?command=27
                ;;
        hpatrol)
                curl http://$IP_ADDR/decoder_control.cgi?command=28
                ;;
        stophpatrol)
                curl http://$IP_ADDR/decoder_control.cgi?command=29
                ;;
        pos)
                curl http://$IP_ADDR/decoder_control.cgi?command=$((30 + ($2*2-1)))
                ;;
        *)
                echo "Syntax:"
                echo "    up, down, left, right"
                echo "    upleft     : up and left diagonally"
                echo "    upright    : up and right diagonally"
                echo "    downleft   : down and left diagonally"
                echo "    downright  : down and right diagonally"
                echo "    vpatrol    : vertical patrol"
                echo "    stopvpatrol: stop vertical patrol"
                echo "    hpatrol    : horizontal patrol"
                echo "    stophpatrol: stop horizontal patrol"
                echo "    pos N      : recall stored position N"
                exit 1
                ;;
esac

exit 0
Attachments
IMG_1183.jpg
IMG_1183.jpg (113.4 KiB) Viewed 28360 times
bkmar1192
Posts: 274
Joined: Sat Sep 12, 2015 11:23 am

Re: Vera VistaCam PT Control

Post by bkmar1192 »

My security camera plugin has an action to send a URL to a camera. Might be worth a try. It is completely untested function since I don't a camera to take commands. Would be happy to work with you to get it working if you are interested.


Sent from my iPhone using Tapatalk
NewfD90
Posts: 61
Joined: Fri Mar 17, 2017 10:18 am

Re: Vera VistaCam PT Control

Post by NewfD90 »

I saw that capability in your plugin. However, for each movement, the camera requires the requisite command, followed by a stop command. The time in between defines how far the camera moves. So to do that within Indigo seemed a bit complicated, hence the script.

Thanks though!
Chance
bkmar1192
Posts: 274
Joined: Sat Sep 12, 2015 11:23 am

Re: Vera VistaCam PT Control

Post by bkmar1192 »

Couldn't you create an action group that would issue the first command then issue the stop with a delay. For example, a 10* clockwise action and a 10* counter clockwise action.


Sent from my iPhone using Tapatalk
NewfD90
Posts: 61
Joined: Fri Mar 17, 2017 10:18 am

Re: Vera VistaCam PT Control

Post by NewfD90 »

OK, I was going to play with this, but the Action for sending a command via URL is no longer there! I swear I saw it yesterday, but maybe that was just from reading your manual.
Attachments
Untitled.png
Untitled.png (139.05 KiB) Viewed 28287 times
bkmar1192
Posts: 274
Joined: Sat Sep 12, 2015 11:23 am

Re: Vera VistaCam PT Control

Post by bkmar1192 »

I'll take a look tonight.


Sent from my iPhone using Tapatalk
bkmar1192
Posts: 274
Joined: Sat Sep 12, 2015 11:23 am

Re: Vera VistaCam PT Control

Post by bkmar1192 »

I just posted version 1.5.4 that fixes the issue of the Camera Command action not being displayed. Thanks.
NewfD90
Posts: 61
Joined: Fri Mar 17, 2017 10:18 am

Re: Vera VistaCam PT Control

Post by NewfD90 »

Got it and updated. Unfortunately, urllib doesn't like the URL. I'm sending a fully formed URL of the type http://user@ipAddr:port/path, which best I can tell seems to be what urlretrieve expects. Does any of the special characters need to be escaped? Perhaps run it through urlencode first?

Code: Select all

Traceback (most recent call last):
  File "plugin.py", line 843, in CameraCommand
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 98, in urlretrieve
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 245, in retrieve
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 213, in open
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 364, in open_http
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 377, in http_error
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 702, in http_error_401
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 766, in retry_http_basic_auth
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 795, in get_user_passwd
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 804, in prompt_user_passwd
EOFError: EOF when reading a line
bkmar1192
Posts: 274
Joined: Sat Sep 12, 2015 11:23 am

Re: Vera VistaCam PT Control

Post by bkmar1192 »

Try the urllib2 option in device setup. It has separate fields for user name and password. It is also a bit more resilient than urllib. Also, the http:// is assumed and does not need to be included.


Sent from my iPhone using Tapatalk
NewfD90
Posts: 61
Joined: Fri Mar 17, 2017 10:18 am

Re: Vera VistaCam PT Control

Post by NewfD90 »

That's how I have it setup. However, the plugin is coded to only use urllib for the CameraCommand call.
User avatar
jay (support)
Site Admin
Posts: 18376
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Vera VistaCam PT Control

Post by jay (support) »

Just a point of interest: we highly recommend using the requests library (included with Indigo 7+) for all http communication - it handles all authentication types, it's easy to use, extremely robust and very well supported.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
Post Reply

Return to “Other Scripts”