1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

let emoncms node accept simple objects

This commit is contained in:
Dave Conway-Jones 2015-11-30 14:23:52 +00:00
parent d8f1ecc629
commit 396173525b
2 changed files with 11 additions and 5 deletions

View File

@ -32,7 +32,8 @@
<script type="text/x-red" data-help-name="emoncms">
<p>Posts data to Emoncms.</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,.. .
value pairs e.g. <pre>name:value,...</pre> or a comma separated list of values e.g. <pre>1,2,...</pre>
or a simple javascript object e.g. <pre>msg.payload = {temp:12}</pre>
<p>If Node is left blank <b>msg.nodegroup</b> will used.</p>
<p>Insertion time can be manipulated by setting <b>msg.time</b>.</p>
</script>

View File

@ -43,10 +43,15 @@ module.exports = function(RED) {
else { http = require("http"); }
this.on("input", function(msg) {
this.url = this.baseurl + '/input/post.json?';
if (msg.payload.indexOf(':') > -1) {
this.url += 'json={' + msg.payload + '}';
} else {
this.url += 'csv='+msg.payload;
if (typeof(msg.payload) !== "string") {
this.url += 'json=' + JSON.stringify(msg.payload);
}
else {
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;