Created
July 17, 2014 16:37
-
-
Save jclement/4ada8e79af80112838f8 to your computer and use it in GitHub Desktop.
Blink(1) when there are outstanding RTDs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Blink1 = require('node-blink1'); | |
var request = require('request').defaults({strictSSL: false}); | |
var blink = new Blink1(); | |
var _ = require('underscore'); | |
blink.fadeToRGB(2000,255,255,0, function() { | |
blink.fadeToRGB(200,0,0,0, function() { | |
}); | |
}); | |
var baseUrl = 'https://e278-jsc:8082/api'; | |
var username = 'System Admin' | |
var password = '1'; | |
var _api = function(method, data, success, failure) { | |
request.post(baseUrl + method, {body: JSON.stringify(data)}, function(error, response, body) { | |
if (error || response.statusCode !== 200) { | |
if (_.isFunction(failure)) { | |
if (body) { | |
failure(error, JSON.parse(body)); | |
} else { | |
failure(error); | |
} | |
} | |
} else { | |
if (_.isFunction(success)) { | |
success(JSON.parse(body)); | |
} | |
} | |
}); | |
}; | |
var errorFunc = function() { | |
blink.fadeToRGB(200,255,0,0, function() { | |
blink.fadeToRGB(100,0,0,0, function() { | |
}); | |
}); | |
}; | |
var fade = 0; | |
setInterval(function() { | |
_api('/Authentication/Login', {UserName: username, Password: password}, function(data) { | |
var token = data.AuthenticationToken; | |
_api('/Rtd/List/Assigned', {AuthenticationToken: token}, function(data) { | |
if (data.TotalRecords > 0) { | |
if (++fade > 1) { | |
fade = 0; | |
} | |
if (fade == 0) { | |
blink.fadeToRGB(500, 255, 255, 0); | |
} else { | |
blink.fadeToRGB(500, 255, 220, 0); | |
} | |
} else { | |
blink.fadeToRGB(500,0,0,0); | |
} | |
_api('/Authentication/Logout', {AuthenticationToken: token}, function() {}, errorFunc); | |
}, errorFunc); | |
}, errorFunc); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment