node-red-contrib-knx
Advanced tools
Comparing version 0.2.1 to 0.3.1
121
knx.js
@@ -126,2 +126,16 @@ /** | ||
node.status({fill: "yellow", shape: "dot", text: "inactive"}); | ||
function nodeStatusConnected() { | ||
node.status({fill: "green", shape: "dot", text: "connected"}); | ||
} | ||
function nodeStatusDisconnected() { | ||
node.status({fill: "red", shape: "dot", text: "disconnected"}); | ||
} | ||
function nodeStatusConnecting() { | ||
node.status({fill: "red", shape: "dot", text: "connecting"}); | ||
} | ||
/** | ||
@@ -197,5 +211,18 @@ * send a group write telegram to a group address | ||
// init a new one-off connection from the effectively singleton KnxController | ||
// there seems to be no way to reuse the outgoing conn in adreek/node-knxjs | ||
this.ctrl.initializeKnxConnection(function (connection) { | ||
if (connection.connected) | ||
nodeStatusConnected(); | ||
else | ||
nodeStatusDisconnected(); | ||
connection.removeListener('connecting', nodeStatusConnecting); | ||
connection.on('connecting', nodeStatusConnecting); | ||
connection.removeListener('connected', nodeStatusConnected); | ||
connection.on('connected', nodeStatusConnected); | ||
connection.removeListener('disconnected', nodeStatusDisconnected); | ||
connection.on('disconnected', nodeStatusDisconnected); | ||
try { | ||
@@ -236,9 +263,49 @@ log("sendAPDU: %j", JSON.stringify(value)); | ||
}); | ||
var that = this; | ||
var node = this; | ||
this.on("close", function () { | ||
if (that.receiveEvent && that.connection) | ||
that.connection.removeListener('event', that.receiveEvent); | ||
if (that.receiveStatus && that.connection) | ||
that.connection.removeListener('status', that.receiveStatus); | ||
if (node.receiveEvent && node.connection) | ||
node.connection.removeListener('event', node.receiveEvent); | ||
if (node.receiveStatus && node.connection) | ||
node.connection.removeListener('status', node.receiveStatus); | ||
}); | ||
function nodeStatusConnecting() { | ||
node.status({fill: "yellow", shape: "dot", text: "connecting"}); | ||
} | ||
function nodeStatusConnected() { | ||
node.status({fill: "yellow", shape: "dot", text: "connected"}); | ||
} | ||
function nodeStatusDisconnected() { | ||
node.status({fill: "yellow", shape: "dot", text: "disconnected"}); | ||
} | ||
node.receiveEvent = function (gad, data, datagram) { | ||
log('knx event gad[' + gad + ']data[' + data.toString('hex') + ']'); | ||
node.send({ | ||
topic: 'knx:event', | ||
payload: { | ||
'srcphy': datagram.source_address, | ||
'dstgad': gad, | ||
'dpt': 'no_dpt', | ||
'value': data.toString(), | ||
'type': 'event' | ||
} | ||
}); | ||
}; | ||
node.receiveStatus = function (gad, data, datagram) { | ||
log('knx status gad[' + gad + ']data[' + data.toString('hex') + ']'); | ||
node.send({ | ||
topic: 'knx:status', | ||
payload: { | ||
'srcphy': datagram.source_address, | ||
'dstgad': gad, | ||
'dpt': 'no_dpt', | ||
'value': data.toString(), | ||
'type': 'status' | ||
} | ||
}); | ||
}; | ||
// this.on("error", function(msg) {}); | ||
@@ -250,32 +317,18 @@ | ||
knxjsController.initializeKnxConnection(function (connection) { | ||
node.connection = connection; | ||
node.connection.removeListener('event', node.receiveEvent); | ||
node.connection.on('event', node.receiveEvent); | ||
node.connection.removeListener('status', node.receiveStatus); | ||
node.connection.on('status', node.receiveStatus); | ||
that.receiveEvent = function (gad, data, datagram) { | ||
log('knx event gad[' + gad + ']data[' + data.toString('hex') + ']'); | ||
node.send({ | ||
topic: 'knx:event', | ||
payload: { | ||
'srcphy': datagram.source_address, | ||
'dstgad': gad, | ||
'dpt': 'no_dpt', | ||
'value': data.toString(), | ||
'type': 'event' | ||
} | ||
}); | ||
}; | ||
that.receiveStatus = function (gad, data, datagram) { | ||
log('knx status gad[' + gad + ']data[' + data.toString('hex') + ']'); | ||
node.send({ | ||
topic: 'knx:status', | ||
payload: { | ||
'srcphy': datagram.source_address, | ||
'dstgad': gad, | ||
'dpt': 'no_dpt', | ||
'value': data.toString(), | ||
'type': 'status' | ||
} | ||
}); | ||
}; | ||
that.connection = connection; | ||
that.connection.on('event', that.receiveEvent); | ||
that.connection.on('status', that.receiveStatus); | ||
if (node.connection.connected) | ||
nodeStatusConnected(); | ||
else | ||
nodeStatusDisconnected(); | ||
node.connection.removeListener('connecting', nodeStatusConnecting); | ||
node.connection.on('connecting', nodeStatusConnecting); | ||
node.connection.removeListener('connected', nodeStatusConnected); | ||
node.connection.on('connected', nodeStatusConnected); | ||
node.connection.removeListener('disconnected', nodeStatusDisconnected); | ||
node.connection.on('disconnected', nodeStatusDisconnected); | ||
}); | ||
@@ -282,0 +335,0 @@ } |
{ | ||
"name": "node-red-contrib-knx", | ||
"version": "0.2.1", | ||
"version": "0.3.1", | ||
"description": "KNX for node-red, utilizing pure JavaScript KNXnet/IP driver (both works: tunelling & routing)", | ||
@@ -30,4 +30,4 @@ "main": "knx.js", | ||
"dependencies": { | ||
"knx.js": "^0.3.1" | ||
"knx.js": "^0.3.3" | ||
} | ||
} |
28394
305
Updatedknx.js@^0.3.3