node-red-contrib-knx
Advanced tools
Comparing version 0.4.0 to 0.5.0
51
knx.js
@@ -5,20 +5,7 @@ /** | ||
var KnxConnectionTunneling = require('knx.js').KnxConnectionTunneling; | ||
var util = require('util'), | ||
KnxConnectionTunneling = require('knx.js').KnxConnectionTunneling; | ||
function timestamp() { | ||
return new Date(). | ||
toISOString(). | ||
replace(/T/, ' '). // replace T with a space | ||
replace(/\..+/, '') | ||
} | ||
function log(msg, args) { | ||
if (args) | ||
console.log(timestamp() + ': ' + msg, args); | ||
else | ||
console.log(timestamp() + ': ' + msg); | ||
} | ||
module.exports = function (RED) { | ||
log("loading knx.js for node-red"); | ||
var knxjs = require('knx.js'); | ||
@@ -33,4 +20,4 @@ | ||
function KnxControllerNode(config) { | ||
log("new KnxControllerNode, config: %j", config); | ||
RED.nodes.createNode(this, config); | ||
this.name = config.name; | ||
this.host = config.host; | ||
@@ -41,2 +28,3 @@ this.port = config.port; | ||
var node = this; | ||
//node.log("new KnxControllerNode, config: " + util.inspect(config)); | ||
@@ -49,3 +37,3 @@ /** | ||
if (node.knxjsconn) { | ||
log('already connected to knxjs server at ' + config.host + ':' + config.port + ' in mode[' + config.mode + ']'); | ||
node.log('already connected to knxjs server at ' + config.host + ':' + config.port + ' in mode[' + config.mode + ']'); | ||
if (handler && (typeof handler === 'function')) | ||
@@ -55,3 +43,3 @@ handler(node.knxjsconn); | ||
} | ||
log('connecting to knxjs server at ' + config.host + ':' + config.port + ' in mode[' + config.mode + ']'); | ||
node.log('connecting to knxjs server at ' + config.host + ':' + config.port + ' in mode[' + config.mode + ']'); | ||
node.knxjsconn = null; | ||
@@ -61,9 +49,9 @@ if (config.mode === 'tunnel/unicast') { | ||
node.knxjsconn.Connect(function (err) { | ||
if (handler && (typeof handler === 'function')) | ||
if (!err && handler && (typeof handler === 'function')) | ||
handler(node.knxjsconn); | ||
if (err) { | ||
log('connecting to knxjs server at ' + config.host + ':' + config.port + ' in mode[' + config.mode + ']'); | ||
//node.warn('cannot connecting to knxjs server at ' + config.host + ':' + config.port + ' in mode[' + config.mode + '], cause: ' + util.inspect(err)); | ||
return null; | ||
} | ||
log('Knx: successfully connected to ' + config.host + ':' + config.port + ' in mode[' + config.mode + ']'); | ||
node.log('Knx: successfully connected to ' + config.host + ':' + config.port + ' in mode[' + config.mode + ']'); | ||
} | ||
@@ -77,3 +65,3 @@ ); | ||
this.on("close", function () { | ||
log('disconnecting from knxjs server at ' + config.host + ':' + config.port + ' in mode[' + config.mode + ']'); | ||
node.log('disconnecting from knxjs server at ' + config.host + ':' + config.port + ' in mode[' + config.mode + ']'); | ||
node.knxjsconn && node.knxjsconn.Disconnect && node.knxjsconn.Disconnect(); | ||
@@ -92,3 +80,2 @@ }); | ||
function KnxOut(config) { | ||
log('new Knx-OUT, config: %j', config); | ||
RED.nodes.createNode(this, config); | ||
@@ -98,5 +85,5 @@ this.name = config.name; | ||
var node = this; | ||
// | ||
//node.log('new Knx-OUT, config: ' + util.inspect(config)); | ||
this.on("input", function (msg) { | ||
log('knxout.onInput, msg=%j', msg); | ||
node.log('knxout.onInput, msg[' + util.inspect(msg) + ']'); | ||
if (!(msg && msg.hasOwnProperty('payload'))) return; | ||
@@ -110,3 +97,3 @@ var payload; | ||
if (payload == null) { | ||
log('knxout.onInput: illegal msg.payload!'); | ||
node.log('knxout.onInput: illegal msg.payload!'); | ||
return; | ||
@@ -127,3 +114,3 @@ } | ||
if (err) { | ||
log('groupAddrSend error: %j', err); | ||
node.error('groupAddrSend error: ' + util.inspect(err)); | ||
} | ||
@@ -134,3 +121,3 @@ }); | ||
this.on("close", function () { | ||
log('knxOut.close'); | ||
node.log('knxOut.close'); | ||
}); | ||
@@ -198,3 +185,3 @@ | ||
throw 'Unsupported action[' + action + '] inside of groupAddrSend'; | ||
log('groupAddrSend action[' + action + '] dstgad:' + dstgad + ', value:' + value + ', dpt:' + dpt); | ||
node.log('groupAddrSend action[' + action + '] dstgad:' + dstgad + ', value:' + value + ', dpt:' + dpt); | ||
switch (dpt) { | ||
@@ -240,3 +227,3 @@ case '1': //Switch | ||
try { | ||
log("sendAPDU: %j", JSON.stringify(value)); | ||
node.log("sendAPDU: " + util.inspect(value)); | ||
connection.Action(dstgad.toString(), value, dpt); | ||
@@ -246,3 +233,3 @@ callback && callback(); | ||
catch (err) { | ||
log('error calling groupAddrSend!: %j', err); | ||
node.error('error calling groupAddrSend: ' + err); | ||
callback(err); | ||
@@ -264,3 +251,2 @@ } | ||
function KnxIn(config) { | ||
log('new KNX-IN, config: %j', config); | ||
RED.nodes.createNode(this, config); | ||
@@ -270,2 +256,3 @@ this.name = config.name; | ||
var node = this; | ||
//node.log('new KNX-IN, config: ' + util.inspect(config)); | ||
var knxjsController = RED.nodes.getNode(config.controller); | ||
@@ -272,0 +259,0 @@ /* ===== Node-Red events ===== */ |
{ | ||
"name": "node-red-contrib-knx", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"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.3" | ||
"knx.js": "^0.5.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
28357
293
+ Addedknx.js@0.5.0(transitive)
- Removedknx.js@0.3.3(transitive)
Updatedknx.js@^0.5.0