From 0e913ea3ef18f1093a5f10222f9a34761795d4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Sun, 4 Sep 2022 14:18:21 +0200 Subject: [PATCH] changed fluxo parsing from regex to simple json usage --- flukso.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/flukso.js b/flukso.js index 2434055..81b9b24 100644 --- a/flukso.js +++ b/flukso.js @@ -4,19 +4,22 @@ var request = require('request'); var Flukso = function(hostname, pathname) { var self = this; - var regexp = /([0-9]+)\]\]$/; // /\(([0-9]+) hosts* up\)/; this.pollPower = function() { request({url: "http://" + hostname + pathname}, function(error, res, response) { if (error) { self.emit('failed', error) } else { - var matches = regexp.exec(response); - if(matches != null && matches.length == 2) { - var time = Date.now(); - var num = matches[1]; - self.emit('done', parseInt(num)); + + 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"); } + } }); };