Skip to content

Instantly share code, notes, and snippets.

@willmendesneto
Last active November 1, 2015 05:35
Show Gist options
  • Save willmendesneto/b5f92a932ec3b7ffadd0 to your computer and use it in GitHub Desktop.
Save willmendesneto/b5f92a932ec3b7ffadd0 to your computer and use it in GitHub Desktop.
Build checker: Application using Arduino + Johnny Five + NodeJS for to monitor build/deploy status in your Continuos Integration server
var request = require('request');
var five = require('johnny-five');
var board = new five.Board();
var CONFIG = {
LED: {
SUCCESS: 12,
ERROR: 10
},
CI_CCTRACKER_URL: 'https://snap-ci.com/willmendesneto/generator-reactor/branch/master/cctray.xml',
INTERVAL: 500
};
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
board.on('ready', function() {
var ledSuccess = new five.Led(CONFIG.LED.SUCCESS);
var ledError = new five.Led(CONFIG.LED.ERROR);
debounce(function(){
request(CONFIG.CI_CCTRACKER_URL, function(error, response, body) {
if (error) {
console.log('Somethink is wrong with your CI =(');
return;
}
if(body.indexOf('Success') !== -1) {
console.log('Your CI is ok!');
ledSuccess.on();
ledError.off();
} else {
console.log('Somethink is wrong with your CI =(. Fix it!!!!');
ledSuccess.off();
ledError.on();
}
});
}, CONFIG.INTERVAL);
});
{
"name": "arduino-build-checker",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "./node_modules/.bin/nodemon index.js -e js,jade",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"johnny-five": "^0.8.98",
"nodemon": "^1.7.1",
"request": "^2.64.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment