Skip to content

Instantly share code, notes, and snippets.

@mjohnsullivan
Last active December 17, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjohnsullivan/5566879 to your computer and use it in GitHub Desktop.
Save mjohnsullivan/5566879 to your computer and use it in GitHub Desktop.
AxisCam motion detection with classic Node streams
/**
* Parses out motion data from the Axis camera motion stream
*/
var util = require('util'),
Stream = require('stream').Stream
var MotionLevelStream = function() {
this.readable = true
this.writable = true
}
util.inherits(MotionLevelStream, Stream)
MotionLevelStream.prototype.write = function(data) {
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.emit('data', { group: Number(motionMatch[1]),
level: Number(motionMatch[2]),
threshold: Number(motionMatch[3]),
ts: new Date })
})
}
MotionLevelStream.prototype.end = function() {
this.emit('end')
}
exports.createStream = function() {
return new MotionLevelStream()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment