Deals with csv and json payload in a smarter way and manipulation

insertion time
This commit is contained in:
henols
2014-03-20 14:51:16 +01:00
parent 8a60d1f918
commit e6f90f9b8d
2 changed files with 13 additions and 33 deletions

View File

@@ -20,7 +20,6 @@ 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;
@@ -72,7 +71,6 @@ 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;
@@ -80,11 +78,11 @@ function Emoncms(n) {
else { var http = require("http"); }
this.on("input", function(msg) {
this.url = this.baseurl + '/input/post.json?';
if(this.payloadType == 'json'){
var topic = this.topic || msg.topic;
this.url += 'json={' + topic + ':' + msg.payload+'}';
} else {
var topic = this.topic || msg.topic;
if(msg.payload.indexOf(',') > -1 || topic.trim() == ''){
this.url += 'csv='+msg.payload;
} else {
this.url += 'json={' + topic + ':' + msg.payload+'}';
}
this.url += '&apikey='+this.apikey;
var nodegroup = this.nodegroup || msg.nodegroup;