Skip to content

Commit

Permalink
added keepalive node, correct handling of online-node with more than …
Browse files Browse the repository at this point in the history
…one miniserver connection
  • Loading branch information
codmpm committed Apr 6, 2017
1 parent a3777a3 commit 0771c1c
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 13 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### 0.3.0
* added keepalive node
* correct handling of online-node with more than one miniserver connection

### 0.2.2
* fixed error if empty room name or empty category name

### 0.2.1
* fixed error on deploying after editing the config node

Expand All @@ -9,7 +16,8 @@

### 0.1.0
* breaks compatibility to 0.0.x
* updated `node-lox-ws`
* added webservice-node
* updated `node-lox-ws-api`

### 0.0.x
* control-in
Expand Down
54 changes: 54 additions & 0 deletions loxone/loxone.html
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,57 @@
});
</script>


<script type="text/x-red" data-help-name="loxone-keepalive">
<p>
This node outputs the current time (in ms) from the keepalive request
done by the underlying library every 2 minutes.<br>
The time could be used as an indicator on connection quality.<br>
<br>
See page 17 of the <a href="https://www.loxone.com/dede/wp-content/uploads/sites/2/2016/08/loxone-communicating-with-the-miniserver.pdf" target="_blank">
webservice documentation</a>.
</p>

</script>

<script type="text/x-red" data-template-name="loxone-keepalive">

<div class="form-row">
<label for="node-input-miniserver">
<i class="fa fa-globe"></i>
Miniserver
</label>
<input type="text" id="node-input-miniserver">
</div>

<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>

<div class="form-row">
<span id="return-msg"></span>
</div>

</script>

<script type="text/javascript">
RED.nodes.registerType('loxone-keepalive', {
category: 'loxone',
paletteLabel: 'keepalive',
color: '#83B817',
defaults: {
name: {value: ''},
miniserver: {type: 'loxone-miniserver', required: true},
},
inputs: 0,
outputs: 1,
icon: "loxone.png",
align: "left",
label: function () {
return this.name || "keepalive";
}
});
</script>


45 changes: 34 additions & 11 deletions loxone/loxone.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ module.exports = function (RED) {
client.connect();

client.on('connect', function () {
node.log('Miniserver connected (' + config.host + ':' + config.port) + ')';
node.log('Miniserver connected (' + config.host + ':' + config.port + ')');
node.connected = true;
});

Expand All @@ -133,7 +133,7 @@ module.exports = function (RED) {
node.connection = client;

node.setConnectionState("green", "connected", "dot");
sendOnlineMsg(true);
sendOnlineMsg(true, config.id);
});

client.on('connect_failed', function () {
Expand All @@ -153,7 +153,7 @@ module.exports = function (RED) {
node.connection = null;

node.setConnectionState("yellow", "connection closed", "ring");
sendOnlineMsg(false);
sendOnlineMsg(false, config.id);
});

client.on('send', function (message) {
Expand Down Expand Up @@ -206,6 +206,23 @@ module.exports = function (RED) {

client.on('keepalive', function (time) {
node.log('keepalive (' + time + 'ms)');

RED.nodes.eachNode(function (nodeData) {

if (nodeData.type === 'loxone-keepalive' &&
nodeData.hasOwnProperty('miniserver') &&
nodeData.miniserver === node.id) {

var keepaliveNode = RED.nodes.getNode(nodeData.id);
if (keepaliveNode) {
keepaliveNode.send({
topic: 'keepalive',
payload: time
});
}
}
});

});

client.on('message_header', function (header) {
Expand Down Expand Up @@ -241,7 +258,7 @@ module.exports = function (RED) {
} else {
done();
}
sendOnlineMsg(false);
sendOnlineMsg(false, config.id);
});

}
Expand Down Expand Up @@ -291,7 +308,8 @@ module.exports = function (RED) {
});
};

LoxoneMiniserver.prototype.setConnectionState = function (color, text, shape = 'dot') {
LoxoneMiniserver.prototype.setConnectionState = function (color, text, shape) {
shape = shape || 'dot';
var newState = function (item) {
item.status({
fill: color,
Expand Down Expand Up @@ -393,13 +411,15 @@ module.exports = function (RED) {
return structure;
};

function sendOnlineMsg(online) {
function sendOnlineMsg(online, configId) {

online = online || false;

RED.nodes.eachNode(function (theNode) {

if (theNode.type == 'loxone-online') {
if (theNode.type === 'loxone-online' &&
theNode.hasOwnProperty('miniserver') &&
theNode.miniserver === configId) {

var node = RED.nodes.getNode(theNode.id);

Expand Down Expand Up @@ -520,12 +540,15 @@ module.exports = function (RED) {

function LoxoneOnlineNode(config) {
RED.nodes.createNode(this, config);
var node = this;
node.miniserver = RED.nodes.getNode(config.miniserver);
}

RED.nodes.registerType('loxone-online', LoxoneOnlineNode);

function LoxoneKeepaliveNode(config) {
RED.nodes.createNode(this, config);
}

RED.nodes.registerType('loxone-keepalive', LoxoneKeepaliveNode);


}
;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-loxone",
"version": "0.2.2",
"version": "0.3.0",
"description": "Connecting the Loxone Miniserver to node-red via Websocket API",
"license": "MIT",
"keywords": [
Expand Down

0 comments on commit 0771c1c

Please sign in to comment.