c# listening for Hikvision events

Joined
Aug 17, 2018
Messages
6
Reaction score
1
Location
Belgium
Hi

We're trying to make a program in c# to capture a JPEG and process it when there is motion detected. But the problem is that we have to listen for the motion event notification but we have no idea how.
We've succeeded to show a live stream and capture a JPEG on button press.
We know there are some functions in the hikvision sdk for this but we have no idea how to use this and how to configure this on the camera.
Does anyone have experience with this? Maybe have an example? Some tips?

anyway thanks in advance
 

alastairstevenson

Staff member
Joined
Oct 28, 2014
Messages
15,930
Reaction score
6,778
Location
Scotland
Maybe use ONVIF event subscriptions?
There are quite a few open-source implementations of an ONVIF client that may show how to do it.
Try a Google search for "onvif open source library".
 
Joined
Aug 17, 2018
Messages
6
Reaction score
1
Location
Belgium
thanks for the information, we will keep this in mind, but we actually already started with the hikvision SDK and, if possible, like to continue with this.
 
Joined
Aug 17, 2018
Messages
6
Reaction score
1
Location
Belgium
we've found this where there is a project for alarm_arm_listen but it's not working for us. we get notification emails for motion detection, but no alert on this example.
do we have to configure a specific setting on the camera?
 

alastairstevenson

Staff member
Joined
Oct 28, 2014
Messages
15,930
Reaction score
6,778
Location
Scotland
Is this HTTP method from the Hikvision IPMD of any use :
8.11.12 Notification alertStream
/Event/notification/alertStream
GET
General Resource v1.0
Viewer
Description It is used to get the event notification data stream through HTTP
server push.
Query None
©2009 – 2014 by HIKVISION. All rights reserved.
98Inbound Data None
Success Return Stream of <EventNotificationAlert>
Notes:
This function is used to get an event notification alert stream from the media device via
HTTP or HTTPS. This function does not require that a client/VMS system be added as an
HTTP(S) destination on the media device. Instead, the client/VMS system can call this
API to initialize a stream of event information from the device. In other words, a
connection is established with the device when this function is called, and stays open to
constantly receive event notifications.
This API uses HTTP server-push with the MIME type multipart/mixed defined in RFC
2046.
<protocol> is the protocol name, i.e. “HTTP” or “HTTPS”.
<channelID> is present for video and analytics events.
<activePostCount> is the sequence number of current notification for this particular event.
It starts at 1. Useful for recurring notifications of an event. Each event maintains a
separate post count.
EventNotificationAlert XML Block
<EventNotificationAlert version=“1.0”
xmlns=“http://www.hikvision.com/ver10/XMLSchema”>
<ipAddress>
<!-- dep, xs:string -->
</ipAddress>
<portNo>
<!-- opt, xs:integer -->
</portNo>
<protocol>
<!-- opt, xs:string -->
</protocol>
<macAddress>
<!-- opt, xs:string;MAC --> </macAddress>
<channelID>
<!-- dep, xs:string -->
</channelID>
<dateTime>
<!-- req, xs:datetime --> </dateTime>
<activePostCount> <!-- req, xs:integer -->
</activePostCount>
<eventType> <!-- req, xs:string, “IO,VMD,videoloss, shelteralarm” --> </eventType>
<eventState>
<!-- req, xs:string, “active,inactive” --> </eventState>
<eventDescription> <!-- req, xs:string -->
</eventDescription>
<inputIOPortID> <!-- dep, xs:integer, if <eventType> is “IO” -->
</inputIOPortID>
<DetectionRegionList>
<!-- dep, if <eventType> is “VMD” -->
<DetectionRegionEntry>
<!-- req -->
<regionID>
<!-- req, xs:string -->
</regionID>
<sensitivityLevel>
<!-- req, xs:integer, 0..100 --> </sensitivityLevel>
</DetectionRegionEntry>
</DetectionRegionList>
</EventNotificationAlert>
Example
The following is an example of an HTTP event stream that pushes a VMD event from
video channel 1.
©2009 – 2014 by HIKVISION. All rights reserved.
99GET /Event/notification/alertStream HTTP/1.1
...
HTTP/1.1 200 OK
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=“<boundary>”
--<boundary>
Content-Type: application/xml; charset=“UTF-8”
Content-Length: xxx
<?xml version=“1.0” encoding=“UTF-8”?>
<EventNotificationAlert version=“1.0”
xmlns=“http://www.hikvision.com/ver10/XMLSchema”>
<ipAddress>172.6.64.7</ipAddress>
<portNo>80</portNo>
<protocol>HTTP</protocol>
<macAddress>01:17:24:45:D9:F4</macAddress>
<channelID>1</channelID>
<dateTime>2009-11-14T15:27Z</dateTime>
<activePostCount>1</activePostCount>
<eventType>VMD</eventType>
<eventState>active</eventState>
<eventDescription>Motion alarm</eventDescription>
<DetectionRegionList>
<DetectionRegionEntry>
<regionID>2</regionID>
<sensitivityLevel>4</sensitivityLevel>
</DetectionRegionEntry>
</DetectionRegionList>
</EventNotificationAlert>
--<boundary>
...
 

