Skip to content

Commit

Permalink
Automatic detection of csv and json call and simplified help text
Browse files Browse the repository at this point in the history
  • Loading branch information
henols committed Apr 3, 2014
1 parent e6f90f9 commit 9808e8a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
21 changes: 3 additions & 18 deletions io/emoncms/88-emoncms.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
<label for="node-input-emonServer"><i class="icon-globe"></i> Emoncms server</label>
<input type="text" id="node-input-emonServer">
</div>
<div class="form-row">
<label for="node-input-topic"><i class="icon-tasks"></i> Key</label>
<input type="text" id="node-input-topic" placeholder="">
</div>
<div class="form-row">
<label for="node-input-nodegroup"><i class="icon-tag"></i> Node</label>
<input type="text" id="node-input-nodegroup" placeholder="">
Expand All @@ -31,22 +27,13 @@
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Emoncms">
</div>
<div class="form-tips">If <b>msg.payload</b> holds comma separated values (csv), Key and <b>msg.topic</b> is ignored and the key will
be automatically generated by Emoncms. If <b>msg.payload</b> holds a single value and Key and <b>msg.topic</b> is not specified, <b>msg.payload</b>
will be treated as a csv otherwise it will be treated as a json payload and the key value can be manually or programmatically set.</br></br>
Key is not mandatory, if Key is left blank <b>msg.topic</b> will used. Key overrides <b>msg.topic</b>, it will be ignored if <b>msg.payload</b> is holding csv</br></br>
Node (numeric) is not mandatory, if Node is left blank <b>msg.nodegrpup</b> will used. Node over rides <b>msg.nodegroup</b>.
</div>
</script>

<script type="text/x-red" data-help-name="emoncms">
<p>Performs post to Emoncms.</p>
<p>If <b>msg.payload</b> holds comma separated values (csv), Key and <b>msg.topic</b> is ignored.
If <b>msg.payload</b> holds a single value and Key and <b>msg.topic</b> is not specified, <b>msg.payload</b>
will be treated as a csv otherwise it will be treated as a json payload</p>
<p>If Key is left blank <b>msg.topic</b> will used, ignored if <b>msg.payload</b> holds csv.</p>
<p>Emoncms post.</p>
<p>The <b>msg.payload</b> can contain either a comma separated list of name value pairs ex. name:value,... or a comma separated list of values ex. 1,2,.. .
<p>If Node is left blank <b>msg.nodegrpup</b> will used.</p>
<p>Insertion time can be manipulated by setting <b>msg.time</b>.</p>
<p>Insertion time can be manipulated by setting <b>msg.time</b>.</p>
</script>

<script type="text/javascript">
Expand All @@ -56,8 +43,6 @@
defaults: {
name: {value:"Emoncms"},
emonServer: {type:"emoncms-server", required:true},
payloadType: {value:"json"},
topic: {value:""},
nodegroup: {value:""}
},
inputs:1,
Expand Down
8 changes: 3 additions & 5 deletions io/emoncms/88-emoncms.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,16 @@ function Emoncms(n) {
this.baseurl = sc.server;
this.apikey = sc.apikey;

this.topic = n.topic ||"";
this.nodegroup = n.nodegroup || "";
var node = this;
if (this.baseurl.substring(0,5) === "https") { var http = require("https"); }
else { var http = require("http"); }
this.on("input", function(msg) {
this.url = this.baseurl + '/input/post.json?';
var topic = this.topic || msg.topic;
if(msg.payload.indexOf(',') > -1 || topic.trim() == ''){
this.url += 'csv='+msg.payload;
if(msg.payload.indexOf(':') > -1){
this.url += 'json={' + msg.payload + '}';
} else {
this.url += 'json={' + topic + ':' + msg.payload+'}';
this.url += 'csv='+msg.payload;
}
this.url += '&apikey='+this.apikey;
var nodegroup = this.nodegroup || msg.nodegroup;
Expand Down

0 comments on commit 9808e8a

Please sign in to comment.