Record start or alarm trigger with an http command?

Brenner

Young grasshopper
Mar 17, 2015
44
0
Hello @all.

Sorry for my bad english first.

I use some DS-2CD2332I ad I´m very happy with it.

Now I want to integrate the cam in my homeautomation system (eq.3 Homematic). I want to trigger the cams for a record if some Homematic sensors (Door/window sensor, Motionsensor) detect a action.


For example the motion sensor 1 detect a motion. Now cam1 and cam2 should start a record and should send a email with some pictures.


I´ve read the Hikvision API documentation but I can´t find a way to tell the camera that there is an alarm or that the should record a video. Can you help me with that?

Thanks in advance.
 
Thanks. But can´t find a way to start recording from outside :-(
 
I was able to get something like this working tonight on my December 2014 HikVision DS-2CD2632F-IS with 5.2.5 firmware which is a model features hardware alarm input and output lines.

I have no experience with any of their other cameras or devices so please don't take anything I write below as likely to work for another device, or even the same device built at another time or with different firmware.

The REST APIs exposed are reasonably well documented in HIK_IPMD_V2.0_201312.pdf, but they provide no mechanism that I can find of triggering recordings. They do show, however, how to trigger the output alarm line to be high or low. From what I can tell the output line appears to have about 1.2k ohm resistance to its ground wire when "high" and an open circuit when "low." The input appears to be a pullup resistor to about 3.3v to be "high" when open circuit and "low" when shorted to ground.

So, I configured the input alarm to be "NO" (normally open), directly wired the alarm output pin to the alarm input pin (again do not copy me!) and raised and lowered the output pin using HTTP PUT methods using the Google Chrome POSTMAN app:

PUT to http://<camera ip>/IO/outputs/1/trigger
Body:
Code:
<IOPortData version="1.0" xmlns="http://www.hikvision.com/ver10/XMLSchema">
    <outputState>high</outputState>
</IOPortData>

this "high" setting triggers the input alarm, and

PUT to http://<camera ip>/IO/outputs/1/trigger
Body:
Code:
<IOPortData version="1.0" xmlns="http://www.hikvision.com/ver10/XMLSchema">
    <outputState>low</outputState>
</IOPortData>


stops the alarm.

To make this call you must authenticate as an "operator" type user that has the following privileges:
  • "Remote: Parameters Settings"
  • "Remote: Notify Surveillance Center / Trigger Alarm Output"

I was hoping that only the latter would be needed as it may be less of a security risks. In fact I would rather have my own code running on the camera, triggered over the network with something like MQTT but I haven't had much luck figuring that out yet.

Unfortunately the link above to wrightwoodsurveillance.com is no longer working, and Google does not appear to have a cache of it. Does anybody know of any other good API resources for these cameras?
 
Last edited by a moderator:
Camera response after sending the above written command:

<?xml version="1.0" encoding="UTF-8"?>
<ResponseStatus version="1.0" xmlns="http://www.hikvision.com/ver10/XMLSchema">
<requestURL>/IO/outputs/1/trigger</requestURL>
<statusCode>4</statusCode>
<statusString>Invalid Operation</statusString>
</ResponseStatus>

I geuss that it worked to comunicate with my camera but that the operation was not correct.
Anyone that knows how to send correct command to trigger alarm? My IP cameras are running on latest SW version 5.2.3.
 
I geuss that it worked to comunicate with my camera but that the operation was not correct.
Anyone that knows how to send correct command to trigger alarm? My IP cameras are running on latest SW version 5.2.3.

Which camera model do you have? Not all models have hardware alarm input/output lines. Also, if your camera does have these lines, you may have to enable and configure them first in the camera configuration.
 
Aha i thought it would work on all ip cameras because of only software dependent.
Models i have is the following:
Hikvision DS-2CD2032F-I
Hikvision DS-2CD2132F-I

How can i see if my cameras have the software feature to receive commands over IP?
 
Last edited by a moderator:
Aha i thought it would work on all ip cameras because of only software dependent.
Models i have is the following:
Hikvision DS-2CD2032F-I
Hikvision DS-2CD2132F-I

Unfortunately neither of these has alarm input/output pins, so the "solution" I describe here will not work. Model numbers that have a -S at the end (or -IS, etc) have alarm input and output pins.

How can i see if my cameras have the software feature to receive commands over IP?

I haven't yet found a purely software-only method for sending commands that trigger a recording. Another idea I had was an "illegal network login" exception but the firmware on my cameras only allows this to trigger emails and surveillance center notifications; it cannot trigger a recording.

Randy
 
For one of my DVRs DS-7208HUHI-F2/N i do it with PHP:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<?php
error_reporting(E_DEPRECATED | E_ERROR | E_PARSE);

ini_set('xdebug.var_display_max_depth', -1);
ini_set('xdebug.var_display_max_children', -1);
ini_set('xdebug.var_display_max_data', -1);

class XMLSerializer {

public static function generateValidXmlFromObj(stdClass $obj, $node_block='nodes', $node_name='node', $arr_attr=array()) {
$arr = get_object_vars($obj);
return self::generateValidXmlFromArray($arr, $node_block, $node_name, $arr_attr);
}

public static function generateValidXmlFromArray($array, $node_block='nodes', $node_name='node', $arr_attr=array()) {
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';

if($node_block)$xml .= '<' . $node_block . '>';
$xml .= self::generateXmlFromArray($array, $node_name, $arr_attr);
if($node_block)$xml .= '</' . $node_block . '>';

return $xml;
}

private static function generateXmlFromArray($array, $node_name, $arr_attr=array()) {
$xml = '';

if (is_array($array) || is_object($array)) {
foreach ($array as $key=>$value) {
$attr = '';
if(array_key_exists($key, $arr_attr))$attr = ' '.$arr_attr[$key];

if (is_numeric($key)) {
if($node_name)$key = $node_name;
}

$xml .= '<' . $key . $attr . '>' . self::generateXmlFromArray($value, $node_name, $arr_attr) . '</' . $key . '>';
}
} else {
$xml = htmlspecialchars($array, ENT_QUOTES);
}

return $xml;
}
}

$url = "http://USER:PASS@IP:PORT/ISAPI/System/IO/outputs/OUTPUTID/status";
$response = file_get_contents($url);
echo "<h2>DVR System Alarm output Status:</h2>";
var_dump($response);


if($_POST['SendXml']){
$url = "http://USER:PASS@IP:PORT/ISAPI/System/IO/outputs/OUTPUTID/trigger";

$object->IOPortData->outputState = "high";//“high,low” means "on,off"

$xml_generater = new XMLSerializer;
$xml = $xml_generater->generateValidXmlFromObj($object, false, false, array('IOPortData' => "xmlns=\"Oops:The page you are visiting may have been deleted,renamed or inaccessible.""));
$params = array(
'http' => array(
'method' => 'PUT',
'header' => "Content-type: text/xml",
'content' => $xml
)
);

echo '<h2>Sending Xml to DVR:</h2>';
$ctx = stream_context_create($params);
$response = @file_get_contents($url, false, $ctx);
var_dump($response);

$url = "http://USER:PASS@IP:PORT/ISAPI/System/IO/outputs/OUTPUTID/status";
$response = file_get_contents($url);
echo '<h2>DVR Result:</h2>';
$response = file_get_contents($url);
var_dump($response);
}


?>
<form action="<?=$_SERVER['REQUEST_URI']?>" method="post">
<input type="hidden" name="SendXml" value="1">
<button type="submit">Send Xml</button>
</form>
</body>
</html>
 
Last edited:
http://down.dipol.com.pl/Cctv/-Hikvision-/isapi/HIKVISION ISAPI_2.0-RaCM Service.pdf

7.4.1 /ISAPI/ContentMgmt/record/control/manual/start/tracks/<ID>
This resource is used to manually Start the recording track, regardless of recording mode.
To Enable or Disable (i.e. permanent Stop) the track, the configuration interface should be used to update the track configuration object to set the enable/disable value accordingly.

7.4.2 /ISAPI/ContentMgmt/record/control/manual/stop/tracks/<ID>

---

curl -X PUT "http://user:passwd@192.168.1.28:80/ISAPI/ContentMgmt/record/control/manual/start/track/101"
– starts recording channel 1 stream 1 (main stream)

Response:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<ResponseStatus version="1.0" xmlns="urn:psialliance-org">
<requestURL>/ISAPI/ContentMgmt/record/control/manual/start/track/101</requestURL>
<statusCode>1</statusCode>
<statusString>OK</statusString>
<subStatusCode>ok</subStatusCode>
</ResponseStatus>

curl -X PUT "http://user:passwd@192.168.1.28:80/ISAPI/ContentMgmt/record/control/manual/stop/track/101"
– stops recording

201 - for main stream Channel 2
301 - etc…

Show all available tracks: “/ISAPI/ContentMgmt/record/tracks”

Tested on HiWatch(HikVision) DVR DS-H204Q
 
  • Like
Reactions: aster1x
Thanks !
Works also for me
Tested on HiWatch(Hikvision) HWN-2104H
To begin with I constantly got:

<statusValue>401</statusValue>
<statusString>Unauthorized</statusString>
</userCheck>

The solution was to change the NVR settings: SYSTEM/SECURITY/WEB validation to: digest/basic


 
Error 401 usually indicates a wrong Username or password.
401 can mean that credentials haven't been passed at all (unauthorized). I am in the same boat, I can't just pass credentials in the URL. So I am looking in the ISAPI documentation to see if there is a way of getting the key (that I see in authenticated traffic).

I am using the DS-KB8112-IM. It's a great device, but I have had a lot of trouble configuring it. Less flexibility all around.