Unable to change DS2-CD2042WD-I settings via API

WxCam

n3wb
Aug 17, 2017
1
0
I am attempting to automate Hikvision camera configuration using the Hikvision IPMD XML API. My camera is a model DS-2CD2042WD-I. I am able to retrieve camera data using any of the documented services, but my attempts to change field values are failing. I copied the XML block from a GET of /System/deviceInfo and deleted all the read-only parameters to make the XML block for PUT. Here's the PHP code I'm using to try changing the System Device Name.

NOTE: I used commas for dots in some places because this post editor makes strange, unwanted replacements.

define('_EOL', "\n");

// Set device name
$url='http://192.168.6.12/System/deviceInfo';
$creds='admin:12345';
$body='<?xml version="1.0" encoding="UTF-8"?>'.
'<DeviceInfo xmlns="http://www,hikvision,com/ver10/XMLSchema" version="1.0">'.
'<deviceName>Cam 7 AAAA</deviceName>'.
'<deviceID>88</deviceID>'.
'</DeviceInfo> ';
$tmpFile='temp.txt';
file_put_contents($tmpFile, $body);
$bytes=filesize($tmpFile);
$stream=fopen($tmpFile, 'r');
echo('Bytes='.$bytes.', handle='.$stream._EOL);

$session=curl_init(); // initialize a curl session
curl_setopt($session,CURLOPT_URL, $url);
curl_setopt($session,CURLOPT_USERPWD, $creds);
curl_setopt($session,CURLOPT_HEADER,TRUE);
curl_setopt($session,CURLOPT_RETURNTRANSFER, TRUE);
//curl_setopt($session,CURLOPT_PUT, TRUE);
curl_setopt($session,CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($session,CURLOPT_CUSTOMREQUEST, 'Content-Type: application/xml; charset="UTF-8"');
curl_setopt($session,CURLOPT_INFILE, $stream); // XML block
curl_setopt($session,CURLOPT_INFILESIZE, $bytes); // size in bytes

$page=curl_exec($session);
$info=curl_getinfo($session);
$err='curl error: '.curl_errno($session).' '.curl_error($session);

curl_close($session);

print_r($info);
echo($err._EOL);
echo($page._EOL);


And here's the curl info on the request. It seems the camera is not responding to the request.

- About to connect() to 192.168.6.12 port 80 (#0)
- Trying 192.168.6.12...
- Adding handle: conn: 0x1b6fe70
- Adding handle: send: 0
- Adding handle: recv: 0
- Curl_addHandleToPipeline: length: 1
- - Conn 0 (0x1b6fe70) send_pipe: 1, recv_pipe: 0
- Connected to 192.168.6.12 (192.168.6.12) port 80 (#0)
- Server auth using Basic with user 'admin'
> Content-Type: application/xml; charset="UTF-8" /System/deviceInfo HTTP/1.1
Authorization: Basic YWRtaW46YmVhdVQzb3g=
Host: 192.168.6.12
Accept: */*
Content-Length: 180
Expect: 100-continue

- Empty reply from server
- Connection #0 to host 192.168.6.12 left intact

Previously I tried using all three EOL types (Mac, linux, DOS) in the XML block before I removed them all, as in the PHP code above. I know the authentication works because I can read anything from the camera. I can also successfully send PUT commands that have no data or XML block requirements, such as a reboot. So I suspect some issue with how I am sending the XML via curl. Also, I can change the device name via web browser while logged in. Then when I read the device information using curl, the changes show up in the XML response. Any ideas where I've gone wrong? Thanks.
 
Last edited: