changed fluxo parsing from regex to simple json usage
This commit is contained in:
parent
d17c24bde7
commit
0e913ea3ef
15
flukso.js
15
flukso.js
|
@ -4,19 +4,22 @@ var request = require('request');
|
||||||
|
|
||||||
var Flukso = function(hostname, pathname) {
|
var Flukso = function(hostname, pathname) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var regexp = /([0-9]+)\]\]$/; // /\(([0-9]+) hosts* up\)/;
|
|
||||||
|
|
||||||
this.pollPower = function() {
|
this.pollPower = function() {
|
||||||
request({url: "http://" + hostname + pathname}, function(error, res, response) {
|
request({url: "http://" + hostname + pathname}, function(error, res, response) {
|
||||||
if (error) {
|
if (error) {
|
||||||
self.emit('failed', error)
|
self.emit('failed', error)
|
||||||
} else {
|
} else {
|
||||||
var matches = regexp.exec(response);
|
|
||||||
if(matches != null && matches.length == 2) {
|
try {
|
||||||
var time = Date.now();
|
var jsondata = JSON.parse(response);
|
||||||
var num = matches[1];
|
var power = jsondata[jsondata.length-1][1];
|
||||||
self.emit('done', parseInt(num));
|
|
||||||
|
self.emit('done', parseInt(power));
|
||||||
|
} catch(err) {
|
||||||
|
console.log("error parsing fluxo data");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue