remotezygote / node-onvif-events

An implementation of Node.js that detects the events of your camera that works with the onvif protocol

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node-onvif-events

A node.JS module that attempts to bridge the gap between your ONVIF camera's motion detection and Motion.

Forked from zmonvif-events and converted for node.JS.

NPM

npm npm

If you like this project you can support me.
Buy Me A Coffee

Installation

    $ npm install --save node-onvif-events

Event Monitor

    const MotionDetection = require('node-onvif-events');

    var configMotion = new MotionDetection({
        url: 'http://192.168.0.230/onvif/device_service/ ', // Onvif Service URL
        id: 1,// Any id
        hostname: '192.168.0.230', // IP from your Device
        username: 'admin', // User
        password: 'pass0rd', // Password
        port: 80 // Onvif Service Port
    });
    
    // Starts Monitoring
    configMotion.start();

Action when Detecting Motion

    const MotionDetection = require('node-onvif-events');

    var lastState = null;

    var configMotion = new MotionDetection({
        url: 'http://192.168.0.230/onvif/device_service/ ', // Onvif Service URL
        id: 1,// Any id
        hostname: '192.168.0.230', // IP from your Device
        username: 'admin', // User
        password: 'pass0rd', // Password
        port: 80 // Onvif Service Port
    });

    function motion() {
        console.log("Motion Detected!!");
    }
    
    function motionStop() {
        console.log("Motion Stopped!!");
    }
    
    function checkState(){
        setInterval(function () {
          var motionState = configMotion.getMotionState();
          if(motionState === true && motionState !== lastState){
            motion()
          }
          else if (motionState === false && motionState !== lastState){
	    motionStop();
	}
	lastState = configMotion.getMotionState();
        }, 1000)
      }

      configMotion.start();
      checkState();

About

An implementation of Node.js that detects the events of your camera that works with the onvif protocol


Languages

Language:JavaScript 100.0%