Http command for PTZ

znation

Young grasshopper
Joined
Aug 29, 2015
Messages
30
Reaction score
1
Hello,

I've a PT cam DS-2CD2F42FWD-IWS

(http://overseas.hikvision.com/en/Products_accessries_512_i5612.html)

Is it possible to control Pan/tilt by http command ?

There's this document : http://www.hikvisioneurope.com/portal/index.php?dir=Integration and Development Materials/00 CGI/&file=HIK_IPMD_V2.0_201312.pdf

It talk about command like this : /PTZCtrl/channels/1/PTZControl with command like PAN_RIGHT, TILT_UP ... how to run those commands correctly ?

Other question is it normal that with a pan/tilt cam, i can't set preset position ?

Thanks
 

Attachments

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,666
Reaction score
14,005
Location
USA
Yes, it is possible, but not with HTTP GET requests. Hikvision couldn't just make it easy, no, they had to require you to use the HTTP PUT request method which is so rarely used elsewhere in the world that it practically ensures everyone will have to write custom code to implement their API.

If you don't know your way around a programming language, then there is no easy answer. I bet you could send the appropriate commands with a program like curl (included in typical linux distributions) but I'm not familiar enough with curl to explain how.
 

znation

Young grasshopper
Joined
Aug 29, 2015
Messages
30
Reaction score
1
Thanks for your answer

Is it hard to implement HTTP PUT ?
 

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,666
Reaction score
14,005
Location
USA
Thanks for your answer

Is it hard to implement HTTP PUT ?
Using an HTTP client library in a programming language, using HTTP PUT is usually as easy as setting the request method to "PUT" and then writing the appropriate string to the request stream before you grab the response stream. Not hard, unless you don't know how to program or you are very unfamiliar with HTTP.
 

znation

Young grasshopper
Joined
Aug 29, 2015
Messages
30
Reaction score
1
On the official documentation it was written : Note: Up to 16 presets can be configured for the Network Mini PT Camera (that's mine)

I see presets, i see a pen when i go to a preset but it does nothing
 

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,666
Reaction score
14,005
Location
USA
On the official documentation it was written : Note: Up to 16 presets can be configured for the Network Mini PT Camera (that's mine)

I see presets, i see a pen when i go to a preset but it does nothing
I don't recall how Hikvision's web interface handles presets exactly, sorry.
 

znation

Young grasshopper
Joined
Aug 29, 2015
Messages
30
Reaction score
1
I know http a little but the way to http put never , i have to google, do i need a software ?
 

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,666
Reaction score
14,005
Location
USA
I know http a little but the way to http put never , i have to google, do i need a software ?
Yes ... (you need software for everything though).

You have not said why or how you want to control the camera, so I really have very little to go on here. I take it you are not a programmer, and will need pre-built software.

Maybe cURL is what you want. You can get it here: https://curl.haxx.se/download.html

This might help you figure out how to do HTTP PUT with cURL: http://stackoverflow.com/questions/13782198/how-to-do-a-put-request-with-curl
 

pozzello

Known around here
Joined
Oct 7, 2015
Messages
2,270
Reaction score
1,117
curl would be your tool for poking around at this to see what works.

building a curl command from the Hik doc in the OP, I would try something like this:

pozzello@sfo-lpapv:~$ curl -X PUT "http://<cam_ip>/PTZ/channels/<ID>/PTZControl" -d "command=[LIGHT|WIPER|FAN|etc...]&presetNo=<N>&patrolNo=<M>&mode=<X>&speed=<Y>"

or it might want the arguments in the URL query string like so:

pozzello@sfo-lpapv:~$ curl -X PUT "http://<cam_ip>/PTZ/channels/<ID>/PTZControl?command=[LIGHT|WIPER|FAN|etc...]&presetNo=<N>&patrolNo=<M>&mode=<X>&speed=<Y>"

a well-designed API would take 'em either way...
 

znation

Young grasshopper
Joined
Aug 29, 2015
Messages
30
Reaction score
1
Thanks for the answer.

By the way i need to run this on my home automation system running with a raspberry pi2

I can see capture screenshot with /Streaming/channels/1/picture but what do you think i could insert on the action line to pan right for example ?

I tried : curl -X PUT "http://192.168.0.5/PTZ/channels/1/PTZControl?command=[PAN_LEFT]" => KO

snap000043.jpg
 

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,666
Reaction score
14,005
Location
USA
Try running that command outside your HA system, in a normal terminal window and see what happens? I suspect your query is being rejected because it is not authenticated. Likely you need to add your camera login info (user name and password) to the curl line somewhere so that when prompted, curl can authenticate.

Also, if you were planning to use /PTZ/channels/1/PTZControl for panning, tilting, and zooming, I encourage a different approach instead. Try the /PTZCtrl/channels/<ID>/relative command that is defined a few pages further down in the document. It is a little more complicated because you have to send an XML string as part of the request body (not just part of the URL), but it will have the advantage of making the camera move a fixed amount with just one command as opposed to having to send a start command followed by a stop command with your original approach. If your stop command were to fail, then the camera would be stuck moving until you managed to fix it, which isn't cool. With the relative position command, there is no stop command required.

However for something like GOTO_PRESET, the original /PTZ/channels/1/PTZControl URL should be fine because that won't require a stop command.
 

pozzello

Known around here
Joined
Oct 7, 2015
Messages
2,270
Reaction score
1,117
try remove the []. i used them as a 'pick one of these', not meant to be included literally...

eg: curl -X PUT "http://192.168.0.5/PTZ/channels/1/PTZControl?command=PAN_LEFT
 

znation

Young grasshopper
Joined
Aug 29, 2015
Messages
30
Reaction score
1
Thanks for your help !

I tried curl -X PUT curl -X PUT http:// login: password@ip: port/PTZ/channels/1/PTZControl?command=PAN_LEFT

Here's the result which sounds better

<?xml version="1.0" encoding="UTF-8"?>
<ResponseStatus version="1.0" xmlns="http://www.hikvision.com/ver10/XMLSchema">
<requestURL>/PTZ/channels/1/PTZControl</requestURL>
<statusCode>1</statusCode>
<statusString>OK</statusString>
</ResponseStatus>

But nothing is moving :-(
 

nayr

IPCT Contributor
Joined
Jul 16, 2014
Messages
9,329
Reaction score
5,325
Location
Denver, CO
Yeah, and a well-designed API would use POST instead of PUT. PUT is practically unused by modern web development.
Agreed, GET/PUT was the old way, POST is the new Modern way.. the problem with GET/PUT is its loaded with security issues, for example if your implementing a pure URL API and you send sensitive information over a GET request, even if you send it over a HTTPS connection the browser has that sensitive information stored in its URL History, and now days that history can be synced with the cloud and multiple devices instantly over insecure channels and that will have completely exposed your credentials in plain text.

If you implement the same API with a POST the data is sent in the clients request headers and not in the URL string, so it prevents that scenario from happening.
 

pozzello

Known around here
Joined
Oct 7, 2015
Messages
2,270
Reaction score
1,117
try adding the 'mode' and 'speed' query parameters, per the doc you originally link to (~page 109):

curl -X PUT curl -X PUT http:// login: password@ip: port/PTZ/channels/1/PTZControl?command=PAN_LEFT&speed=1&mode=start
 

znation

Young grasshopper
Joined
Aug 29, 2015
Messages
30
Reaction score
1
Hello,

Sorry for the delay i wasn't available to work on my PT cam.

Here's the result, now i can run curl command without any problem, i suceeded to reboot my cam with curl command : curl -X PUT "http://user:password@IP:port/System/reboot"

But i still can't control my cam by curl after http request viewing (when i press arrow to move the cam on hikvision interface) i can see url is /ISAPI/PTZCtrl/channels/1/continuous with an xml file : <PTZData><pan>-100</pan><tilt>0</tilt></PTZData> (when i move to the left)

But how to write it to do it myself ? I don't know how to insert the xml part on the command

Thanks for your help

EDIT : fount it !!!!
curl -X PUT -T TEST_PTZ.xml http://login:password@ip/PTZCtrl/channels/1/Continuous (in TEST_PTZ.xml : <PTZData><pan>-100</pan><tilt>0</tilt></PTZData>)

thanks for everything, hope it can help somebody too
 
Last edited by a moderator:
Top