Added telegram parsing

This commit is contained in:
2017-03-29 11:40:40 +02:00
parent 28949ae32f
commit 9fb5eec212
2 changed files with 91 additions and 2 deletions
+86 -2
View File
@@ -16,8 +16,11 @@ router.post('/telegram', function(req, res){
});
res.status(200);
res.send("{\"success\":\"true\"}");
parseTelegram(req.body.datagram, function(){
res.status(200);
res.send("{\"success\":\"true\"}");
})
});
/* GET api listing. */
@@ -28,5 +31,86 @@ router.get('/', function(req, res) {
var parseTelegram = function(data, callback){
var toe1 = 0; //Totaal opgenomen energie (tarief 1)
var toe2 = 0; //Totaal opgenomen energie (tarief 2)
var tte1 = 0; //Totaal teruggeleverde energie (tarief 1)
var tte2 = 0; //Totaal teruggeleverde energie (tarief 2)
var ht = 0; //Huidig tarief
var hov = 0; //Huidig opgenomen vermogen
var htv = 0; //Huidig teruggeleverd vermogen
var regx = /./g;
var found = "";
//TOE1
regx = /1-0:1\.8\.1\((\d{6}\.\d{3})\*kWh\)/g;
found = str.match(regx);
if(found.length > 0)
toe1 = found[0];
//TOE2
regx = /1-0:1\.8\.2\((\d{6}\.\d{3})\*kWh\)/g;
found = str.match(regx);
if(found.length > 0)
toe2 = found[0];
//TTE1
regx = /1-0:2\.8\.1\((\d{6}\.\d{3})\*kWh\)/g;
found = str.match(regx);
if(found.length > 0)
tte1 = found[0];
//TTE2
regx = /1-0:2\.8\.2\((\d{6}\.\d{3})\*kWh\)/g;
found = str.match(regx);
if(found.length > 0)
tte2 = found[0];
//HT
regx = /0-0:96\.14\.0\((\d{4})\)/g;
found = str.match(regx);
if(found.length > 0)
ht = found[0];
//HOV
regx = /1-0:1\.7\.0\((\d{2}\.\d{3})\*kW\)/g;
found = str.match(regx);
if(found.length > 0)
hov = found[0];
//HTV
regx = /1-0:2\.7\.0\((\d{2}\.\d{3})\*kW\)/g;
found = str.match(regx);
if(found.length > 0)
htv = found[0];
connection.query(
'INSERT INTO measurement (TOE1, TOE2, TTE1, TTE2, HT, HOV, HTV, time) VALUES (?, ?, ?, ?, ?, ?, ?, NOW())', [toe1, toe2, tte1, tte2, ht, hov, htv],
function (error, results, fields) {
if (error) throw error;
callback();
});
}
module.exports = router;
+5
View File
@@ -20,6 +20,11 @@ router.post('/device', function(req, res){
res.send("{\"success\":\"true\"}");
});
router.get('/device', function(req, res){
connection.query(