I’m playing around with the API on my Hikvision IP camera.
Reading this thread here I have just been able to send curl commands from my Windows laptop, to the camera to turn on or off the motion detection and that worked.
However to do this I had to create two XML files, one for on and one for off.
I know how to send Curl commands from Vera in a scene for example but I don’t know about also using xml payload files.
Ideally I don’t want to even have to use the xml files and just have a single line curl command that turns on or off the motion detection on the camera, but searching on Google I haven’t seen anyway to do that yet.
I guess I could just upload the xml files to Vera but its not ideal.
Searching for curl on Vera there are two locations however.
You don’t want to use ‘-T’ because that uses a different mechanism to transfer the data than the API is likely expecting. Use -d '@/path/to/MotionDetectionOn.xml'. Notice that I’ve enclosed the argument to “-d” in single quotes. If the argument to “-d” starts with an @, it is interpreted as a filename that is read and used for the payload. Otherwise (no @) the string is used directly as the payload. So this will read the file in and use its contents.
To run curl from scene Lua, you use os.execute("curl -s -m 15 -X POST [etc]")
I would recommend using SSH to log in to your Vera and running test curls from there until you get the right mix of options. I’ve included “-s” (silent) in my example, as well as “-m 15” (timeout 15 seconds), which I consider both recommended/best practice for “automated” requests. The “-X POST” tells it to use a HTTP POST rather than a GET, which is better/usually necessary when sending payload data (definitely necessary whenever the payload is/can be >1024 bytes, but usually fine when it’s smaller so you can just use it all the time).
os.execute("curl -s -m 15 -X POST -d '@/etc/cmh-ludl/MotionDetectionOn.xml' 'http://admin:password@192.168.1.15/ISAPI/System/Video/inputs/channels/1/motionDetection'")
In the above, also notice that I’ve enclosed the URL in single quotes. I do this habitually with shell arguments in case the string contains (or could contain, if dynamically generated) special characters that the shell may try to grab/interpret first. The biggest offender here, IMO, is “&”, which appears in URLs with query parameters. If that character is not quoted (or escaped, that’s another way), the shell will grab it and do odd things with the remainder of the string after, but still issue the query, just cut off at the point the “&” appears, causing odd behavior that can be difficult to debug. Shell quoting and escaping is a whole big topic unto itself, but you’re on pretty safe ground with the example you’ve given, so I won’t go down that rabbit hole further.
Edit: you may need to include -H 'Content-Type: application/xml' before the URL so that curl can tell the API it’s sending XML data in the payload. The API may assume it and you may be fine without it, but some APIs require you to be very literal.
I’ve uploaded the two xml files in to the directory on Vera you suggested and I’ve tried running your command from the SSH terminal on Vera but it says:
-ash: syntax error: unexpected word (expecting “)”)
Which model do you use and what is your goal, i have managed to trigger manual recording of the camera via Vera without any xml files uploaded, just with use of curl command. So now i use triggers from vera to trigger and stop recordings.
It might help if you posted the entire command line you tried?
Edit: if you posted the “os.execute” part to the SSH command line, that’s incorrect. The “os.execute” is the scene Lua version. If you’re on the SSH command line, you just submit the stuff inside the double-quotes (i.e. starting with the word “curl” and ending with the closing single quote on the URL). Sorry if that wasn’t clear.
I’ve added a virtual switch for on / off and added some PLEG logic to send the commands to turn on or off the motion detection on the camera.
Handy now as there is washing out on the line blowing about, so I can now easily turn off motion detection and it stops all the alerts going to my phone and stops the camera from recording.
I can even ask Google Home to turn on or off that virtual switch as well.
Imperihome - Camera Motion Detection - Turned Off:
I have followed all the instructions from Rigpapa, but still can’t get it to work. I’m trying to set the motion dectection of my Hikvision camera to ON.
On the command prompt I’m using: curl -T motionDetection_on.xml http://admin:password@84.192.221.112:65002/ISAPI/System/Video/inputs/channels/1/motionDetection
Then went to Putty and logged in to my Vera3 (SSH).
There i’m using: curl -s -m 15 -X PUT -d '@/etc/cmh-ludl/motionDetection_on.xml' 'http://admin:password@84.192.221.112:65002/ISAPI/System/Video/inputs/channels/1/motionDetection'
Removed the underscore, but that didn’t work.
Changing the 8080 port? It has been a long time that I installed the camera…at the time I remember I could not use the 80 port because it was blocked.