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>