From 112a3abdc71e7873c37f6c0db39af61831ee7da1 Mon Sep 17 00:00:00 2001 From: henols Date: Fri, 7 Feb 2014 12:08:16 +0100 Subject: [PATCH] Emoncms A node that can publish to one or more Emoncms servers and acconts --- io/emoncms/88-emoncms.html | 94 ++++++++++++++++++++++++++++++ io/emoncms/88-emoncms.js | 71 ++++++++++++++++++++++ io/emoncms/icons/emoncms-logo.png | Bin 0 -> 1418 bytes 3 files changed, 165 insertions(+) create mode 100644 io/emoncms/88-emoncms.html create mode 100644 io/emoncms/88-emoncms.js create mode 100644 io/emoncms/icons/emoncms-logo.png diff --git a/io/emoncms/88-emoncms.html b/io/emoncms/88-emoncms.html new file mode 100644 index 00000000..ff71828b --- /dev/null +++ b/io/emoncms/88-emoncms.html @@ -0,0 +1,94 @@ + + + + + + + + + + + diff --git a/io/emoncms/88-emoncms.js b/io/emoncms/88-emoncms.js new file mode 100644 index 00000000..a40ee9a5 --- /dev/null +++ b/io/emoncms/88-emoncms.js @@ -0,0 +1,71 @@ +/** + * Copyright 2013 Henrik Olsson henols@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +var RED = require(process.env.NODE_RED_HOME+"/red/red"); +//The Server Definition - this opens (and closes) the connection +function EmoncmsServerNode(n) { + RED.nodes.createNode(this,n); + this.server = n.server; + this.apikey = n.apikey; + this.name = n.name; +} +RED.nodes.registerType("emoncms-server",EmoncmsServerNode); + +function Emoncms(n) { + RED.nodes.createNode(this,n); + this.emonServer = n.emonServer; + var sc = RED.nodes.getNode(this.emonServer); + + this.baseurl = sc.server; + this.apikey = sc.apikey; + + 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?json={' + topic + ':' + msg.payload+'}&apikey='+this.apikey; + if(this.nodegroup != ""){ + this.url += '&node='+this.nodegroup; + } + node.log("[emoncms] "+this.url); + http.get(this.url, function(res) { + node.log("Http response: " + res.statusCode); + msg.rc = res.statusCode; + msg.payload = ""; + if ((msg.rc != 200) && (msg.rc != 404)) { + node.send(msg); + } + res.setEncoding('utf8'); + res.on('data', function(chunk) { + msg.payload += chunk; + }); + res.on('end', function() { + node.send(msg); + }); + }).on('error', function(e) { + // node.error(e); + msg.rc = 503; + msg.payload = e; + node.send(msg); + }); + }); +} + +RED.nodes.registerType("emoncms",Emoncms); diff --git a/io/emoncms/icons/emoncms-logo.png b/io/emoncms/icons/emoncms-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..8cde78715855be139d55b070f2f3bd97fb28b410 GIT binary patch literal 1418 zcmV;51$Fv~P)(^b8FWQhbW?9;ba!ELWdL_~cP?peYja~^ zaAhuUa%Y?FJQ@H11qVq)K~zYIwU$e4RM#DczjN+$#$(SbeheOi85@%{kPzA;<4`M2 zLVyTxB1KLXRg>-#q;9fFltr3dqApr>m#S)|c2iYiL#%cMrFEJ(AvPG8$k>R7J=haG zhVi@~_i?(gu^^&Rk;0LFyL-M*_kSM$Ba~7+%po5t{XqpIBO|S&qobh*nIpcdL`RMs z=@vq~0X%CM=C(*AY%8V6=kqn!^)4&r|5FI@=drP|#RnD~K7908TU+b<0|VPT13??7 z=}@g!5mM3;45H~em2z3l&dx4ZtCbJN#>PJWzXT&ABb$8RKb}gZcE;oJ(Cpl0BH=LI z$s~zH0;S;QH(72hE>bKM8Q4BRHk&Oi%wJDyn)b?x6DOAbr(kq+)T}oeGf(V%GF2!R zP`+aDg`-^cqTKXas0)j~U4gjXU{|QZv(ekk{p%A<)4&b{RXTlPu3ReZIDPuGdxv?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