NodeJS Module: node-dahua-api

nayr

IPCT Contributor
Joined
Jul 16, 2014
Messages
9,329
Reaction score
5,325
Location
Denver, CO
Current Status: BETA 1.0, Work In Progress
Software Repository: https://github.com/nayrnet/node-dahua-api
NPM Package: https://www.npmjs.com/package/node-dahua-api

What:
This is a module for NodeJS to interact with your Dahua IPC/PTZ through JavaScript, if you want to script in advanced logic this will get you started.​

Install:
  • Download and Install NodeJS for your Platform: https://nodejs.org
  • Download and install the module: npm install node-dahua-api

Features:
  • Alarm Listener, watch and respond instantly to: Motion/Faults/Inputs
  • Day/Night Switching, switch between Day/Night profiles.
  • PTZ Commands, go to presets, absolute locations, etc.

Need to Implement:
  • Update Sunrise/Sunset times for Geographic location
  • Trigger Recording
  • Trigger Snapshot
  • Suggestions??

This will be the dedicated Support & Discussion thread for this project, contributions are very welcome!

Right now I want to know what functionality you think I should add to this, there is no way I am implementing the entire API.. I started with the functionality I needed the most, but im sure there are other things to be done.

Also need testers to start playing with it, with new cameras and old to make sure it works for all Dahuas.. Ive already found changing day/night profile is dependent on features being avilable.
 
Last edited by a moderator:

nayr

IPCT Contributor
Joined
Jul 16, 2014
Messages
9,329
Reaction score
5,325
Location
Denver, CO
implementing this into Domoticz so I fixed a few bugs and added some more functionality.. notably ptzPreset(int), ptzZoom(float), and finally ptzMove(direction,action,speed)

And here is some output from the example.js provided with the package
Code:
./example.js 
Local Alarm Triggered: 0
Local Alarm Ended: 0
Local Alarm Triggered: 0
Local Alarm Ended: 0
Video Motion Detected
Video Motion Ended
Video Motion Detected
Video Motion Ended
Video Motion Detected
Video Motion Ended
This is really cool, I dont use motion detection for recording.. but I can still set it up to be a Motion Sensor for my Automation System.. use it to turn on/off lights, etc..

my integration with Domoticz can be found here: https://github.com/nayrnet/domoticz-ipcc
 
Last edited by a moderator:

marid2apterbilt

Young grasshopper
Joined
Oct 18, 2015
Messages
95
Reaction score
7
I need to go skim thru your automation thread. Love the idea of using the motion on the cams to trigger other devices/ lights/ etc. Ive put my zwave installation on hold waiting to see what comes of the Lutron 442 patent that recently expired. 442 patent restricted current status updates via internet to INWALL installed switches.
 

nayr

IPCT Contributor
Joined
Jul 16, 2014
Messages
9,329
Reaction score
5,325
Location
Denver, CO
cheers, today I broke ground on this module's twin brother.. node-hikvision-api @ https://github.com/nayrnet/node-hikvision-api thanks to wrightwoodsurveillance giving me remote access to a Hikvision for development purposes.. its far from finished, I just got the same alarm monitoring functionality working (I think) and need to spend more time on the rest of the commands.

I am unifying both API's as both my dahua and hikvision NodeJS modules have the exact same functions and responses despite what module you use.. so mix and match to your hearts content.

i think the functionality your waiting for is instant updates from inwall switches, ie if you hit a switch it tells the controller instantly what the new status is.. thats what Lutron owned, but truthfully its a minor inconvenience.. and easy to work with, yeah none of my light switches directly trigger anything else but I know the status within a few seconds so I can still write logic based off the state.. almost never does anyone flip on a light switch and then trigger something else that will react differently depending on that light before I know the status..

the best use for that feature is chaining switches, so you can have living room switch also control a hallway switch in unison.. but you can get those with master/slaves without lutron's patent, they just cant send the command directly to the ZW controller. and then of course anything but in-wall switches can send instant status updates based upon input without issue...

