diff --git a/io/emoncms/88-emoncms.html b/io/emoncms/88-emoncms.html index 8f20f07e..d210d22d 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 4138b0bc..7635cb34 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) {