From 8a60d1f9185a7a26635c453186f473121dd12bd2 Mon Sep 17 00:00:00 2001 From: henols Date: Wed, 19 Mar 2014 22:20:27 +0100 Subject: [PATCH 1/3] Support for csv payload and manipulation insertion time --- io/emoncms/88-emoncms.html | 38 ++++++++++++++++++++++++++++++++------ io/emoncms/88-emoncms.js | 18 ++++++++++++++---- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/io/emoncms/88-emoncms.html b/io/emoncms/88-emoncms.html index 8f20f07eb..d210d22d9 100644 --- a/io/emoncms/88-emoncms.html +++ b/io/emoncms/88-emoncms.html @@ -20,7 +20,14 @@
- + + +
+
+
@@ -31,14 +38,21 @@
-
Topic is not mandatory, if Topic is left blank msg.topic will used. Topic overrides msg.topic
- Node Group (numeric) is not mandatory, if Node Group is left blank msg.nodegrpup will used. Node Group overrides msg.nodegroup
+
If Payload is set to csv, msg.payload can be a comma separated values and the key will + be automatically generated by Emoncms, if Payload is set to json, msg.payload can only be a single value and + the key value can be manually or programmatically set.

+ Key is not mandatory, if Key is left blank msg.topic will used. Key overrides msg.topic

+ Node (numeric) is not mandatory, if Node is left blank msg.nodegrpup will used. Node over rides msg.nodegroup. +
@@ -85,7 +112,6 @@ category: 'config', defaults: { server: {value:"http://localhost",required:true}, - // apikey: {value:"",required:true}, name: {value:""} }, label: function() { diff --git a/io/emoncms/88-emoncms.js b/io/emoncms/88-emoncms.js index 4138b0bc2..7635cb349 100644 --- a/io/emoncms/88-emoncms.js +++ b/io/emoncms/88-emoncms.js @@ -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) { From e6f90f9b8d3021885fe48f0e125e3abcca6bcaf5 Mon Sep 17 00:00:00 2001 From: henols Date: Thu, 20 Mar 2014 14:51:16 +0100 Subject: [PATCH 2/3] Deals with csv and json payload in a smarter way and manipulation insertion time --- io/emoncms/88-emoncms.html | 36 +++++++++--------------------------- io/emoncms/88-emoncms.js | 10 ++++------ 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/io/emoncms/88-emoncms.html b/io/emoncms/88-emoncms.html index d210d22d9..de9234d59 100644 --- a/io/emoncms/88-emoncms.html +++ b/io/emoncms/88-emoncms.html @@ -20,37 +20,31 @@
- - -
-
- +
-
If Payload is set to csv, msg.payload can be a comma separated values and the key will - be automatically generated by Emoncms, if Payload is set to json, msg.payload can only be a single value and - the key value can be manually or programmatically set.

- Key is not mandatory, if Key is left blank msg.topic will used. Key overrides msg.topic

+
If msg.payload holds comma separated values (csv), Key and msg.topic is ignored and the key will + be automatically generated by Emoncms. If msg.payload holds a single value and Key and msg.topic is not specified, msg.payload + will be treated as a csv otherwise it will be treated as a json payload and the key value can be manually or programmatically set.

+ Key is not mandatory, if Key is left blank msg.topic will used. Key overrides msg.topic, it will be ignored if msg.payload is holding csv

Node (numeric) is not mandatory, if Node is left blank msg.nodegrpup will used. Node over rides msg.nodegroup.
@@ -75,18 +69,6 @@ }, 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(); } }); diff --git a/io/emoncms/88-emoncms.js b/io/emoncms/88-emoncms.js index 7635cb349..938cdad57 100644 --- a/io/emoncms/88-emoncms.js +++ b/io/emoncms/88-emoncms.js @@ -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; From 9808e8a3a6c01828e854240409be4efe969c3c89 Mon Sep 17 00:00:00 2001 From: henols Date: Thu, 3 Apr 2014 09:42:49 +0200 Subject: [PATCH 3/3] Automatic detection of csv and json call and simplified help text --- io/emoncms/88-emoncms.html | 21 +++------------------ io/emoncms/88-emoncms.js | 8 +++----- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/io/emoncms/88-emoncms.html b/io/emoncms/88-emoncms.html index de9234d59..22cd2e270 100644 --- a/io/emoncms/88-emoncms.html +++ b/io/emoncms/88-emoncms.html @@ -19,10 +19,6 @@
-
- - -
@@ -31,22 +27,13 @@
-
If msg.payload holds comma separated values (csv), Key and msg.topic is ignored and the key will - be automatically generated by Emoncms. If msg.payload holds a single value and Key and msg.topic is not specified, msg.payload - will be treated as a csv otherwise it will be treated as a json payload and the key value can be manually or programmatically set.

- Key is not mandatory, if Key is left blank msg.topic will used. Key overrides msg.topic, it will be ignored if msg.payload is holding csv

- Node (numeric) is not mandatory, if Node is left blank msg.nodegrpup will used. Node over rides msg.nodegroup. -