GithubHelp home page GithubHelp logo

alex-tmnet / node-dahua-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pawliukaz/node-dahua-api

0.0 0.0 0.0 34 KB

NodeJS Module for Dahua IPC HTTP API

License: GNU General Public License v3.0

JavaScript 100.00%

node-dahua-api's Introduction

node-dahua-api

GPL-3.0 npm node

NodeJS Module for communication with Dahua IP Cameras..

Status: Work in Progress

Example:

#!/usr/bin/nodejs
var     ipcamera	= require('node-dahua-api');

// Options:
var options = {
	host	: '192.168.1.100',
	port 	: '80',
	user 	: 'admin',
	pass 	: 'password123',
	log 	: false
};

var dahua 	= new ipcamera.dahua(options);

// Switch to Day Profile
dahua.nightProfile()

// PTZ Go to preset 10
dahua.ptzPreset(10)

// Monitor Camera Alarms
dahua.on('alarm', function(code,action,index) {
	if (code === 'VideoMotion' && action === 'Start')	console.log('Video Motion Detected')
	if (code === 'VideoMotion' && action === 'Stop')	console.log('Video Motion Ended')
	if (code === 'AlarmLocal' && action === 'Start')	console.log('Local Alarm Triggered: ' + index)
	if (code === 'AlarmLocal' && action === 'Stop')		console.log('Local Alarm Ended: ' + index)
	if (code === 'VideoLoss' && action === 'Start')		console.log('Video Lost!')
	if (code === 'VideoLoss' && action === 'Stop')		console.log('Video Found!')
	if (code === 'VideoBlind' && action === 'Start')	console.log('Video Blind!')
	if (code === 'VideoBlind' && action === 'Stop')		console.log('Video Unblind!')
});

// Find Files
var query = {
  'channel': '0',
  'startTime': '2018-5-9 09:00:00',
  'endTime': '2018-5-9 12:00:00',
  'types': ['jpg','dav'], // [ “dav”, “jpg”, “mp4” ]
  'count': 10 // max. 100
};

dahua.findFiles(query);
dahua.on('filesFound',function(data){
  console.log('filesFound:', data);
});

// Save File
var fileMeta = { 
       Channel: '0',
       EndTime: '2018-05-19 10:45:00',
       FilePath: '/mnt/sd/2018-05-19/001/dav/10/10.36.45-10.45.00[R][0@0][0].dav',
       StartTime: '2018-05-19 10:36:45',
       Type: 'dav'
};

dahua.saveFile(fileMeta);
dahua.on('saveFile',function( msg ){
  console.log('File saved!');
});

// Get a snapshot
dahua.getSnapshot();
dahua.on('getSnapshot',function( msg ){
  console.log(msg);
});

Functions:

// Switch Camera to Night Profile
dahua.dayProfile()

// Switch Camera to Night Profile
dahua.nightProfile()

// Issue Dahua RAW PTZ Command (See API Manual in GitHub Wiki)
dahua.ptzCommand(cmd,arg1,arg2,arg3,arg4)

// Go To Preset
dahua.ptzPreset(int)

// PTZ Zoom, input level: positive = zoom in / negative = zoom out
dahua.ptzZoom(float)

// PTZ Move
// Directions = Up/Down/Left/Right/LeftUp/RightUp/LeftDown/RightDown
// Actions = start/stop
// Speed = 1-8
dahua.ptzMove(direction,action,speed)

// Request current PTZ Status
dahua.ptzStatus()

// Find files
var query = {
  'channel': '0',
  'startTime': '2018-5-9 09:00:00',
  'endTime': '2018-5-9 12:00:00',
  'types': ['jpg','dav'], // [ “dav”, “jpg”, “mp4” ] - optional
  'count': 10 // max. 100 - optional
};
dahua.findFiles(query)

// Callback for file search results
dahua.on('filesFound',function(data){
  console.log('filesFound:', data);
});

// Save file
// requires a the following options for filename creation
// attributes equal findFile results object structure
var fileMeta = { 
       Channel: '0',
       EndTime: '2018-05-19 10:45:00',
       FilePath: '/mnt/sd/2018-05-19/001/dav/10/10.36.45-10.45.00[R][0@0][0].dav',
       StartTime: '2018-05-19 10:36:45',
       Type: 'dav'
};
dahua.saveFile(fileMeta);

// Callback for file saved
dahua.on('saveFile',function( msg ){
  console.log('File saved!');
});

// Get a snapshot
var options = {
  'path': 'snaps', // optinal, where to save the file
  'channel':'', // optional, defaults to 0,
  'filename' : '', // optional, defaults to [HOST]_ch[channel]_[TIMESTAMP]
};
  
dahua.getSnapshot();
dahua.on('getSnapshot',function( msg ){
  console.log(msg);
});

// Callback for any Alarm (Motion Detection/Video Loss & Blank/Alarm Inputs)
dahua.on('alarm', function(code,action,index){  });

// Callback for PTZ Status
dahua.on('ptzStatus', function(data){  });

// Callback on connect
dahua.on('connect', function(){  });

// Callback on error
dahua.on('error', function(error){  });

Options

  • host - hostname of your Dahua camera
  • port - port for your Dahua camera (80 by default)
  • user - username for camera
  • pass - password for camera
  • log - boolean to show detailed logs, defaults to false.
  • cameraAlarms - boolean to listen to camera alarms, defaults to true

More Info:

About:

By: Ryan Hunt

node-dahua-api's People

Contributors

nayrnet avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.