From b2d8760d4e4ae36b4a345c9942b0b6e26dd57214 Mon Sep 17 00:00:00 2001 From: kennyboy55 Date: Wed, 29 Mar 2017 13:33:29 +0200 Subject: [PATCH] Compatible for multiple smart meters --- mean-app/server/routes/thingapi.js | 32 +++++++++++++----------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/mean-app/server/routes/thingapi.js b/mean-app/server/routes/thingapi.js index 1184b75..7ca404d 100644 --- a/mean-app/server/routes/thingapi.js +++ b/mean-app/server/routes/thingapi.js @@ -30,62 +30,58 @@ var parseTelegram = function(data, callback){ //} //TOE1 - regx = /1-0:1\.8\.1\((\d{5}\.\d{3})\*kWh\)/g + regx = /1-0:1\.8\.1\((\d{5,6}\.\d{3})\*kWh\)/g found = str.match(regx); - console.log("\n\nPARSING\n"); - console.log(str); - console.log(found); - - if(found.length > 0) + if(found) toe1 = found[0]; //TOE2 - regx = /1-0:1\.8\.2\((\d{5}\.\d{3})\*kWh\)/g; + regx = /1-0:1\.8\.2\((\d{5,6}\.\d{3})\*kWh\)/g; found = str.match(regx); - if(found.length > 0) + if(found) toe2 = found[0]; //TTE1 - regx = /1-0:2\.8\.1\((\d{5}\.\d{3})\*kWh\)/g; + regx = /1-0:2\.8\.1\((\d{5,6}\.\d{3})\*kWh\)/g; found = str.match(regx); - if(found.length > 0) + if(found) tte1 = found[0]; //TTE2 - regx = /1-0:2\.8\.2\((\d{5}\.\d{3})\*kWh\)/g; + regx = /1-0:2\.8\.2\((\d{5,6}\.\d{3})\*kWh\)/g; found = str.match(regx); - if(found.length > 0) + if(found) tte2 = found[0]; //HT - regx = /0-0:96\.14\.0\((\d{4})\)/g; + regx = /0-0:96\.14\.0\((\d{2,4})\)/g; found = str.match(regx); - if(found.length > 0) + if(found) ht = found[0]; //HOV - regx = /1-0:1\.7\.0\((\d{2}\.\d{2})\*kW\)/g; + regx = /1-0:1\.7\.0\((\d{2,4}\.\d{2,3})\*kW\)/g; found = str.match(regx); - if(found.length > 0) + if(found) hov = found[0]; //HTV - regx = /1-0:2\.7\.0\((\d{2}\.\d{2})\*kW\)/g; + regx = /1-0:2\.7\.0\((\d{2,4}\.\d{2,3})\*kW\)/g; found = str.match(regx); - if(found.length > 0) + if(found) htv = found[0];