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">
|
||||
</div>
|
||||
<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="">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
@ -31,14 +38,21 @@
|
||||
<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>
|
||||
<div class="form-tips">If Payload is set to csv, <b>msg.payload</b> can be a comma separated values and the key will
|
||||
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 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>If Payload is set to csv, <b>msg.payload</b> can contain comma separated values and Key and <b>msg.topic</b> are ignored,
|
||||
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 type="text/javascript">
|
||||
@ -48,6 +62,7 @@
|
||||
defaults: {
|
||||
name: {value:"Emoncms"},
|
||||
emonServer: {type:"emoncms-server", required:true},
|
||||
payloadType: {value:"json"},
|
||||
topic: {value:""},
|
||||
nodegroup: {value:""}
|
||||
},
|
||||
@ -60,6 +75,18 @@
|
||||
},
|
||||
labelStyle: function() {
|
||||
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>
|
||||
@ -85,7 +112,6 @@
|
||||
category: 'config',
|
||||
defaults: {
|
||||
server: {value:"http://localhost",required:true},
|
||||
// apikey: {value:"",required:true},
|
||||
name: {value:""}
|
||||
},
|
||||
label: function() {
|
||||
|
@ -20,6 +20,7 @@ function EmoncmsServerNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.server = n.server;
|
||||
this.name = n.name;
|
||||
this.payloadType = n.payloadType;
|
||||
var credentials = RED.nodes.getCredentials(n.id);
|
||||
if (credentials) {
|
||||
this.apikey = credentials.apikey;
|
||||
@ -71,18 +72,27 @@ function Emoncms(n) {
|
||||
this.baseurl = sc.server;
|
||||
this.apikey = sc.apikey;
|
||||
|
||||
this.payloadType = n.payloadType;
|
||||
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(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;
|
||||
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