-
Notifications
You must be signed in to change notification settings - Fork 2
/
dp-testing.js
34 lines (31 loc) · 1.08 KB
/
dp-testing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const Knx = require('knx');
const YAML = require("js-yaml");
const Fs = require("fs");
var config = YAML.load(Fs.readFileSync("config.yml"));
var datapoints = config.datapoints
var sources = config.sources
function handler(group_addr, datapoint) {
dp = new Knx.Datapoint({ga: group_addr, dpt: datapoint.type}, connection);
dp.on('change', function(oldvalue, newvalue) {
if (datapoint.name) {
var short_name = datapoint.name
} else {
// remove common special chars to create a more machine readable tag
var short_name = datapoint.description.replace(/([(,)])/g, '').replace(/([ ])/g, '_').replace(/[^\x00-\x7F]/g, '');
}
console.log("%s **** METRIC: GA: %j (%j, %j), value: %j",
new Date().toISOString(),
group_addr, datapoint.type, datapoint.description, newvalue);
});
}
var dp = new Object;
var connection = Knx.Connection({
ipAddr: config.knx.gateway_ip, ipPort: config.knx.gateway_port,
handlers: {
connected: function() {
for(var group_addr in datapoints) {
handler(group_addr, datapoints[group_addr])
}
},
}
});