but yes I agree, should be nice seeing some affordable switches with instant status pushes come in soon.. but dont let that hold you back, there is really only 1 switch in my house that I wish had it.. and that was my living room dimmer, and only so I can over-ride dimmer levels depending on time of day (ie full bright by default at day, and 60% bright by default at night), I could do it now but it'd happen 20s after you hit the button sometimes.
 
Last edited by a moderator:

miffy_bf

n3wb
Joined
May 27, 2016
Messages
4
Reaction score
0
Hi, I am trying to install your Dahua API to a SOC running Debian. However I got an error saying that I missed fficonfig.h, may I know what is the missing package i have to install?

In file included from ../deps/libffi/src/prep_cif.c:27:0:
../deps/libffi/include/ffi_common.h:17:23: fatal error: fficonfig.h: No such file or directory
#include <fficonfig.h>
^
compilation terminated.
 

nayr

IPCT Contributor
Joined
Jul 16, 2014
Messages
9,329
Reaction score
5,325
Location
Denver, CO
where'd you get your NodeJS? whats the whole log, i cant tell what module its bombing on.
 

miffy_bf

n3wb
Joined
May 27, 2016
Messages
4
Reaction score
0
Thank you for your fast reply. I got the node.js at https://nodejs.org/en/download/ using the ARM Binaries (.tar.xz) - ARMv8. Here is the log

debian@pine64pro:~/dahua$ npm install node-dahua-api-
> ref@1.3.2 install /home/debian/dahua/node_modules/node-dahua-api/node_modules/net-keepalive/node_modules/ref
> node-gyp rebuild

make: Entering directory '/home/debian/dahua/node_modules/node-dahua-api/node_modules/net-keepalive/node_modules/ref/build'
CXX(target) Release/obj.target/binding/src/binding.o
SOLINK_MODULE(target) Release/obj.target/binding.node
COPY Release/binding.node
make: Leaving directory '/home/debian/dahua/node_modules/node-dahua-api/node_modules/net-keepalive/node_modules/ref/build'

> ffi@2.0.0 install /home/debian/dahua/node_modules/node-dahua-api/node_modules/net-keepalive/node_modules/ffi
> node-gyp rebuild

make: Entering directory '/home/debian/dahua/node_modules/node-dahua-api/node_modules/net-keepalive/node_modules/ffi/build'
CC(target) Release/obj.target/ffi/deps/libffi/src/prep_cif.o
In file included from ../deps/libffi/src/prep_cif.c:27:0:
../deps/libffi/include/ffi_common.h:17:23: fatal error: fficonfig.h: No such file or directory
#include <fficonfig.h>
^
compilation terminated.
deps/libffi/ffi.target.mk:106: recipe for target 'Release/obj.target/ffi/deps/libffi/src/prep_cif.o' failed
make: *** [Release/obj.target/ffi/deps/libffi/src/prep_cif.o] Error 1
make: Leaving directory '/home/debian/dahua/node_modules/node-dahua-api/node_modules/net-keepalive/node_modules/ffi/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 3.10.101-0-pine64-longsleep
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/debian/dahua/node_modules/node-dahua-api/node_modules/net-keepalive/node_modules/ffi
gyp ERR! node -v v4.4.5
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok
npm ERR! Linux 3.10.101-0-pine64-longsleep
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "node-dahua-api"
npm ERR! node v4.4.5
npm ERR! npm v2.15.5
npm ERR! code ELIFECYCLE

npm ERR! ffi@2.0.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ffi@2.0.0 install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the ffi package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs ffi
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls ffi
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /home/debian/dahua/npm-debug.log
debian@pine64pro:~/dahua$
 

miffy_bf