Tolting Colt Acres

Pulling my weight
Joined
Jun 7, 2016
Messages
379
Reaction score
153
http://my.camera.ip.address/ISAPI/Event/notification/alertStream

yields a stream of data like this:


--boundary
Content-Type: application/xml; charset="UTF-8"
Content-Length: 550

<EventNotificationAlert version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<ipAddress>192.168.100.231</ipAddress>
<portNo>80</portNo>
<protocol>HTTP</protocol>
<macAddress>xx:xx:Xx:xx:Xx:xx</macAddress>
<channelID>1</channelID>
<dateTime>2018-08-21T11:44:09-5:00</dateTime>
<activePostCount>1</activePostCount>
<eventType>VMD</eventType>
<eventState>active</eventState>
<eventDescription>Motion alarm</eventDescription>
<DetectionRegionList>
</DetectionRegionList>
<channelName>SWN</channelName>
</EventNotificationAlert>
 

DannyDS

n3wb
Joined
Sep 25, 2017
Messages
7
Reaction score
0
Tolting Colt Acres in the example you mention update all the hikvision sdk.dll's with the latest ones from hikvisions website, that should get it recieving alarm data
 

Jeremy Spiering

Young grasshopper
Joined
Feb 14, 2018
Messages
24
Reaction score
20
Nayrnet has written some pretty sweet code for NodeJS. It is really simple to use. I know it isn't C#, but you might consider using it as the listener for the events, and have it trigger your C# application when it detects events. Maybe via HTTP requests or websocket or something like that.

nayrnet/node-hikvision-api
 

Ron C

Young grasshopper
Joined
Jun 20, 2019
Messages
49
Reaction score
3
Location
Los Alamos, NM, USA
Hi

We're trying to make a program in c# to capture a JPEG and process it when there is motion detected. But the problem is that we have to listen for the motion event notification but we have no idea how.
We've succeeded to show a live stream and capture a JPEG on button press.
We know there are some functions in the hikvision sdk for this but we have no idea how to use this and how to configure this on the camera.
Does anyone have experience with this? Maybe have an example? Some tips?

anyway thanks in advance

Hello,

I was wondering, did you ever find out how to listen for these hikvision events?

thanks,

Ron
 

DannyDS

n3wb
Joined
Sep 25, 2017
Messages
7
Reaction score
0
Thanks for the quick reply. Which SDK is it though? There are so many different SDK's? I want to subscribe to the NVR events.
Hikvision network SDK, I'm guessing you will be using windows they have a 32 and 64 bit version, the demo has options for subscribing to alarms this is where it stays logged in to the unit 24/7 or you can input an IP address and port into the NVR or camera and the unit can send the alarms to your receiver
 

rizaan

n3wb
Joined
Jul 4, 2020
Messages
6
Reaction score
0
Location
South Africa
A
Hikvision network SDK, I'm guessing you will be using windows they have a 32 and 64 bit version, the demo has options for subscribing to alarms this is where it stays logged in to the unit 24/7 or you can input an IP address and port into the NVR or camera and the unit can send the alarms to your receiver
Amazing. I will give it a go. Thanks bud.
 

rizaan

n3wb
Joined
Jul 4, 2020
Messages
6
Reaction score
0
Location
South Africa
I'
Hikvision network SDK, I'm guessing you will be using windows they have a 32 and 64 bit version, the demo has options for subscribing to alarms this is where it stays logged in to the unit 24/7 or you can input an IP address and port into the NVR or camera and the unit can send the alarms to your receiver
I'm actually trying to update a binary flag on my Home Automation Server (Home Assistant). The current integration doesnt seem to work with motion detection. If I can capture the events, I am going to update the flag in Home Assistant manually though the API.
 

DannyDS

n3wb
Joined
Sep 25, 2017
Messages
7
Reaction score
0
I'

I'm actually trying to update a binary flag on my Home Automation Server (Home Assistant). The current integration doesnt seem to work with motion detection. If I can capture the events, I am going to update the flag in Home Assistant manually though the API.
If you need any help I've also got a fake SMTP server you can run that receives email alarms from the hik and parses it in to the data you would need
 

rizaan

n3wb
Joined
Jul 4, 2020
Messages
6
Reaction score
0
Location
South Africa
ha
If you need any help I've also got a fake SMTP server you can run that receives email alarms from the hik and parses it in to the data you would need
hahaha that sounds like a brilliant work around. Let me first give the SDK a try then try the fake SMTP server. Thanks for the assistance.
 

rizaan

n3wb
Joined
Jul 4, 2020
Messages
6
Reaction score
0
Location
South Africa
@DannyDS and @SamM I have successfully created the windows service that listens to all the events on the HikVision NVR using the SDK. It then publishes all the events and alarms to an MQTT receiver. In my case, this is Node-Red in Home Assistant.

Code available on rizaanlakay/HikVisionEvents if anyone wants the windows service.
 

SamM

Pulling my weight
Joined
Mar 29, 2020
Messages
245
Reaction score
109
Location
SA
Thats great. Will check it out a bit later
 
Top