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

@@ -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;