2014-07-23 00:16:15 +00:00
|
|
|
var util = require('util');
|
|
|
|
var EventEmitter = require('events').EventEmitter;
|
2016-01-08 16:47:28 +00:00
|
|
|
var request = require('request');
|
2014-07-23 00:16:15 +00:00
|
|
|
|
|
|
|
var Flukso = function(hostname, pathname) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.pollPower = function() {
|
2016-01-08 16:47:28 +00:00
|
|
|
request({url: "http://" + hostname + pathname}, function(error, res, response) {
|
|
|
|
if (error) {
|
|
|
|
self.emit('failed', error)
|
|
|
|
} else {
|
2022-09-04 12:18:21 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
var jsondata = JSON.parse(response);
|
|
|
|
var power = jsondata[jsondata.length-1][1];
|
|
|
|
|
|
|
|
self.emit('done', parseInt(power));
|
|
|
|
} catch(err) {
|
|
|
|
console.log("error parsing fluxo data");
|
2014-07-23 00:16:15 +00:00
|
|
|
}
|
2022-09-04 12:18:21 +00:00
|
|
|
|
2016-01-08 16:47:28 +00:00
|
|
|
}
|
|
|
|
});
|
2014-07-23 00:16:15 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
util.inherits(Flukso, EventEmitter);
|
|
|
|
module.exports = Flukso;
|