mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Support for csv payload and manipulation insertion time
This commit is contained in:
parent
4b3db1e780
commit
8a60d1f918
@ -20,7 +20,14 @@
|
|||||||
<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-payloadType"><i class="icon-envelope"></i> Payload</label>
|
||||||
|
<select id="node-input-payloadType" style="width:125px !important">
|
||||||
|
<option value="csv">csv</option>
|
||||||
|
<option value="json">json</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row" id="node-input-row-topic">
|
||||||
|
<label for="node-input-topic"><i class="icon-tasks"></i> Key</label>
|
||||||
<input type="text" id="node-input-topic" placeholder="">
|
<input type="text" id="node-input-topic" placeholder="">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
@ -31,14 +38,21 @@
|
|||||||
<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>
|
<div class="form-tips">If Payload is set to csv, <b>msg.payload</b> can be a comma separated values and the key will
|
||||||
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>
|
be automatically generated by Emoncms, if Payload is set to json, <b>msg.payload</b> can only be a single value 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></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>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>If Payload is set to csv, <b>msg.payload</b> can contain comma separated values and Key and <b>msg.topic</b> are ignored,
|
||||||
<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>
|
if Payload is set to json, <b>msg.payload</b> can only be a single value and Key or <b>msg.topic</b> must be specified</p>
|
||||||
|
<p>If Key is left blank <b>msg.topic</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>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -48,6 +62,7 @@
|
|||||||
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:""},
|
topic: {value:""},
|
||||||
nodegroup: {value:""}
|
nodegroup: {value:""}
|
||||||
},
|
},
|
||||||
@ -60,6 +75,18 @@
|
|||||||
},
|
},
|
||||||
labelStyle: function() {
|
labelStyle: function() {
|
||||||
return this.name?"node_label_italic":"";
|
return this.name?"node_label_italic":"";
|
||||||
|
},
|
||||||
|
oneditprepare: function() {
|
||||||
|
$("#node-input-payloadType").change(function() {
|
||||||
|
var id = $("#node-input-payloadType option:selected").val();
|
||||||
|
if (id == "json") {
|
||||||
|
$("#node-input-row-topic").show();
|
||||||
|
} else {
|
||||||
|
$("#node-input-row-topic").hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$("#node-input-payloadType").val(this.payloadType);
|
||||||
|
$("#node-input-payloadType").change();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@ -85,7 +112,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() {
|
||||||
|
@ -20,6 +20,7 @@ function EmoncmsServerNode(n) {
|
|||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.server = n.server;
|
this.server = n.server;
|
||||||
this.name = n.name;
|
this.name = n.name;
|
||||||
|
this.payloadType = n.payloadType;
|
||||||
var credentials = RED.nodes.getCredentials(n.id);
|
var credentials = RED.nodes.getCredentials(n.id);
|
||||||
if (credentials) {
|
if (credentials) {
|
||||||
this.apikey = credentials.apikey;
|
this.apikey = credentials.apikey;
|
||||||
@ -71,18 +72,27 @@ function Emoncms(n) {
|
|||||||
this.baseurl = sc.server;
|
this.baseurl = sc.server;
|
||||||
this.apikey = sc.apikey;
|
this.apikey = sc.apikey;
|
||||||
|
|
||||||
|
this.payloadType = n.payloadType;
|
||||||
this.topic = n.topic ||"";
|
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(this.payloadType == 'json'){
|
||||||
|
var topic = this.topic || msg.topic;
|
||||||
|
this.url += 'json={' + topic + ':' + 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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user