mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
lots of little node edits to clean up jsHint "errors"
This commit is contained in:
@@ -14,68 +14,70 @@
|
||||
* 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.name = n.name;
|
||||
}
|
||||
RED.nodes.registerType("emoncms-server",EmoncmsServerNode,{
|
||||
credentials: {
|
||||
apikey: {type:"text"}
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
//The Server Definition - this opens (and closes) the connection
|
||||
function EmoncmsServerNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.server = n.server;
|
||||
this.name = n.name;
|
||||
}
|
||||
});
|
||||
|
||||
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.credentials.apikey;
|
||||
|
||||
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) {
|
||||
this.url = this.baseurl + '/input/post.json?';
|
||||
if(msg.payload.indexOf(':') > -1){
|
||||
this.url += 'json={' + msg.payload + '}';
|
||||
} else {
|
||||
this.url += 'csv='+msg.payload;
|
||||
RED.nodes.registerType("emoncms-server",EmoncmsServerNode,{
|
||||
credentials: {
|
||||
apikey: {type:"text"}
|
||||
}
|
||||
this.url += '&apikey='+this.apikey;
|
||||
var nodegroup = this.nodegroup || msg.nodegroup;
|
||||
if(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) {
|
||||
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);
|
||||
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.credentials.apikey;
|
||||
|
||||
this.nodegroup = n.nodegroup || "";
|
||||
var node = this;
|
||||
var http;
|
||||
if (this.baseurl.substring(0,5) === "https") { http = require("https"); }
|
||||
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;
|
||||
}
|
||||
this.url += '&apikey='+this.apikey;
|
||||
var nodegroup = this.nodegroup || msg.nodegroup;
|
||||
if(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) {
|
||||
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);
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "node-red-node-emoncms",
|
||||
"version" : "0.0.2",
|
||||
"version" : "0.0.3",
|
||||
"description" : "A Node-RED node to send energy data to emoncms.org.",
|
||||
"dependencies" : {
|
||||
},
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "node-red-node-snmp",
|
||||
"version" : "0.0.1",
|
||||
"version" : "0.0.2",
|
||||
"description" : "A Node-RED node that looks for SNMP oids.",
|
||||
"dependencies" : {
|
||||
"net-snmp" : "1.1.13"
|
||||
|
@@ -15,6 +15,7 @@
|
||||
**/
|
||||
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var snmp = require ("net-snmp");
|
||||
|
||||
function SnmpNode(n) {
|
||||
@@ -67,9 +68,9 @@ module.exports = function(RED) {
|
||||
var maxRepetitions = 20;
|
||||
|
||||
function sortInt (a, b) {
|
||||
if (a > b) return 1;
|
||||
else if (b > a) return -1;
|
||||
else return 0;
|
||||
if (a > b) { return 1; }
|
||||
else if (b > a) { return -1; }
|
||||
else { return 0; }
|
||||
}
|
||||
|
||||
function responseCb (error, table) {
|
||||
@@ -77,11 +78,19 @@ module.exports = function(RED) {
|
||||
console.error (error.toString ());
|
||||
} else {
|
||||
var indexes = [];
|
||||
for (index in table) { indexes.push (parseInt (index)); }
|
||||
for (var index in table) {
|
||||
if (table.hasOwnProperty(index)) {
|
||||
indexes.push (parseInt (index));
|
||||
}
|
||||
}
|
||||
indexes.sort (sortInt);
|
||||
for (var i = 0; i < indexes.length; i++) {
|
||||
var columns = [];
|
||||
for (column in table[indexes[i]]) { columns.push(parseInt (column)); }
|
||||
for (var column in table[indexes[i]]) {
|
||||
if (table[indexes[i]].hasOwnProperty(column)) {
|
||||
columns.push(parseInt (column));
|
||||
}
|
||||
}
|
||||
columns.sort(sortInt);
|
||||
console.log ("row index = " + indexes[i]);
|
||||
for (var j = 0; j < columns.length; j++) {
|
||||
|
Reference in New Issue
Block a user