Skip to content

Commit

Permalink
webservice-node: added optional appending of msg.payload to uri
Browse files Browse the repository at this point in the history
  • Loading branch information
codmpm committed Apr 17, 2017
1 parent b5982ea commit ed99692
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 0.4.0
* webservice-node: added checkbox for appending `msg.payload` to the URI of the webservice node

### 0.3.1
* review readme
* fixed image display from readme on flows.nodered.org
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ The flow itself could be found here: http://flows.nodered.org/flow/0b3c81b336102
The webservice node, added in version `0.1.0`, allows you to directly call webservice URI's through the already
established websocket connection.

Beginning with version `0.4.0` you can choose to automaticly append the incoming `msg.payload` to the set URI.
This is handy to add dynamic content to the webservice call, for example `DownOn` or `DownOff`.

As the `UpDownDigital` (etc.) virtual input has no state where the control-in node can listen to, I've switched it as
an example via the webservice-node. See a short video here: https://cloud.codm.de/nextcloud/index.php/s/IttSURIGl8OkUBf

Expand Down
56 changes: 46 additions & 10 deletions loxone/loxone.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
if (node) {
var url = './loxone-miniserver/struct?id=' + node.id;

if (node.credentials || node.changed){
if (node.credentials || node.changed) {
url = './loxone-miniserver/struct-changed' +
'?id=' + node.id +
'&host=' + encodeURIComponent(node.host) +
'&port=' + encodeURIComponent(node.port);

if (node.credentials){
if (node.credentials.username){
if (node.credentials) {
if (node.credentials.username) {
url += '&username=' + encodeURIComponent(node.credentials.username);
}
if (node.credentials.password){
if (node.credentials.password) {
url += '&password=' + encodeURIComponent(node.credentials.password);
}
}
Expand Down Expand Up @@ -200,6 +200,8 @@
</a>.
</p>



</script>

<script type="text/x-red" data-template-name="loxone-control-in">
Expand Down Expand Up @@ -258,6 +260,8 @@
</div>




</script>

<script type="text/javascript">
Expand Down Expand Up @@ -332,6 +336,8 @@
Control as described in the Structure File Documentation.
</p>



</script>


Expand Down Expand Up @@ -381,6 +387,8 @@
<span id="return-msg"></span>
</div>



</script>

<script type="text/javascript">
Expand Down Expand Up @@ -443,7 +451,6 @@
</script>



<script type="text/x-red" data-help-name="loxone-miniserver">
<p>
Configure the Miniserver to connect to, the default port is 80. The credentials will be hashed with a key given by the Miniserver.<br>
Expand All @@ -461,6 +468,8 @@
For further details, see the API-documentation.
</p>



</script>


Expand Down Expand Up @@ -494,6 +503,8 @@
</label>
</div>



</script>

<script type="text/javascript">
Expand All @@ -518,7 +529,6 @@
</script>



<script type="text/x-red" data-help-name="loxone-webservice">
<p>
This is used to get a return from a webservice call through the existing
Expand All @@ -528,7 +538,10 @@
See the <a href="https://www.loxone.com/enen/kb/web-services/" target="_blank">Webservice documenation</a><br>
The configured Websocket-Connection is used for communication.<br>
<br>
<code>msg.uri</code> from the incoming message object overwrites the set uri.
<code>msg.uri</code> from the incoming message object overwrites the set uri. <br>
<br>
You can choose if <code>msg.payload</code> should be appended to the URI call. This works for the set URIs
and for URIs from <code>msg.uri</code>.<br>
<br>
The return will hold the answer from the requested datapoint (URI):<br>
<pre>{
Expand All @@ -541,6 +554,8 @@
<b>Currently no AES command encryption for Webservice-Calls</b>
</p>



</script>


Expand All @@ -562,20 +577,33 @@
<input type="text" id="node-input-uri" placeholder="jdev/cfg/version">
</div>

<div class="form-row" id="node-appendpayload">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-appendpayload" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-appendpayload" style="width: 70%;">Append <code>msg.payload</code>?</label>
</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-tips">
The URI has to start with <code>jdev/</code> as <code>dev/</code> is deprecated!<br>
Simply add use 'jdev' instead of 'dev' according to the documenation.
Simply add use 'jdev' instead of 'dev' according to the documenation.<br>
<br>
Checking the 'append payload' checkbox will append <code>msg.payload</code> to the set URI
either if it is set in the node or supplied via <code>msg.uri</code>.<br>
(<code>jdev/sps/foo/{msg.payload}</code>)
</div>

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



</script>

<script type="text/javascript">
Expand All @@ -586,7 +614,8 @@
defaults: {
name: {value: ''},
miniserver: {type: 'loxone-miniserver', required: true},
uri: {value: ''}
uri: {value: ''},
appendpayload: {value: false}
},
inputs: 1,
outputs: 1,
Expand All @@ -599,13 +628,14 @@
</script>



<script type="text/x-red" data-help-name="loxone-online">
<p>
This node simply outputs <code>true</code> or <code>false</code> in
<code>msg.payload</code> when the miniserver comes online or goes offline.
</p>



</script>


Expand All @@ -628,6 +658,8 @@
<span id="return-msg"></span>
</div>



</script>

<script type="text/javascript">
Expand Down Expand Up @@ -660,6 +692,8 @@
webservice documentation</a>.
</p>



</script>

<script type="text/x-red" data-template-name="loxone-keepalive">
Expand All @@ -681,6 +715,8 @@
<span id="return-msg"></span>
</div>



</script>

<script type="text/javascript">
Expand Down
7 changes: 4 additions & 3 deletions loxone/loxone.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,13 @@ module.exports = function (RED) {
return null;
}

node.uri = wantedURI;
//node.log('sending ' + wantedURI);
node.uri = wantedURI + ((config.appendpayload === true) ? msg.payload : '');

//node.log('sending ' + node.uri);

//add node to the queue for waiting messages and send the URI
node.miniserver.registerWebserviceNode(node);
node.miniserver.connection.connection.send(wantedURI);
node.miniserver.connection.connection.send(node.uri);

});

Expand Down
Binary file modified node-red-contrib-loxone-webservice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.3.1",
"version": "0.4.0",
"description": "Connecting the Loxone Miniserver to node-red via Websocket API",
"license": "MIT",
"keywords": [
Expand Down

0 comments on commit ed99692

Please sign in to comment.