motion3.js

/** * Parses out motion data from the Axis camera motion stream * Implemented with the new Node streams */ var stream = require('stream'), util = require('util') var MotionLevelStream = function() { stream.Transform.call(this, {objectMode: true}) this._transform = function(data, encoding, cb) { var that = this // Important bit of the stream is: group=0;level=0;threshold=11; var match = data.toString().match(/group=\d+;level=\d+;threshold=\d+/g) if (match) match.forEach(function(motion) { var motionMatch = motion.match(/group=(\d+);level=(\d+);threshold=(\d+)/) that.push({ group: Number(motionMatch[1]), level: Number(motionMatch[2]), threshold: Number(motionMatch[3]), ts: new Date }) }) cb() } } util.inherits(MotionLevelStream, stream.Transform) exports.createStream = function() { return new MotionLevelStream() }
AxisCam motion detection with new Node streams Transform without prototypes

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.