Jump to content
Minglarn

Set OSD text with PHP (Hikvision DS-2CD2032-I )

Recommended Posts

Hi!!

Been following this forum for a while and have learned a lot!

A couple days ago I thought I could change the settings on my DS-2CD2032-I cam using PHP and XML.

 

Is it possible to do this cause I've tried this code:

 

<?php
$xml_data = '<?xml version="1.0" encoding="UTF-8"?>
<TextOverlay version="1.0" xmlns="http://www.hikvision.com/ver10/XMLSchema">
<id>1</id>
<enabled>true</enabled>
<posX>16</posX>
<posY>0</posY>
<message>Temp: -0.5C</message>
</TextOverlay>';

$URL = 'http://user:passwd@192.168.1.218/Video/inputs/channels/1/overlays/text/1';

		$ch = curl_init($URL);
		curl_setopt($ch, CURLOPT_URL, $URL);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($ch);
		curl_close($ch);
		print_r($output);

?>

 

But no matter how I do it I always get the result as: Invalid Operation

 

What am I doing wrong?

 

//Minglarn...

Share this post


Link to post
Share on other sites

сорри за некропост )

USE IT

<?php
$xml_data = '<?xml version="1.0" encoding="UTF-8"?>
<TextOverlay version="1.0" xmlns="http://www.hikvision.com/ver10/XMLSchema">
<id>1</id>
<enabled>true</enabled>
<posX>16</posX>
<posY>0</posY>
<message>Temp: -0.5C</message>
</TextOverlay>'."\r\n";

 $user = "admin";
 $pass = "12345";



$host = '192.168.1.218';
$path = '/Video/inputs/channels/1/overlays/text/1';

//открываем сокет
$fp = @fsockopen("tcp://".$host, 80, $errno, $errstr, 10);
if (!$fp)
{
   die($errstr.':'.$errno);
}
else
{
       $header  = "PUT $path HTTP/1.1\r\n";
       $header .= "Authorization: Basic ".base64_encode("$user:$pass")."\r\n";
       $header .= "User-Agent: php-script\r\n";
       $header .= "Host: $host\r\n";
       $header .= "Accept: */*\r\n";
       $header .= "Content-Length: ".strlen($xml_data)."\r\n\r\n";

   //посылаем данные
   fwrite($fp, $header.$xml_data);

   $headers='';

   //читаем заголовки
   while ($str = trim(fgets($fp, 4096)))
   $headers .= "$str\n";

   $body='';

   //читаем ответ
   while (!feof($fp))
   $body.= fgets($fp, 4096);

   //закрываем сокет
   fclose($fp);
}

//выводим данные
echo $headers.'<hr/>'.$body;

?>

Share this post


Link to post
Share on other sites

I do it with shell scripts like on an Arduino or Raspberri PI using the curl command with the XML. I had it working to take the temperature using a temp sensor and update the OSD with the temperature.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×