n3wb
Joined
May 27, 2016
Messages
4
Reaction score
0
I already run sudo apt-get install libffi-dev before. I ran again and it said I am already have the latest version. Is it the file "fficonfig.h" only for x86 platform?
 

nayr

IPCT Contributor
Joined
Jul 16, 2014
Messages
9,329
Reaction score
5,325
Location
Denver, CO
no, ive never installed this on an x86 platform.. and I dont been have libffi-dev installed on my arm boxes that are running this..

I think net-keepalive updated dependencies or something, will have to try an older version or something.
 

miffy_bf

n3wb
Joined
May 27, 2016
Messages
4
Reaction score
0
I try to npm install net-keepalive, it gives the same error. By the way, what do you mean about old version? old-version of node-dahua-api? or old version of libffi?
 

nayr

IPCT Contributor
Joined
Jul 16, 2014
Messages
9,329
Reaction score
5,325
Location
Denver, CO
its probably a newer version of net-keepalive, I have no libffi libraries at all and its working fine.. what version are you installing? I have: "net-keepalive": "^0.3.3"
 

KhurramF

n3wb
Joined
Aug 10, 2016
Messages
3
Reaction score
0
implementing this into Domoticz so I fixed a few bugs and added some more functionality.. notably ptzPreset(int), ptzZoom(float), and finally ptzMove(direction,action,speed)

And here is some output from the example.js provided with the package
Code:
./example.js 
Local Alarm Triggered: 0
Local Alarm Ended: 0
Local Alarm Triggered: 0
Local Alarm Ended: 0
Video Motion Detected
Video Motion Ended
Video Motion Detected
Video Motion Ended
Video Motion Detected
Video Motion Ended
This is really ineresting. I just started using Dahua IP cameras and did not know if motion detection on the camera was possible. I would like to use your plugin in my setup. I am a total noob at NodeJS. Is it possible to share more information on how to use your plugin? If you can post the contents of example.js, I think it will set me on the right path.

Thanks for developing this plugin.
 

randyth

Young grasshopper
Joined
Aug 26, 2015
Messages
77
Reaction score
8
A wonderful plugin indeed.
I wish there was a way to pull a screenshot/picture from the camera though.
 

nayr

IPCT Contributor
Joined
Jul 16, 2014
Messages
9,329
Reaction score
5,325
Location
Denver, CO
http://<IP>/cgi-bin/snapshot.cgi

or

http://<IP>:9989/onvif/media_service/snapshot
 

randyth

Young grasshopper
Joined
Aug 26, 2015
Messages
77
Reaction score
8
http://<IP>/cgi-bin/snapshot.cgi

or

http://<IP>:9989/onvif/media_service/snapshot

Awesome. http://<IP>/cgi-bin/snapshot.cgi works. But do you know how to pull from the second stream (instead of main stream)?
 

nayr

IPCT Contributor
Joined
Jul 16, 2014
Messages
9,329
Reaction score
5,325
Location
Denver, CO
thats not doable, just resize the jpeg if you need it smaller..
 

randyth

Young grasshopper
Joined
Aug 26, 2015
Messages
77
Reaction score
8
thats not doable, just resize the jpeg if you need it smaller..
That's a bummer.
I saw on https://www.ispyconnect.com/man.aspx?n=Dahua several urls with the variable channel or chn or even subtype. But these variables doesn't seem to make a difference with my model (the snapshot is always of the main stream).

I'm pulling snapshots every seconds with a python script and I noticed that some of the snapshots sometimes get garbled up (eg they only contain data in the half upper section. The lower section is blank).
I thought pulling a lower-res screenshot directly from the camera would avoid this, but that route doesn't seem possible. I guess I will have to play with the interval settings (maybe pulling HD screenshots every second is too much).

I have a different question though:
Do you know if it is possible to set or configure the text-overlay setting through scripting (or maybe just enable/disable)?
(it is possible to enable a text overlay with some custom text and position. I would like to show a text that is controlled through a script).
 
Top