NodeJS Module: node-dahua-api

just forked the module and should work now with digest-auth. also added functions for file search and retrieval
streiten/node-dahua-api

tested on IPC-HFW5831E-Z5E with firmware version 2.622.0000000.18.R, Build Date: 2017-11-10
as the camera has no PTZ those functions are not tested
@nayr hasn't been active on the forum in a while, but may respond to a pull request.
 
Would be nice if somebody could make a Home Assistant component from the github code :love:
 
Would be nice if somebody could make a Home Assistant component from the github code :love:
You can use the Amcrest component (dahua makes amcrest). It looks like the developer may have been working off an old version of the HTTP API.
This is the most recent version of the API that's posted publicly that I'm aware of: https://s3.amazonaws.com/amcrest-files/Amcrest+HTTP+API+3.2017.pdf (v2.12)

Consider contacting the developers of the amcrest component with feature requests and giving them a link to the newer documentation.
 
  • Like
Reactions: mat200
I'd like to trigger a "Lens Init". The API (V1.67) doesn't include a suitable CGI command.
Is it possible with node.js?

Best regards, Carver
 
@tangent: Thanks, but there's also no Lens Init available. And to do that with node-dahua-api (if possible), I don't know the command.
 
Things like snapshot (which uses the following url: http://<ip>/cgi-bin/snapshot.cgi?channel=1) now gets a

Error
ErrorID=5, Detail=Server internal error!
I'd go back to the Dahua HTTP API documentation (amcrest version linked above) and test the basic functions in your web browser.

I'm not sure if the nodejs code has been updated to use digest authentication which newer cameras and nvrs are using. You may have to manually make some changes.
 
I'd go back to the Dahua HTTP API documentation (amcrest version linked above) and test the basic functions in your web browser.

I'm not sure if the nodejs code has been updated to use digest authentication which newer cameras and nvrs are using. You may have to manually make some changes.

Yeah did that...a lot of those functions don't work any more. Like snapshot.cgi, getConfig?action=ChannelTitle, the odd one does though.

Looks like in this device, and others? they've changed the api. Using fiddler I think i managed to figure out they've gone to a RPC2 call where json is posted. ie I see now that I can call the RPC2 with a json string containing "method":"configManager.getConfig","params":{"name":"ChannelTitle"} (and a few more and it seems to replicate that function that used to be in the http api call for configManger?action=getConfig&name=ChannelTitle.

So people using this api may start encountering issues on different hardware
 
Yeah did that...a lot of those functions don't work any more. Like snapshot.cgi, getConfig?action=ChannelTitle, the odd one does though.

Looks like in this device, and others? they've changed the api. Using fiddler I think i managed to figure out they've gone to a RPC2 call where json is posted. ie I see now that I can call the RPC2 with a json string containing "method":"configManager.getConfig","params":{"name":"ChannelTitle"} (and a few more and it seems to replicate that function that used to be in the http api call for configManger?action=getConfig&name=ChannelTitle.

So people using this api may start encountering issues on different hardware
What firmware version are you running? Unfortunately Dahua doesn't make the API publicly available anymore and only provides it to people who sign an NDA.
This combined with their disregard for the license terms of open source software are a bit irritating.
 
Did Nayr leave the forum? :(

I'm looking into getting both motion and IVS into MQTT messages for some of my cameras...
I have a service that does it (docker/python service to mqtt - psyciknz/CameraEvents ), which can also send image content for notifications. But the snapshot function is not working for my particular unit.

And the only other issue it might have is getting the channel list for an nvr. But it still sends motion alerts out.
 
I will test that tomorrow, buddy. Nice! We just installed a Dahua A46 as a baby monitor and it replaced a hacked Xiaomi Dafang running Dafang Hacks with the MQTT motion detection alerts... so I need something similar.
 
Did Nayr leave the forum? :(

I'm looking into getting both motion and IVS into MQTT messages for some of my cameras...
He hasn't been active here in quite a while. He had a lot of more important things going on in his life.
 
Last edited:
Hi! Is there some way to get a list of presets by this API?

Yup!

http://<IP>/cgi-bin/ptz.cgi?action=getPresets&channel=0

My Dahua SD49225T-HN returns:

Code:
presets[0].Index=1
presets[0].Name=Whatever
presets[0].Type=0
presets[1].Index=2
presets[1].Name=Whatever Else
presets[1].Type=0
presets[2].Index=3
presets[2].Name=Whatever Else Again
presets[2].Type=0

etc

And I agree with you, very very useful.

Incidentally I found it in the Amcrest API, not the Dahua API, even though I'm using a Dahua camera...

https://s3.amazonaws.com/amcrest-files/Amcrest+HTTP+API+3.2017.pdf
 
Last edited:
  • Like
Reactions: tangent
I have a service that does it (docker/python service to mqtt - psyciknz/CameraEvents ), which can also send image content for notifications. But the snapshot function is not working for my particular unit.

And the only other issue it might have is getting the channel list for an nvr. But it still sends motion alerts out.
Hi cool!
Thx for sharing.

Maybe a stupid question but how do I install it on ..lets say ubuntu?
Gitclone it ..and then? ;-)
 
Anyone know if there is a way to enable / disable p2p via the api?
Also, is there a way to grab the QR code via api?

I am trying to create a web based playback experience similar to what the user gets if they are standing at the dvr.
Do you guys think this api is sufficient for that?