mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Merge pull request #43 from henols/master
Deals with csv and json payload in a smarter way
This commit is contained in:
commit
afa46ef676
@ -20,25 +20,20 @@
|
||||
<input type="text" id="node-input-emonServer">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-topic"><i class="icon-tasks"></i> Topic</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 Group</label>
|
||||
<label for="node-input-nodegroup"><i class="icon-tag"></i> Node</label>
|
||||
<input type="text" id="node-input-nodegroup" placeholder="">
|
||||
</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="Emoncms">
|
||||
</div>
|
||||
<div class="form-tips">Topic is not mandatory, if Topic is left blank <b>msg.topic</b> will used. Topic overrides <b>msg.topic</b></br>
|
||||
Node Group (numeric) is not mandatory, if Node Group is left blank <b>msg.nodegrpup</b> will used. Node Group overrides <b>msg.nodegroup</b></div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="emoncms">
|
||||
<p>Performs post to Emoncms.</p>
|
||||
<p>Topic is not mandatory, if Topic is left blank <b>msg.topic</b> will used. Topic overrides <b>msg.topic</b></p>
|
||||
<p>Node Group (numeric) is not mandatory, if Node Group is left blank <b>msg.nodegrpup</b> will used. Node overrides <b>msg.nodegrpup</b></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>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -48,7 +43,6 @@
|
||||
defaults: {
|
||||
name: {value:"Emoncms"},
|
||||
emonServer: {type:"emoncms-server", required:true},
|
||||
topic: {value:""},
|
||||
nodegroup: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
@ -85,7 +79,6 @@
|
||||
category: 'config',
|
||||
defaults: {
|
||||
server: {value:"http://localhost",required:true},
|
||||
// apikey: {value:"",required:true},
|
||||
name: {value:""}
|
||||
},
|
||||
label: function() {
|
||||
|
@ -71,18 +71,24 @@ 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) {
|
||||
|
||||
var topic = this.topic || msg.topic;
|
||||
this.url = this.baseurl + '/input/post.json?';
|
||||
if(msg.payload.indexOf(':') > -1){
|
||||
this.url += 'json={' + msg.payload + '}';
|
||||
} else {
|
||||
this.url += 'csv='+msg.payload;
|
||||
}
|
||||
this.url += '&apikey='+this.apikey;
|
||||
var nodegroup = this.nodegroup || msg.nodegroup;
|
||||
this.url = this.baseurl + '/input/post.json?json={' + topic + ':' + msg.payload+'}&apikey='+this.apikey;
|
||||
if(nodegroup != ""){
|
||||
this.url += '&node='+nodegroup;
|
||||
this.url += '&node=' + nodegroup;
|
||||
}
|
||||
if(typeof msg.time !== 'undefined'){
|
||||
this.url += '&time=' + msg.time;
|
||||
}
|
||||
node.log("[emoncms] "+this.url);
|
||||
http.get(this.url, function(res) {
|
||||
|
Loading…
Reference in New Issue
Block a user