IPC-HDB4300C HTTP API - Get current alarm state

psycik

Getting the hang of it
Dec 9, 2015
225
41
Wellington, New Zealand
I've been playing with this camera. I have it running in SmartPSS pretty well, including using PC-NVR for recording.

I have the motion detection pretty well going. But I really hate how the email notifications work. I really like being notified. But for one even this thing gives me about 20 emails.

I've tried some gmail foo, but can't seem to suppress everything but the attachment one.

So anyway, it has an api, but has anyone figured out how to get the current alarm state out of
  • the camera directly
  • the pc-nvr
  • smartpss
So that I might write my own notification.
 
setting up my home automation I stumbled across this request and here is the answer for Dahua Cameras

Code:
http://<ip address>/cgi-bin/alarm.cgi?action=getInStates
Get alarm input state for all channels.A bit in the response result indicates a channel alarm states, below result 3 means alarm channel 1 and channel 2 havealarm now.
result=0  (No Alarm)
result=1  (Channel 1 Alarm)
result=2  (Channel 2 Alarm)
result=3  (Channel 1 & 2 Alarm)
 
  • Like
Reactions: SistemasYusa
setting up my home automation I stumbled across this request and here is the answer for Dahua Cameras

Code:
http://<ip address>/cgi-bin/alarm.cgi?action=getInStates
Get alarm input state for all channels.A bit in the response result indicates a channel alarm states, below result 3 means alarm channel 1 and channel 2 havealarm now.
result=0  (No Alarm)
result=1  (Channel 1 Alarm)
result=2  (Channel 2 Alarm)
result=3  (Channel 1 & 2 Alarm)

I actually found there'e a stream you can attach to which is live. As what you posted you'd have to check all the time.
http://ipaddress//cgi-bin/eventManager.cgi?action=attach&codes=[VideoMotion,AlarmLocal,MDResult]
 
suck, I get a 400 bad request response.. on all my Dahuas.. this must be something new.
 
Last edited by a moderator:
suck, I get a 400 bad request response.. on all my Dahuas.. this must be something new.

Ahh, my 4300c (about 2 months old) it doesn't do anything in a browser, but I have an windows service I've written that connects to this stream and when an event is detected it will post out a message - rather than relying on the built in notifcations.
 
suck, I get a 400 bad request response.. on all my Dahuas.. this must be something new.

Hi Nayr,

are you sure you have brackets around the eventCode names?

Make sure you have something like this:
http://192.168.0.113:85/cgi-bin/eventManager.cgi?action=attach&codes=[VideoMotion]
instead of
http://192.168.0.113:85/cgi-bin/eventManager.cgi?action=attach&codes=VideoMotion

I was running through some tests and if the brackets were missing i'd get a 400 response. But with the brackets I'd get a 200 OK response and this was with a camera running firmware back from 2013. I believe this feature was added in the documents back in 2012 as well. So I would think it should work for you as well.
 
@psycik (never mind, i figured it out)

by any chance have you tried using the API to configure any of the settings? I've been spending the last few hours trying to get the commands for configManager.cgi?action=setConfig to work for any of the parameters and every time it just gives me an error. I can successfully set/activate presets on a PTZ, but that's it. Just curious if anyone else know how to get the other commands to work... here's an example:

http://10.1.1.67/cgi-bin/configManager.cgi?action=setConfig&ChannelTitle[0].Name=PTZCamera
(in my script the brackets are encoded)

Edit:
of course shortly after writing this it starts working for me. I have no idea still why it wasn't working but now it does. I can only assume I had a typo somewhere

I do notice that that the easiest way for me to figure out which is correct is first to use the getConfig command to get a response of all the values. then manipulate it in the web GUI to to make sure it's the correct parameter, then use the returned parameters from the get command to set a parameter.
 
Last edited by a moderator:
@yuaa2: Attached is the latest version of the API that I can find.
@surveillanceone (Chase), thanks again for the help on this.. I am going to spend the next few days coding up a module for Domoticz (FOSS Automation Software) so it can support Dahua Cameras natively as motion sensors, alarm inputs, alarm outputs, etc..

I am going to plug you for this, so to everyone else here, since I was having trouble with the API and at my witts end, so went to my trusty distributor we all know and love here,
Wrightwood Surveillance and asked for help, and he figured out my mistake.. Good luck getting support like this from AliBaba.

Cheers,
-R
 

Attachments

Last edited by a moderator:
  • Like
Reactions: surveillanceone
@nayr

Thanks for the praise! You gave me the motivation to look at this deeper and now I'm going to add this to my home automation as well!

I'm going to work on some python code that can receive these events from Dahua and Hikvision cameras to tie into my software as well. Right now I use EventGhost as a bridge to many other systems so it'll probably just run inside that. But maybe it can be turned into a stand alone little program that can execute other commands based on the alarm received.
 
Last edited by a moderator:
Always glad to help motivate!

I've already written a NodeJS module for interfacing with my Home Automation software. (http://www.domoticz.com), https://github.com/nayrnet/node-domoticz-mqtt

so im going to start work on a new module called something like node-dahua-api, then it'll be a piece of cake to tie everything together.

If your into home automation go check out my thread, in the last few pages ive been outlining my camera automation: https://www.ipcamtalk.com/showthread.php/1037-nayr-s-home-automation-build-out
 
Here you guys go, got this damn functionality working after a bunch of trial and error.. started work on my NodeJS module, I have not published it to NPM yet because it only monitors for alarms right now.. I will in a few days once its more complete.

https://github.com/nayrnet/node-dahua-api

the example code i provided will output something like this:
Code:
Code=AlarmLocal,action=Start,index=0
Code=AlarmLocal,action=Stop,index=0
Code=AlarmLocal,action=Start,index=0
Code=AlarmLocal,action=Stop,index=0
Code=VideoMotion,action=Start,index=0
Code=VideoMotion,action=Stop,index=0
Code=VideoMotion,action=Start,index=0
Code=VideoMotion,action=Stop,index=0
Code=VideoMotion,action=Start,index=0
Code=VideoMotion,action=Stop,index=0

I'll stat a new thread here shortly once basic functionality is implemented
 
Last edited by a moderator:
Hello, i wonder if you could give me some basic direction about how to get started?
I am trying to build a sort of "dashboard" to let me know that the Dahua NVRs are online etc etc

I have node installed on my local box.
I have cloned your git hub project. (node-dahua-api)
I have a JetBrains IDE installed.

Should I be able to open your dahua.js file and "run" it?

When I click "run" in the IDE it just gives error messages...

Error: Cannot find module 'request'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)

etc

Any tips?

Thanks
 
run npm install so you get all the dependencies.. the readme contains an example that can be ran directly
 
You know the codes AlarmLocal, VIdeoMotion, MDResult, etc - where did you get them? is there a comprehensive list somewhere, or a way to tell the camera to send all codes?
 
the docs in post #9
 
Thank you for that, that's very useful, but still missing IVS, Face Detection, TripWire, Missing Object, etc, etc that's present in their newer smart cameras :( - can't seem to find a way to extract that information, hmm - I'll ask Dahua.
 
Thank you for that, that's very useful, but still missing IVS, Face Detection, TripWire, Missing Object, etc, etc that's present in their newer smart cameras :( - can't seem to find a way to extract that information, hmm - I'll ask Dahua.
I was looking at a newer API doc (which is from 2014): DAHUA_HTTP_API_FOR_IPC&SD-V1.40
It's in section, 15.1.1 GetVideoAnalyseRule page 105.
 
link?