mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Automatic detection of csv and json call and simplified help text
This commit is contained in:
parent
e6f90f9b8d
commit
9808e8a3a6
@ -19,10 +19,6 @@
|
|||||||
<label for="node-input-emonServer"><i class="icon-globe"></i> Emoncms server</label>
|
<label for="node-input-emonServer"><i class="icon-globe"></i> Emoncms server</label>
|
||||||
<input type="text" id="node-input-emonServer">
|
<input type="text" id="node-input-emonServer">
|
||||||
</div>
|
</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">
|
<div class="form-row">
|
||||||
<label for="node-input-nodegroup"><i class="icon-tag"></i> Node</label>
|
<label for="node-input-nodegroup"><i class="icon-tag"></i> Node</label>
|
||||||
<input type="text" id="node-input-nodegroup" placeholder="">
|
<input type="text" id="node-input-nodegroup" placeholder="">
|
||||||
@ -31,20 +27,11 @@
|
|||||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Emoncms">
|
<input type="text" id="node-input-name" placeholder="Emoncms">
|
||||||
</div>
|
</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>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="emoncms">
|
<script type="text/x-red" data-help-name="emoncms">
|
||||||
<p>Performs post to Emoncms.</p>
|
<p>Emoncms post.</p>
|
||||||
<p>If <b>msg.payload</b> holds comma separated values (csv), Key and <b>msg.topic</b> is ignored.
|
<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,.. .
|
||||||
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>If Node is left blank <b>msg.nodegrpup</b> will used.</p>
|
<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>
|
||||||
@ -56,8 +43,6 @@
|
|||||||
defaults: {
|
defaults: {
|
||||||
name: {value:"Emoncms"},
|
name: {value:"Emoncms"},
|
||||||
emonServer: {type:"emoncms-server", required:true},
|
emonServer: {type:"emoncms-server", required:true},
|
||||||
payloadType: {value:"json"},
|
|
||||||
topic: {value:""},
|
|
||||||
nodegroup: {value:""}
|
nodegroup: {value:""}
|
||||||
},
|
},
|
||||||
inputs:1,
|
inputs:1,
|
||||||
|
@ -71,18 +71,16 @@ function Emoncms(n) {
|
|||||||
this.baseurl = sc.server;
|
this.baseurl = sc.server;
|
||||||
this.apikey = sc.apikey;
|
this.apikey = sc.apikey;
|
||||||
|
|
||||||
this.topic = n.topic ||"";
|
|
||||||
this.nodegroup = n.nodegroup || "";
|
this.nodegroup = n.nodegroup || "";
|
||||||
var node = this;
|
var node = this;
|
||||||
if (this.baseurl.substring(0,5) === "https") { var http = require("https"); }
|
if (this.baseurl.substring(0,5) === "https") { var http = require("https"); }
|
||||||
else { var http = require("http"); }
|
else { var http = require("http"); }
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
this.url = this.baseurl + '/input/post.json?';
|
this.url = this.baseurl + '/input/post.json?';
|
||||||
var topic = this.topic || msg.topic;
|
if(msg.payload.indexOf(':') > -1){
|
||||||
if(msg.payload.indexOf(',') > -1 || topic.trim() == ''){
|
this.url += 'json={' + msg.payload + '}';
|
||||||
this.url += 'csv='+msg.payload;
|
|
||||||
} else {
|
} else {
|
||||||
this.url += 'json={' + topic + ':' + msg.payload+'}';
|
this.url += 'csv='+msg.payload;
|
||||||
}
|
}
|
||||||
this.url += '&apikey='+this.apikey;
|
this.url += '&apikey='+this.apikey;
|
||||||
var nodegroup = this.nodegroup || msg.nodegroup;
|
var nodegroup = this.nodegroup || msg.nodegroup;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user