Accessing Hikvision API to change setting on DS-2CD2342WD-I ??

GMD99

Young grasshopper
Joined
Apr 21, 2015
Messages
62
Reaction score
3
I have several cameras (all model DS-2CD2342WD-I) behind an NVR (DS-7608NI-E2 / 8P).

I am trying to figure out how I can modify some of the settings of the cameras using the API.

As an example, I am trying to figure out how I enable or disable the smart events Line Crossing .

Using a browser I can send the following command to the camera to get the current configuration of this type of smart event...


http://username:password@camera address:port number/ISAPI/Smart/LineDetection/1

(note that the :p is really "colon p")


The result of this is the following:

<LineDetection>
<id>1</id>
<enabled>true</enabled>
"); vertical-align: bottom; height: 10px;"><normalizedScreenSize>
<normalizedScreenWidth>1000</normalizedScreenWidth>
<normalizedScreenHeight>1000</normalizedScreenHeight>
</normalizedScreenSize>
"); vertical-align: bottom; height: 10px;"><LineItemList size="1">
"); vertical-align: bottom; height: 10px;"><LineItem>
<id>1</id>
<enabled>false</enabled>
<sensitivityLevel>60</sensitivityLevel>
<directionSensitivity>any</directionSensitivity>
"); vertical-align: bottom; height: 10px;"><CoordinatesList>
"); vertical-align: bottom; height: 10px;"><Coordinates>
<positionX>645</positionX>
<positionY>109</positionY>
</Coordinates>
"); vertical-align: bottom; height: 10px;"><Coordinates>
<positionX>28</positionX>
<positionY>365</positionY>
</Coordinates>
</CoordinatesList>
</LineItem>
</LineItemList>
<isSupportMultiScene>false</isSupportMultiScene>
<recogRuleType>vectorMode</recogRuleType>
</LineDetection>


However, since I want to automate the process perhaps using Python on my Raspberry pi, I need to be able to access this xml data using the curl command which I think should be as follows:

curl http://username:password@camera address:port number/ISAPI/Smart/LineDetection/1

(note that the :p is really "colon p")


Unfortunately, the response I am getting is not the same! Here is what I get...

<!DOCTYPE html>
<html><head><title>Document Error: Unauthorized</title></head>
<body><h2>Access Error: 401 -- Unauthorized</h2>
<p>Authentication Error</p>
</body>
</html>


I have checked that the username and password are identical yet I am getting "Unauthorized"!

I do not believe that this should have any impact on this but I am accessing the cameras by entering the ip address of the NVR with the port assigned to the camera (Virtual Host). Because this works through the browser, I would expect that I should be able to also access the camera using a PuTTY session on my Raspberry or in a Command session on my Win10 PC... but I cannot!

Any ideas on why this is happening?
 

alastairstevenson

Staff member
Joined
Oct 28, 2014
Messages
15,963
Reaction score
6,794
Location
Scotland
I am accessing the cameras by entering the ip address of the NVR with the port assigned to the camera (Virtual Host).
It might be worth trying this when accessing the cameras directly at their actual IP address as opposed to using the NVR NATed address.

There is a way to gain normal access to cameras connected to NVR POE ports -
3 things needed -
Virtual Host enabled on the NVR.
Cameras must have the NVR PoE interface add the default gateway, or 192.168.254.1 To do this you'll need to have the PoE channel in manual mode to stop the NVR changing the gateway back to an unsuitable value.
And in order to tell your network where to direct the packets for the cameras, you will need to add a static route in your router/gateway, something like -
For network 192.168.254.0/24 (ie subnet mask 255.255.255.0) use <NVR_IP_address> as gateway.
 

GMD99

Young grasshopper
Joined
Apr 21, 2015
Messages
62
Reaction score
3
Thanks for the reply...

I believe that I have most of your points already setup:

- Virtual Host was already enabled on the NVR

- Accessing the NVR with iVMS-4200 (Device Management --> Remote Configuration --> Camera --> Modify) it shows the camera parameters which shows 'Manual' . The camera also already has the IPv4 Default Gateway set up as 192.168.254.1

- My router also already has a routing table entry as Destination LAN IP as 192.168.254.0; Subnet mask as 255.255.255.0; and Gateway as the NVR's IP address on my network.

So given that I seem to have the things that you said are required I tried to access the camera from a PuTTY session on my Raspberry with

curl http://username:camera password@192.168.254.2/ISAPI/Smart/LineDetection/1

Note that I tried it without a port number and then I tried it using the http port of the camera (80)... in both cases the response was the same as I originally posted "Unauthorized".

I also tried it with the port number of the server port of the camera (8000); the http port of the NVR (xx) and the server port of the NVR (xxxx) . (The http and server ports on the camera and the NVR are different). In all these cases the response was "Failed to connect".

Using a browser I get the proper response when I enter either of the following:

http://username:camera password@192.168.254.2/ISAPI/Smart/LineDetection/1

or

http://username;camera password@NVR_address:NATed Port number/ISAPI/Smart/LineDetection/1




So, unfortunately, this did not seems to resolve my issue! Any other thoughts?
 

alastairstevenson

Staff member
Joined
Oct 28, 2014
Messages
15,963
Reaction score
6,794
Location
Scotland
So, unfortunately, this did not seems to resolve my issue!
Was worth a try.

I have a recollection that some of the newer firmware has options for authentication type, basic or digest.
It may be worth checking the camera web GUI for any options the firmware may have.

Here is a slightly changed command line to try, explicitly for both types, for a camera that requires digest :
Code:
alastair@PC-I5 ~ $ curl --basic -u admin:yourpassword http://192.168.1.102/ISAPI/Smart/LineDetection/1
<!DOCTYPE html>
<html><head><title>Document Error: Unauthorized</title></head>
<body><h2>Access Error: 401 -- Unauthorized</h2>
<p>Authentication Error</p>
</body>
</html>
alastair@PC-I5 ~ $ curl --digest -u admin:yourpassword http://192.168.1.102/ISAPI/Smart/LineDetection/1
<?xml version="1.0" encoding="UTF-8"?>
<LineDetection>
<id>1</id>
<enabled>true</enabled>
<normalizedScreenSize>
<normalizedScreenWidth>1000</normalizedScreenWidth>
<normalizedScreenHeight>1000</normalizedScreenHeight>
</normalizedScreenSize>
<LineItemList size="1" >
<LineItem>
<id>1</id>
<enabled>false</enabled>
<sensitivityLevel>50</sensitivityLevel>
<directionSensitivity>any</directionSensitivity>
<CoordinatesList>
<Coordinates>
<positionX>83</positionX>
<positionY>687</positionY>
</Coordinates>
<Coordinates>
<positionX>989</positionX>
<positionY>24</positionY>
</Coordinates>
</CoordinatesList>
</LineItem>
</LineItemList>
<isSupportMultiScene>false</isSupportMultiScene>
<recogRuleType>vectorMode</recogRuleType>
</LineDetection>
alastair@PC-I5 ~ $
 
Top