raumstatus/flukso.js

30 lines
803 B
JavaScript
Raw Permalink Normal View History

var util = require('util');
var EventEmitter = require('events').EventEmitter;
2016-01-08 16:47:28 +00:00
var request = require('request');
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 {
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");
}
2016-01-08 16:47:28 +00:00
}
});
};
};
util.inherits(Flukso, EventEmitter);
module.exports = Flukso;