-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
55 lines (50 loc) · 1.68 KB
/
Copy pathapp.js
File metadata and controls
55 lines (50 loc) · 1.68 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const Knx = require('knx');
const YAML = require("js-yaml");
const Fs = require("fs");
const Influx = require('influx');
var config = YAML.load(Fs.readFileSync("config.yml"));
var datapoints = config.datapoints
var sources = config.sources
const influx = new Influx.InfluxDB({
host: config.influxdb.host,
database: config.influxdb.database,
username: config.influxdb.username,
password: config.influxdb.password,
})
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 catched: GA: %j (%j, %j), value: %j",
new Date().toISOString(),
group_addr, datapoint.type, datapoint.description, newvalue);
influx.writePoints([
{
measurement: datapoint.measurement,
tags: { group_addr: group_addr, short_name: short_name },
fields: { value: 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])
}
},
event: function (evt, src, dest, value) {
console.log("%s **** EVENT %j: src: %j, dest: %j, value: %j",
new Date().toISOString(),
evt, src, dest, value);
}
}
});