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">
|
<input type="text" id="node-input-emonServer">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-topic"><i class="icon-tasks"></i> Topic</label>
|
<label for="node-input-nodegroup"><i class="icon-tag"></i> Node</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>
|
|
||||||
<input type="text" id="node-input-nodegroup" placeholder="">
|
<input type="text" id="node-input-nodegroup" placeholder="">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<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">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>
|
||||||
|
|
||||||
<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>Topic is not mandatory, if Topic is left blank <b>msg.topic</b> will used. Topic overrides <b>msg.topic</b></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>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>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>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -48,7 +43,6 @@
|
|||||||
defaults: {
|
defaults: {
|
||||||
name: {value:"Emoncms"},
|
name: {value:"Emoncms"},
|
||||||
emonServer: {type:"emoncms-server", required:true},
|
emonServer: {type:"emoncms-server", required:true},
|
||||||
topic: {value:""},
|
|
||||||
nodegroup: {value:""}
|
nodegroup: {value:""}
|
||||||
},
|
},
|
||||||
inputs:1,
|
inputs:1,
|
||||||
@ -85,7 +79,6 @@
|
|||||||
category: 'config',
|
category: 'config',
|
||||||
defaults: {
|
defaults: {
|
||||||
server: {value:"http://localhost",required:true},
|
server: {value:"http://localhost",required:true},
|
||||||
// apikey: {value:"",required:true},
|
|
||||||
name: {value:""}
|
name: {value:""}
|
||||||
},
|
},
|
||||||
label: function() {
|
label: function() {
|
||||||
|
@ -71,19 +71,25 @@ 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?';
|
||||||
var topic = this.topic || msg.topic;
|
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;
|
var nodegroup = this.nodegroup || msg.nodegroup;
|
||||||
this.url = this.baseurl + '/input/post.json?json={' + topic + ':' + msg.payload+'}&apikey='+this.apikey;
|
|
||||||
if(nodegroup != ""){
|
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);
|
node.log("[emoncms] "+this.url);
|
||||||
http.get(this.url, function(res) {
|
http.get(this.url, function(res) {
|
||||||
node.log("Http response: " + res.statusCode);
|
node.log("Http response: " + res.statusCode);
|
||||||
|
Loading…
Reference in New Issue
Block a user