Skip to content

Instantly share code, notes, and snippets.

@boombatower
Last active October 27, 2016 15:21
Show Gist options
  • Save boombatower/b98c854669fee122111bd49e79633af2 to your computer and use it in GitHub Desktop.
Save boombatower/b98c854669fee122111bd49e79633af2 to your computer and use it in GitHub Desktop.
Play a notification sound whenever an Android IP Webcam motion sensor exceeds the threshold.
// Execute in developer console on /sensors.html.
var limit = document.getElementById('motion_limit').value;
var audio = new Audio('http://gabenewell.org/audio/gabenewellwatchingyou.mp3');
(function() {
var origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
this.addEventListener('load', function() {
var response = JSON.parse(this.responseText);
for (var i = 0; i < response['motion']['data'].length; i++) {
if (response['motion']['data'][i][1][0] >= limit) {
console.log('motion over threshold');
audio.play();
}
}
});
origOpen.apply(this, arguments);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment