Re-lint a load of nodes

This commit is contained in:
Dave Conway-Jones 2017-01-29 17:45:44 +00:00
parent 603189f123
commit 316a2fd272
42 changed files with 447 additions and 254 deletions

View File

@ -6,11 +6,13 @@
"disallowMixedSpacesAndTabs": true, "disallowMixedSpacesAndTabs": true,
"disallowMultipleSpaces": {"allowEOLComments": true}, "disallowMultipleSpaces": {"allowEOLComments": true},
"disallowKeywordsOnNewLine": [], "disallowKeywordsOnNewLine": [],
"requireKeywordsOnNewLine": ["else", "catch"],
"requireSpaceBeforeBlockStatements": 1, "requireSpaceBeforeBlockStatements": 1,
//"requireSpaceBeforeObjectValues": false, //"requireSpaceBeforeObjectValues": false,
//"requireSemicolons": true, //"requireSemicolons": true,
//"validateParameterSeparator": ", ", //"validateParameterSeparator": ", ",
//"validateQuoteMarks": false, //"validateQuoteMarks": false,
"requireSpaceAfterKeywords": ["do","for","if","else","switch","case","try","while"], "requireSpaceAfterKeywords": ["do","for","if","else","switch","case","try","while"],
"maximumLineLength": 255 "maximumLineLength": 255,
"disallowTabs": true
} }

View File

@ -20,14 +20,17 @@ module.exports = function(RED) {
} }
if (node.fieldType === 'msg') { if (node.fieldType === 'msg') {
RED.util.setMessageProperty(msg,node.field,value); RED.util.setMessageProperty(msg,node.field,value);
} else if (node.fieldType === 'flow') { }
else if (node.fieldType === 'flow') {
node.context().flow.set(node.field,value); node.context().flow.set(node.field,value);
} else if (node.fieldType === 'global') { }
else if (node.fieldType === 'global') {
node.context().global.set(node.field,value); node.context().global.set(node.field,value);
} }
node.send(msg); node.send(msg);
} catch(err) { }
node.error(err.message); catch(e) {
node.error(e.message);
} }
}); });
} }

View File

@ -10,7 +10,8 @@ module.exports = function(RED) {
this.on("input", function(msg) { this.on("input", function(msg) {
if (node.inte == "true" || node.inte === true) { if (node.inte == "true" || node.inte === true) {
msg.payload = Math.round(Number(Math.random()) * (node.high - node.low + 1) + node.low - 0.5); msg.payload = Math.round(Number(Math.random()) * (node.high - node.low + 1) + node.low - 0.5);
} else { }
else {
msg.payload = Number(Math.random()) * (node.high - node.low) + node.low; msg.payload = Number(Math.random()) * (node.high - node.low) + node.low;
} }
node.send(msg); node.send(msg);

View File

@ -42,7 +42,7 @@ module.exports = function(RED) {
tot = tot + n - pop; tot = tot + n - pop;
tot2 = tot2 + (n*n) - (pop * pop); tot2 = tot2 + (n*n) - (pop * pop);
if (a.length > 1) { if (a.length > 1) {
msg.payload = Math.sqrt((a.length * tot2 - tot * tot)/(a.length * (a.length - 1))); msg.payload = Math.sqrt((a.length * tot2 - tot * tot)/(a.length * (a.length - 1)));
} }
else { msg.payload = 0; } else { msg.payload = 0; }
} }

View File

@ -14,9 +14,11 @@ module.exports = function (RED) {
adjustName = function (pin) { adjustName = function (pin) {
if (pin === "P8_7") { if (pin === "P8_7") {
pin = "P8_07"; pin = "P8_07";
} else if (pin === "P8_8") { }
else if (pin === "P8_8") {
pin = "P8_08"; pin = "P8_08";
} else if (pin === "P8_9") { }
else if (pin === "P8_9") {
pin = "P8_09"; pin = "P8_09";
} }
return pin; return pin;
@ -38,7 +40,8 @@ module.exports = function (RED) {
this.averaging = n.averaging; this.averaging = n.averaging;
if (this.averaging) { if (this.averaging) {
this.averages = 10; this.averages = 10;
} else { }
else {
this.averages = 1; this.averages = 1;
} }
@ -54,7 +57,8 @@ module.exports = function (RED) {
count = count - 1; count = count - 1;
if (count > 0) { if (count > 0) {
bonescript.analogRead(node._pin, analogReadCallback); bonescript.analogRead(node._pin, analogReadCallback);
} else { }
else {
var msg = {}; var msg = {};
msg.topic = node.topic; msg.topic = node.topic;
sum = sum/node.averages; sum = sum/node.averages;
@ -76,7 +80,8 @@ module.exports = function (RED) {
count = node.averages; count = node.averages;
bonescript.analogRead(node._pin, analogReadCallback); bonescript.analogRead(node._pin, analogReadCallback);
}); });
} else { }
else {
node.error("Unconfigured input pin"); node.error("Unconfigured input pin");
} }
} }
@ -92,18 +97,22 @@ module.exports = function (RED) {
this._pin = adjustName(this.pin); // Adjusted for Octal if necessary this._pin = adjustName(this.pin); // Adjusted for Octal if necessary
if (n.activeLow) { // Set the 'active' state 0 or 1 as appropriate if (n.activeLow) { // Set the 'active' state 0 or 1 as appropriate
this.activeState = 0; this.activeState = 0;
} else { }
else {
this.activeState = 1; this.activeState = 1;
} }
this.updateInterval = n.updateInterval*1000; // How often to send totalActiveTime messages this.updateInterval = n.updateInterval*1000; // How often to send totalActiveTime messages
this.debounce = n.debounce || null; // Enable switch contact debouncing algorithm this.debounce = n.debounce || null; // Enable switch contact debouncing algorithm
if (n.outputOn === "rising") { if (n.outputOn === "rising") {
this.activeEdges = [false, true]; this.activeEdges = [false, true];
} else if (n.outputOn === "falling") { }
else if (n.outputOn === "falling") {
this.activeEdges = [true, false]; this.activeEdges = [true, false];
} else if (n.outputOn === "both") { }
else if (n.outputOn === "both") {
this.activeEdges = [true, true]; this.activeEdges = [true, true];
} else { }
else {
node.error("Invalid edge type: " + n.outputOn); node.error("Invalid edge type: " + n.outputOn);
} }
@ -130,10 +139,12 @@ module.exports = function (RED) {
node.interruptAttached = true; node.interruptAttached = true;
node.on("input", inputCallback); node.on("input", inputCallback);
node.intervalId = setInterval(timerCallback, node.updateInterval); node.intervalId = setInterval(timerCallback, node.updateInterval);
} else { }
else {
node.error("Failed to attach interrupt"); node.error("Failed to attach interrupt");
} }
} else if (node.currentState !== Number(x)) { }
else if (node.currentState !== Number(x)) {
if (node.debounce) { if (node.debounce) {
if (node.debouncing === false) { if (node.debouncing === false) {
node.debouncing = true; node.debouncing = true;
@ -141,7 +152,8 @@ module.exports = function (RED) {
bonescript.digitalRead(node._pin, debounceCallback); bonescript.digitalRead(node._pin, debounceCallback);
}, Number(node.debounce)); }, Number(node.debounce));
} }
} else { }
else {
sendStateMessage(x); sendStateMessage(x);
} }
} }
@ -166,7 +178,8 @@ module.exports = function (RED) {
var now = Date.now(); var now = Date.now();
if (node.currentState === node.activeState) { if (node.currentState === node.activeState) {
node.lastActiveTime = now; node.lastActiveTime = now;
} else if (!isNaN(node.lastActiveTime)) { }
else if (!isNaN(node.lastActiveTime)) {
node.totalActiveTime += now - node.lastActiveTime; node.totalActiveTime += now - node.lastActiveTime;
} }
if (node.activeEdges[node.currentState]) { if (node.activeEdges[node.currentState]) {
@ -203,7 +216,8 @@ module.exports = function (RED) {
var inputCallback = function (ipMsg) { var inputCallback = function (ipMsg) {
if (String(ipMsg.topic).search(/load/i) < 0 || isFinite(ipMsg.payload) === false) { if (String(ipMsg.topic).search(/load/i) < 0 || isFinite(ipMsg.payload) === false) {
node.totalActiveTime = 0; node.totalActiveTime = 0;
} else { }
else {
node.totalActiveTime = Number(ipMsg.payload); node.totalActiveTime = Number(ipMsg.payload);
} }
if (node.currentState === node.activeState) { if (node.currentState === node.activeState) {
@ -217,7 +231,8 @@ module.exports = function (RED) {
if (node.activeEdges[0] && node.activeEdges[1]) { if (node.activeEdges[0] && node.activeEdges[1]) {
msg = [{topic: node.topic}, {topic: node.topic}]; msg = [{topic: node.topic}, {topic: node.topic}];
msg[0].payload = node.currentState; msg[0].payload = node.currentState;
} else { }
else {
msg = [null, {topic: node.topic}]; msg = [null, {topic: node.topic}];
} }
msg[1].payload = node.totalActiveTime; msg[1].payload = node.totalActiveTime;
@ -246,12 +261,14 @@ module.exports = function (RED) {
node.emit("input", {}); node.emit("input", {});
}, 50); }, 50);
}); });
} else { }
else {
node.error("Unable to set " + pin + " as input: " + response); node.error("Unable to set " + pin + " as input: " + response);
} }
}); });
}); });
} else { }
else {
node.error("Unconfigured input pin"); node.error("Unconfigured input pin");
} }
} }
@ -286,10 +303,12 @@ module.exports = function (RED) {
node.interruptAttached = true; node.interruptAttached = true;
node.on("input", inputCallback); node.on("input", inputCallback);
node.intervalId = setInterval(timerCallback, node.updateInterval); node.intervalId = setInterval(timerCallback, node.updateInterval);
} else { }
else {
node.error("Failed to attach interrupt"); node.error("Failed to attach interrupt");
} }
} else { }
else {
node.pulseTime = [node.pulseTime[1], process.hrtime()]; node.pulseTime = [node.pulseTime[1], process.hrtime()];
node.pulseCount = node.pulseCount + 1; node.pulseCount = node.pulseCount + 1;
} }
@ -301,7 +320,8 @@ module.exports = function (RED) {
var inputCallback = function (msg) { var inputCallback = function (msg) {
if (String(msg.topic).search(/load/i) < 0 || isFinite(msg.payload) === false) { if (String(msg.topic).search(/load/i) < 0 || isFinite(msg.payload) === false) {
node.pulseCount = 0; node.pulseCount = 0;
} else { }
else {
node.pulseCount = Number(msg.payload); node.pulseCount = Number(msg.payload);
} }
}; };
@ -337,19 +357,22 @@ module.exports = function (RED) {
if (node.countType === "pulse") { if (node.countType === "pulse") {
// interruptType = bonescript.FALLING; <- doesn't work in v0.2.4 // interruptType = bonescript.FALLING; <- doesn't work in v0.2.4
interruptType = bonescript.RISING; interruptType = bonescript.RISING;
} else { }
else {
interruptType = bonescript.CHANGE; interruptType = bonescript.CHANGE;
} }
// Attempt to attach the required interrupt handler to the pin. If we succeed, // Attempt to attach the required interrupt handler to the pin. If we succeed,
// the input event and interval handlers will be installed by interruptCallback // the input event and interval handlers will be installed by interruptCallback
bonescript.attachInterrupt(node._pin, interruptType, interruptCallback) bonescript.attachInterrupt(node._pin, interruptType, interruptCallback)
}); });
} else { }
else {
node.error("Unable to set " + pin + " as input: " + response); node.error("Unable to set " + pin + " as input: " + response);
} }
}); });
}); });
} else { }
else {
node.error("Unconfigured input pin"); node.error("Unconfigured input pin");
} }
} }
@ -376,12 +399,15 @@ module.exports = function (RED) {
var newState; var newState;
if (node.toggle) { if (node.toggle) {
newState = node.currentState === 0 ? 1 : 0; newState = node.currentState === 0 ? 1 : 0;
} else { }
else {
if (isFinite(Number(msg.payload))) { if (isFinite(Number(msg.payload))) {
newState = Number(msg.payload) > 0.5; newState = Number(msg.payload) > 0.5;
} else if (msg.payload) { }
else if (msg.payload) {
newState = true; newState = true;
} else { }
else {
newState = false; newState = false;
} }
if (node.inverting) { if (node.inverting) {
@ -402,7 +428,8 @@ module.exports = function (RED) {
setPinMode(node._pin, bonescript.OUTPUT, function (response, pin) { setPinMode(node._pin, bonescript.OUTPUT, function (response, pin) {
if (response) { if (response) {
node.error("Unable to set " + pin + " as output: " + response.err); node.error("Unable to set " + pin + " as output: " + response.err);
} else { }
else {
node.on("input", inputCallback); node.on("input", inputCallback);
setTimeout(function () { setTimeout(function () {
bonescript.digitalWrite(node._pin, node.defaultState, function() {}); bonescript.digitalWrite(node._pin, node.defaultState, function() {});
@ -410,7 +437,8 @@ module.exports = function (RED) {
} }
}); });
}); });
} else { }
else {
node.error("Unconfigured output pin"); node.error("Unconfigured output pin");
} }
} }
@ -453,10 +481,12 @@ module.exports = function (RED) {
node.send({topic: node.topic, payload: node.pulseState}); node.send({topic: node.topic, payload: node.pulseState});
}); });
} }
} else { }
else {
if (node.pulseTimer !== null) { if (node.pulseTimer !== null) {
clearTimeout(node.pulseTimer); clearTimeout(node.pulseTimer);
} else { }
else {
bonescript.digitalWrite(node._pin, node.pulseState, function() { bonescript.digitalWrite(node._pin, node.pulseState, function() {
node.send({topic: node.topic, payload: node.pulseState}); node.send({topic: node.topic, payload: node.pulseState});
}); });
@ -484,12 +514,14 @@ module.exports = function (RED) {
node.on("input", inputCallback); node.on("input", inputCallback);
// Set the pin to the default state once the dust settles // Set the pin to the default state once the dust settles
setTimeout(endPulseCallback, 50); setTimeout(endPulseCallback, 50);
} else { }
else {
node.error("Unable to set " + pin + " as output: " + response.err); node.error("Unable to set " + pin + " as output: " + response.err);
} }
}); });
}); });
} else { }
else {
node.error("Unconfigured output pin"); node.error("Unconfigured output pin");
} }
} }

View File

@ -1,9 +1,9 @@
{ {
"name" : "node-red-node-beaglebone", "name" : "node-red-node-beaglebone",
"version" : "0.1.8", "version" : "0.1.9",
"description" : "A set of Node-RED nodes to interface to the GPIO pins of a Beaglebone Black board", "description" : "A set of Node-RED nodes to interface to the GPIO pins of a Beaglebone Black board",
"dependencies" : { "dependencies" : {
"octalbonescript":"^1.2.*" "octalbonescript":"^1.2.2"
}, },
"repository" : { "repository" : {
"type":"git", "type":"git",

View File

@ -12,7 +12,8 @@ module.exports = function(RED) {
try { try {
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString(); var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
if (cpuinfo.indexOf(": BCM") === -1) { throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); } if (cpuinfo.indexOf(": BCM") === -1) { throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); }
} catch(err) { }
catch(err) {
throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); throw "Info : "+RED._("rpi-gpio.errors.ignorenode");
} }

View File

@ -164,10 +164,12 @@ module.exports = function(RED) {
if (node.pin !== undefined) { if (node.pin !== undefined) {
if (node.pin === "12") { if (node.pin === "12") {
node.child = spawn(gpioCommand, ["buzz",node.pin]); node.child = spawn(gpioCommand, ["buzz",node.pin]);
} else { }
else {
if (node.set && (node.out === "out")) { if (node.set && (node.out === "out")) {
node.child = spawn(gpioCommand, [node.out,node.pin,node.level]); node.child = spawn(gpioCommand, [node.out,node.pin,node.level]);
} else { }
else {
node.child = spawn(gpioCommand, [node.out,node.pin]); node.child = spawn(gpioCommand, [node.out,node.pin]);
} }
} }

View File

@ -32,7 +32,7 @@ module.exports = function(RED) {
return typeof (value) === "undefined" || value === null ? value = defaultValue : value; return typeof (value) === "undefined" || value === null ? value = defaultValue : value;
} }
function validateArray(value, defaultValue){ function validateArray(value, defaultValue) {
return typeof (value) === "undefined" || Array.isArray(value) ? value : defaultValue; return typeof (value) === "undefined" || Array.isArray(value) ? value : defaultValue;
} }
@ -66,7 +66,7 @@ module.exports = function(RED) {
this.name = n.name; this.name = n.name;
this.serial = n.serial; this.serial = n.serial;
this.mode = n.mode || "normal"; this.mode = n.mode || "normal";
this.task = n.task || "set_color"; this.task = n.task || "set_color";
this.delay = n.delay || 500; this.delay = n.delay || 500;
this.repeats = n.repeats || 1; this.repeats = n.repeats || 1;
@ -95,25 +95,28 @@ module.exports = function(RED) {
if (Object.size(node.led) === 0) { if (Object.size(node.led) === 0) {
node.status({fill:"red",shape:"ring",text:"not found"}); node.status({fill:"red",shape:"ring",text:"not found"});
node.error("BlinkStick with serial number " + node.serial + " not found"); node.error("BlinkStick with serial number " + node.serial + " not found");
} else { }
else {
node.status({fill:"green",shape:"dot",text:"connected"}); node.status({fill:"green",shape:"dot",text:"connected"});
if(node.mode == "normal"){node.led.setMode(0);} if (node.mode == "normal") {node.led.setMode(0);}
else if(node.mode == "inverted"){node.led.setMode(1);} else if (node.mode == "inverted") {node.led.setMode(1);}
else if(node.mode == "neopixel"){node.led.setMode(2);} else if (node.mode == "neopixel") {node.led.setMode(2);}
if (callback) { callback(); } if (callback) { callback(); }
} }
}); });
} else { }
else {
node.led = blinkstick.findFirst(); node.led = blinkstick.findFirst();
if (Object.size(node.led) === 0) { if (Object.size(node.led) === 0) {
node.status({fill:"red",shape:"ring",text:"not found"}); node.status({fill:"red",shape:"ring",text:"not found"});
node.error("No BlinkStick found"); node.error("No BlinkStick found");
} else { }
else {
node.status({fill:"green",shape:"dot",text:"connected"}); node.status({fill:"green",shape:"dot",text:"connected"});
if(node.mode == "normal"){node.led.setMode(0);} if (node.mode == "normal") {node.led.setMode(0);}
else if(node.mode == "inverted"){node.led.setMode(1);} else if (node.mode == "inverted") {node.led.setMode(1);}
else if(node.mode == "neopixel"){node.led.setMode(2);} else if (node.mode == "neopixel") {node.led.setMode(2);}
if (callback) { callback(); } if (callback) { callback(); }
} }
} }
@ -159,12 +162,15 @@ module.exports = function(RED) {
//Select animation to perform //Select animation to perform
if (node.task == "pulse") { if (node.task == "pulse") {
node.led.pulse(node.color, {'duration': node.duration, 'steps': node.steps, 'channel': node.channel, 'index': node.index }, blinkstickAnimationComplete); node.led.pulse(node.color, {'duration': node.duration, 'steps': node.steps, 'channel': node.channel, 'index': node.index }, blinkstickAnimationComplete);
} else if (node.task == "morph") { }
else if (node.task == "morph") {
node.led.morph(node.color, {'duration': node.duration, 'steps': node.steps, 'channel': node.channel, 'index': node.index }, blinkstickAnimationComplete); node.led.morph(node.color, {'duration': node.duration, 'steps': node.steps, 'channel': node.channel, 'index': node.index }, blinkstickAnimationComplete);
} else if (node.task == "blink") { }
else if (node.task == "blink") {
node.led.blink(node.color,{'repeats': node.repeats, 'delay': node.delay, 'channel': node.channel, 'index': node.index }, blinkstickAnimationComplete); node.led.blink(node.color,{'repeats': node.repeats, 'delay': node.delay, 'channel': node.channel, 'index': node.index }, blinkstickAnimationComplete);
} else { }
if(node.row.length > 0){ else {
if (node.row.length > 0) {
var dat = []; var dat = [];
for (var i = 0; i < node.row.length; i++) { for (var i = 0; i < node.row.length; i++) {
if (typeof node.row[i] === "string") { // if string then assume must be colour names if (typeof node.row[i] === "string") { // if string then assume must be colour names
@ -187,14 +193,15 @@ module.exports = function(RED) {
node.led.setColors(node.channel, dat, blinkstickAnimationComplete); node.led.setColors(node.channel, dat, blinkstickAnimationComplete);
} }
else { else {
node.warn("Colour array length not / 3"); node.warn("Colour array length not / 3");
} }
} }
else { else {
node.led.setColor(node.color, {'channel': node.channel, 'index': node.index}, blinkstickAnimationComplete); node.led.setColor(node.color, {'channel': node.channel, 'index': node.index}, blinkstickAnimationComplete);
} }
} }
} catch (err) { }
catch (err) {
if (err.toString().indexOf("setColor") !== -1) { if (err.toString().indexOf("setColor") !== -1) {
node.led.setColour(node.color, blinkstickAnimationComplete); node.led.setColour(node.color, blinkstickAnimationComplete);
node.warn("Old version - please upgrade Blinkstick npm"); node.warn("Old version - please upgrade Blinkstick npm");
@ -269,19 +276,22 @@ module.exports = function(RED) {
node.channel = typeof(data.channel) !== 'undefined' ? data.channel : node.channel; node.channel = typeof(data.channel) !== 'undefined' ? data.channel : node.channel;
node.index = data.index ? data.index : node.index; node.index = data.index ? data.index : node.index;
node.row = data.row ? data.row : node.row; node.row = data.row ? data.row : node.row;
} else { }
else {
node.error(data); node.error(data);
return; return;
} }
} }
} else if (p1.test(msg.payload)) { }
else if (p1.test(msg.payload)) {
//Color value is represented as "red,green,blue" string of bytes //Color value is represented as "red,green,blue" string of bytes
var rgb = msg.payload.split(","); var rgb = msg.payload.split(",");
//Convert color value back to HEX string for easier implementation //Convert color value back to HEX string for easier implementation
node.color = "#" + decimalToHex(parseInt(rgb[0])&255) + node.color = "#" + decimalToHex(parseInt(rgb[0])&255) +
decimalToHex(parseInt(rgb[1])&255) + decimalToHex(parseInt(rgb[2])&255); decimalToHex(parseInt(rgb[1])&255) + decimalToHex(parseInt(rgb[2])&255);
} else { }
else {
//Sanitize color value //Sanitize color value
node.color = msg.payload.toLowerCase().replace(/\s+/g,''); node.color = msg.payload.toLowerCase().replace(/\s+/g,'');
if (node.color === "amber") { node.color = "#FFBF00"; } if (node.color === "amber") { node.color = "#FFBF00"; }
@ -293,7 +303,8 @@ module.exports = function(RED) {
if (animationComplete) { if (animationComplete) {
applyColor(); applyColor();
} }
} else { }
else {
//Attempt to find BlinkStick and start animation if it's found //Attempt to find BlinkStick and start animation if it's found
findBlinkStick(function() { findBlinkStick(function() {
if (animationComplete) { if (animationComplete) {

View File

@ -16,7 +16,8 @@ module.exports = function(RED) {
try { try {
device = new HID.HID(devices[i].path); device = new HID.HID(devices[i].path);
break; break;
} catch (e) { }
catch (e) {
node.log(e) node.log(e)
} }
} }
@ -32,16 +33,19 @@ module.exports = function(RED) {
var g = parseInt(msg.payload.slice(3,5),16); var g = parseInt(msg.payload.slice(3,5),16);
var b = parseInt(msg.payload.slice(5),16); var b = parseInt(msg.payload.slice(5),16);
device.sendFeatureReport([115,r,g,b]); device.sendFeatureReport([115,r,g,b]);
} else if (p2.test(msg.payload)) { }
else if (p2.test(msg.payload)) {
var args = msg.payload.split(','); var args = msg.payload.split(',');
if (args.length == 3) { if (args.length == 3) {
device.sendFeatureReport([115,parseInt(args[0]),parseInt(args[1]),parseInt(args[2])]); device.sendFeatureReport([115,parseInt(args[0]),parseInt(args[1]),parseInt(args[2])]);
} }
} else { }
else {
node.warn("incompatable input - " + msg.payload); node.warn("incompatable input - " + msg.payload);
} }
}); });
} else { }
else {
node.warn("no digispark RGB found"); node.warn("no digispark RGB found");
} }

View File

@ -16,31 +16,37 @@ module.exports = function(RED) {
var g = node.x.read(); var g = node.x.read();
var msg = { payload:g, topic:node.board+"/D"+node.pin }; var msg = { payload:g, topic:node.board+"/D"+node.pin };
switch (g) { switch (g) {
case 0: case 0: {
node.status({fill:"green",shape:"ring",text:"low"}); node.status({fill:"green",shape:"ring",text:"low"});
if (node.interrupt=== "f" || node.interrupt === "b") { if (node.interrupt=== "f" || node.interrupt === "b") {
node.send(msg); node.send(msg);
} }
break; break;
case 1: }
case 1: {
node.status({fill:"green",shape:"dot",text:"high"}); node.status({fill:"green",shape:"dot",text:"high"});
if (node.interrupt=== "r" || node.interrupt === "b") { if (node.interrupt=== "r" || node.interrupt === "b") {
node.send(msg); node.send(msg);
} }
break; break;
default: }
default: {
node.status({fill:"grey",shape:"ring",text:"unknown"}); node.status({fill:"grey",shape:"ring",text:"unknown"});
}
} }
}); });
switch (node.x.read()) { switch (node.x.read()) {
case 0: case 0: {
node.status({fill:"green",shape:"ring",text:"low"}); node.status({fill:"green",shape:"ring",text:"low"});
break; break;
case 1: }
case 1: {
node.status({fill:"green",shape:"dot",text:"high"}); node.status({fill:"green",shape:"dot",text:"high"});
break; break;
default: }
default: {
node.status({}); node.status({});
}
} }
this.on('close', function() { this.on('close', function() {
node.x.isr(m.EDGE_BOTH, null); node.x.isr(m.EDGE_BOTH, null);

View File

@ -10,7 +10,8 @@ module.exports = function(RED) {
var node = this; var node = this;
if (node.pin === 14) { if (node.pin === 14) {
node.p = new m.Gpio(3,false,true); // special for onboard LED v1 node.p = new m.Gpio(3,false,true); // special for onboard LED v1
} else { }
else {
node.p = new m.Gpio(node.pin); node.p = new m.Gpio(node.pin);
} }
node.p.mode(m.PIN_GPIO); node.p.mode(m.PIN_GPIO);
@ -21,7 +22,8 @@ module.exports = function(RED) {
node.on("input", function(msg) { node.on("input", function(msg) {
if (msg.payload == "1") { if (msg.payload == "1") {
node.p.write(1); node.p.write(1);
} else { }
else {
node.p.write(0); node.p.write(0);
} }
}); });

View File

@ -56,7 +56,8 @@ module.exports = function(RED) {
} }
else { console.log(key); } else { console.log(key); }
}); });
} catch(err) { node.warn("can't open MakeyMakey: Do you need root access ?"); } }
catch(err) { node.warn("can't open MakeyMakey: Do you need root access ?"); }
} }
else { else {
findmakey(); findmakey();

View File

@ -6,7 +6,8 @@ module.exports = function(RED) {
try { try {
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString(); var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
if (cpuinfo.indexOf(": BCM") === -1) { throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); } if (cpuinfo.indexOf(": BCM") === -1) { throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); }
} catch(err) { }
catch(err) {
throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); throw "Info : "+RED._("rpi-gpio.errors.ignorenode");
} }

View File

@ -10,7 +10,8 @@ module.exports = function(RED) {
try { try {
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString(); var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
if (cpuinfo.indexOf(": BCM") === -1) { throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); } if (cpuinfo.indexOf(": BCM") === -1) { throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); }
} catch(err) { }
catch(err) {
throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); throw "Info : "+RED._("rpi-gpio.errors.ignorenode");
} }
@ -57,7 +58,8 @@ module.exports = function(RED) {
if (node.mode.indexOf("need") >= 0) { if (node.mode.indexOf("need") >= 0) {
needle = colors.getRGB(parts[0],node.rgb); needle = colors.getRGB(parts[0],node.rgb);
pay = "0,"+(l-1)+","+node.fgnd+"\n"+l+","+needle+"\n"+(l+1)+","+(node.pixels-1)+","+node.bgnd; pay = "0,"+(l-1)+","+node.fgnd+"\n"+l+","+needle+"\n"+(l+1)+","+(node.pixels-1)+","+node.bgnd;
} else { }
else {
node.fgnd = colors.getRGB(parts[0],node.rgb); node.fgnd = colors.getRGB(parts[0],node.rgb);
pay = "0,"+l+","+node.fgnd+"\n"+(l+1)+","+(node.pixels-1)+","+node.bgnd; pay = "0,"+l+","+node.fgnd+"\n"+(l+1)+","+(node.pixels-1)+","+node.bgnd;
} }
@ -78,7 +80,8 @@ module.exports = function(RED) {
ll = ll - 1; ll = ll - 1;
if (node.mode.indexOf("need") >= 0) { if (node.mode.indexOf("need") >= 0) {
pay = "0,"+(ll-1)+","+node.fgnd+"\n"+ll+","+needle+"\n"+(ll+1)+","+(node.pixels-1)+","+node.bgnd; pay = "0,"+(ll-1)+","+node.fgnd+"\n"+ll+","+needle+"\n"+(ll+1)+","+(node.pixels-1)+","+node.bgnd;
} else { }
else {
pay = "0,"+ll+","+node.fgnd+"\n"+(ll+1)+","+(node.pixels-1)+","+node.bgnd; pay = "0,"+ll+","+node.fgnd+"\n"+(ll+1)+","+(node.pixels-1)+","+node.bgnd;
} }
} }

View File

@ -7,42 +7,49 @@ module.exports = function(RED) {
var checkLength = function(text) { var checkLength = function(text) {
var l = text.length; var l = text.length;
switch(true) { switch (true) {
case /^http:\/\/www./.test(text): case /^http:\/\/www./.test(text): {
l -= 10; l -= 10;
break; break;
case /^https:\/\/www./.test(text): }
l -= 11; case /^https:\/\/www./.test(text): {
break; l -= 11;
case /^http:\/\//.test(text): break;
l -= 6; }
break; case /^http:\/\//.test(text): {
case /^https:\/\//.test(text): l -= 6;
l -= 7; break;
break; }
case /^https:\/\//.test(text): {
l -= 7;
break;
}
} }
switch(true) { switch (true) {
case /.*\.info\/.*/.test(text): case /.*\.info\/.*/.test(text): {
l -= 5; l -= 5;
break; break;
}
case /.*\.com\/.*/.test(text): case /.*\.com\/.*/.test(text):
case /.*\.net\/.*/.test(text): case /.*\.net\/.*/.test(text):
case /.*\.org\/.*/.test(text): case /.*\.org\/.*/.test(text):
case /.*\.edu\/.*/.test(text): case /.*\.edu\/.*/.test(text):
case /.*\.biz\/.*/.test(text): case /.*\.biz\/.*/.test(text):
case /.*\.gov\/.*/.test(text): case /.*\.gov\/.*/.test(text):
case /.*\.info.*/.test(text): case /.*\.info.*/.test(text): {
l -= 4; l -= 4;
break; break;
}
case /.*\.com.*/.test(text): case /.*\.com.*/.test(text):
case /.*\.net.*/.test(text): case /.*\.net.*/.test(text):
case /.*\.org.*/.test(text): case /.*\.org.*/.test(text):
case /.*\.edu.*/.test(text): case /.*\.edu.*/.test(text):
case /.*\.biz.*/.test(text): case /.*\.biz.*/.test(text):
case /.*\.gov.*/.test(text): case /.*\.gov.*/.test(text): {
l -= 3; l -= 3;
break; break;
}
} }
return l; return l;
} }
@ -70,7 +77,8 @@ module.exports = function(RED) {
try { try {
eddystoneBeacon.advertiseUrl(node.url, node.options); eddystoneBeacon.advertiseUrl(node.url, node.options);
node.status({fill:"green",shape:"dot",text:node.url}); node.status({fill:"green",shape:"dot",text:node.url});
} catch(e) { }
catch(e) {
node.error('Error setting beacon URL', e); node.error('Error setting beacon URL', e);
} }
} }
@ -83,7 +91,8 @@ module.exports = function(RED) {
try { try {
eddystoneBeacon.advertiseUid(node.namespace, node.instance, node.options); eddystoneBeacon.advertiseUid(node.namespace, node.instance, node.options);
node.status({fill:"green",shape:"dot",text:node.namespace}); node.status({fill:"green",shape:"dot",text:node.namespace});
} catch(e) { }
catch(e) {
node.error('Error setting beacon information', e); node.error('Error setting beacon information', e);
} }
} }
@ -96,7 +105,8 @@ module.exports = function(RED) {
try { try {
eddystoneBeacon.stop(); eddystoneBeacon.stop();
node.status({fill:"red",shape:"dot",text:"Stopped"}); node.status({fill:"red",shape:"dot",text:"Stopped"});
} catch(e) { }
catch(e) {
node.error('error shutting down beacon', e); node.error('error shutting down beacon', e);
} }
return; return;
@ -107,7 +117,8 @@ module.exports = function(RED) {
try { try {
eddystoneBeacon.advertiseUrl(node.url, node.options); eddystoneBeacon.advertiseUrl(node.url, node.options);
node.status({fill:"green",shape:"dot",text:node.url}); node.status({fill:"green",shape:"dot",text:node.url});
} catch(e) { }
catch(e) {
node.error('Error setting beacon URL', e); node.error('Error setting beacon URL', e);
} }
return; return;
@ -116,7 +127,8 @@ module.exports = function(RED) {
try { try {
eddystoneBeacon.advertiseUid(node.namespace, node.instance, node.options); eddystoneBeacon.advertiseUid(node.namespace, node.instance, node.options);
node.status({fill:"green",shape:"dot",text:node.namespace}); node.status({fill:"green",shape:"dot",text:node.namespace});
} catch(e) { }
catch(e) {
node.error('Error setting beacon information', e); node.error('Error setting beacon information', e);
} }
return; return;
@ -124,30 +136,33 @@ module.exports = function(RED) {
} }
// url mode // url mode
if (node.mode === "url") { if (node.mode === "url") {
if (checkLength(msg.payload) <= 18) { if (checkLength(msg.payload) <= 18) {
try { try {
node.url = msg.payload; node.url = msg.payload;
eddystoneBeacon.advertiseUrl(node.url, node.options); eddystoneBeacon.advertiseUrl(node.url, node.options);
node.status({fill:"green",shape:"dot",text:node.url}); node.status({fill:"green",shape:"dot",text:node.url});
} catch(e) { }
node.status({fill:"red",shape:"dot",text:"Error setting URL"}); catch(e) {
node.error('error updating beacon URL', e); node.status({fill:"red",shape:"dot",text:"Error setting URL"});
} node.error('error updating beacon URL', e);
} else { }
node.status({fill:"red",shape:"dot",text:"URL too long"}); }
} else {
node.status({fill:"red",shape:"dot",text:"URL too long"});
}
} }
// uid mode // uid mode
else { else {
try { try {
node.namespace = msg.payload; node.namespace = msg.payload;
node.instance = msg.topic; node.instance = msg.topic;
eddystoneBeacon.advertiseUid(node.namespace, node.instance, node.options); eddystoneBeacon.advertiseUid(node.namespace, node.instance, node.options);
node.status({fill:"green",shape:"dot",text:msg.payload}); node.status({fill:"green",shape:"dot",text:msg.payload});
} catch(e) { }
node.status({fill:"red",shape:"dot",text:"Error setting beacon information"}); catch(e) {
node.error('Error setting beacon information', e); node.status({fill:"red",shape:"dot",text:"Error setting beacon information"});
} node.error('Error setting beacon information', e);
}
} }
}); });
@ -157,7 +172,8 @@ module.exports = function(RED) {
node.status({}); node.status({});
eddystoneBeacon.stop(); eddystoneBeacon.stop();
done(); done();
} catch(e) { }
catch(e) {
node.error('error shutting down beacon', e); node.error('error shutting down beacon', e);
} }
}); });

View File

@ -100,7 +100,8 @@ module.exports = function(RED) {
},node.uuid); },node.uuid);
} }
},15000); },15000);
} else { }
else {
console.log("reconfig",node.uuid); console.log("reconfig",node.uuid);
enable(node); enable(node);
} }
@ -114,46 +115,54 @@ module.exports = function(RED) {
var enable = function(node) { var enable = function(node) {
if (node.temperature) { if (node.temperature) {
node.stag.notifyIrTemperature(function() {}); node.stag.notifyIrTemperature(function() {});
} else { }
else {
node.stag.unnotifyIrTemperature(function() {}); node.stag.unnotifyIrTemperature(function() {});
} }
if (node.pressure) { if (node.pressure) {
node.stag.notifyBarometricPressure(function() {}); node.stag.notifyBarometricPressure(function() {});
} else { }
else {
node.stag.unnotifyBarometricPressure(function() {}); node.stag.unnotifyBarometricPressure(function() {});
} }
if (node.humidity) { if (node.humidity) {
node.stag.notifyHumidity(function() {}); node.stag.notifyHumidity(function() {});
} else { }
else {
node.stag.unnotifyHumidity(function() {}); node.stag.unnotifyHumidity(function() {});
} }
if (node.accelerometer) { if (node.accelerometer) {
node.stag.notifyAccelerometer(function() {}); node.stag.notifyAccelerometer(function() {});
} else { }
else {
node.stag.unnotifyAccelerometer(function() {}); node.stag.unnotifyAccelerometer(function() {});
} }
if (node.magnetometer) { if (node.magnetometer) {
node.stag.notifyMagnetometer(function() {}); node.stag.notifyMagnetometer(function() {});
} else { }
else {
node.stag.unnotifyMagnetometer(function() {}); node.stag.unnotifyMagnetometer(function() {});
} }
if (node.gyroscope) { if (node.gyroscope) {
node.stag.notifyGyroscope(function() {}); node.stag.notifyGyroscope(function() {});
} else { }
else {
node.stag.unnotifyGyroscope(function() {}); node.stag.unnotifyGyroscope(function() {});
} }
if (node.stag.type === "cc2650") { if (node.stag.type === "cc2650") {
if (node.luxometer) { if (node.luxometer) {
node.stag.enableLuxometer(function() {}); node.stag.enableLuxometer(function() {});
node.stag.notifyLuxometer(function() {}); node.stag.notifyLuxometer(function() {});
} else { }
else {
node.stag.unnotifyLuxometer(function() {}); node.stag.unnotifyLuxometer(function() {});
node.stag.disableLuxometer(function() {}); node.stag.disableLuxometer(function() {});
} }
} }
if (node.keys) { if (node.keys) {
node.stag.notifySimpleKey(function() {}); node.stag.notifySimpleKey(function() {});
} else { }
else {
node.stag.unnotifySimpleKey(function() {}); node.stag.unnotifySimpleKey(function() {});
} }
} }

View File

@ -48,7 +48,8 @@ module.exports = function(RED) {
delete subscriptions[dev]; delete subscriptions[dev];
delete sub2dev[sub.sid]; delete sub2dev[sub.sid];
subscribe({dev: subs[s]}); subscribe({dev: subs[s]});
} else { }
else {
// console.log("resubscription good %s", res.statusCode); // console.log("resubscription good %s", res.statusCode);
// console.log("dev - %s", util.inspect(dev)); // console.log("dev - %s", util.inspect(dev));
} }
@ -78,7 +79,8 @@ module.exports = function(RED) {
if (subscriptions[dev]) { if (subscriptions[dev]) {
//exists //exists
subscriptions[dev].count++; subscriptions[dev].count++;
} else { }
else {
//new //new
var ipAddr; var ipAddr;
@ -97,7 +99,8 @@ module.exports = function(RED) {
break; break;
} }
} }
} else { }
else {
//node 0.10 not great but best we can do //node 0.10 not great but best we can do
if (!addrs[add].internal && addrs[add].family == 'IPv4') { if (!addrs[add].internal && addrs[add].family == 'IPv4') {
ipAddr = addrs[add].address; ipAddr = addrs[add].address;
@ -143,7 +146,8 @@ module.exports = function(RED) {
if (res.statusCode == 200) { if (res.statusCode == 200) {
subscriptions[dev] = {'count': 1, 'sid': res.headers.sid}; subscriptions[dev] = {'count': 1, 'sid': res.headers.sid};
sub2dev[res.headers.sid] = dev; sub2dev[res.headers.sid] = dev;
} else { }
else {
console.log('failed to subsrcibe'); console.log('failed to subsrcibe');
} }
}); });
@ -181,10 +185,12 @@ module.exports = function(RED) {
unSubreq.end(); unSubreq.end();
} else { }
else {
subscriptions[dev].count--; subscriptions[dev].count--;
} }
} else { }
else {
//shouldn't ever get here //shouldn't ever get here
} }
} }
@ -210,7 +216,8 @@ module.exports = function(RED) {
node.status({fill: 'green',shape: 'dot',text: 'found'}); node.status({fill: 'green',shape: 'dot',text: 'found'});
} }
}); });
} else { }
else {
node.status({fill: 'green',shape: 'dot',text: 'found'}); node.status({fill: 'green',shape: 'dot',text: 'found'});
} }
@ -227,27 +234,32 @@ module.exports = function(RED) {
if (typeof msg.payload === 'string') { if (typeof msg.payload === 'string') {
if (msg.payload == 'on' || msg.payload == '1' || msg.payload == 'true') { if (msg.payload == 'on' || msg.payload == '1' || msg.payload == 'true') {
on = 1; on = 1;
} else if (msg.payload === 'toggle') { }
else if (msg.payload === 'toggle') {
on = 2; on = 2;
} }
} else if (typeof msg.payload === 'number') { }
else if (typeof msg.payload === 'number') {
if (msg.payload >= 0 && msg.payload < 3) { if (msg.payload >= 0 && msg.payload < 3) {
on = msg.payload; on = msg.payload;
} }
} else if (typeof msg.payload === 'object') { }
else if (typeof msg.payload === 'object') {
//object need to get complicated here //object need to get complicated here
if (msg.payload.state && typeof msg.payload.state === 'number') { if (msg.payload.state && typeof msg.payload.state === 'number') {
if (dev.type === 'socket') { if (dev.type === 'socket') {
if (msg.payload >= 0 && msg.payload < 2) { if (msg.payload >= 0 && msg.payload < 2) {
on = msg.payload.state; on = msg.payload.state;
} }
} else if (dev.type === 'light' || dev.type === 'group') { }
else if (dev.type === 'light' || dev.type === 'group') {
if (msg.payload >= 0 && msg.payload < 3) { if (msg.payload >= 0 && msg.payload < 3) {
on = msg.payload.state; on = msg.payload.state;
} }
} }
} }
} else if (typeof msg.payload === 'boolean') { }
else if (typeof msg.payload === 'boolean') {
if (msg.payload) { if (msg.payload) {
on = 1; on = 1;
} }
@ -256,10 +268,12 @@ module.exports = function(RED) {
if (dev.type === 'socket') { if (dev.type === 'socket') {
//console.log("socket"); //console.log("socket");
wemo.toggleSocket(dev, on); wemo.toggleSocket(dev, on);
} else if (dev.type === 'light`') { }
else if (dev.type === 'light`') {
//console.log("light"); //console.log("light");
wemo.setStatus(dev,'10006', on); wemo.setStatus(dev,'10006', on);
} else { }
else {
console.log('group'); console.log('group');
wemo.setStatus(dev, '10006', on); wemo.setStatus(dev, '10006', on);
} }
@ -295,17 +309,18 @@ module.exports = function(RED) {
switch (notification.type){ switch (notification.type){
case 'light': case 'light':
case 'group': case 'group': {
if (dd.id === notification.id) { if (dd.id === notification.id) {
node.send(msg); node.send(msg);
} }
break; break;
case 'socket': }
case 'socket': {
node.send(msg); node.send(msg);
break; break;
default: }
default: {}
} }
} }
}; };
@ -316,7 +331,8 @@ module.exports = function(RED) {
if (wemo.get(node.dev)) { if (wemo.get(node.dev)) {
node.status({fill: 'green',shape: 'dot',text: 'found'}); node.status({fill: 'green',shape: 'dot',text: 'found'});
subscribe(node); subscribe(node);
} else { }
else {
wemo.on('discovered', function(d) { wemo.on('discovered', function(d) {
if (node.dev === d) { if (node.dev === d) {
node.status({fill: 'green',shape: 'dot',text: 'found'}); node.status({fill: 'green',shape: 'dot',text: 'found'});
@ -324,7 +340,8 @@ module.exports = function(RED) {
} }
}); });
} }
} else if (node.ipaddr) { }
else if (node.ipaddr) {
//legacy //legacy
var devices = Object.keys(wemo.devices); var devices = Object.keys(wemo.devices);
for (var d in devices) { for (var d in devices) {

View File

@ -34,7 +34,8 @@ module.exports = function(RED) {
else { else {
if (msg.payload.indexOf(':') > -1) { if (msg.payload.indexOf(':') > -1) {
this.url += 'json={' + msg.payload + '}'; this.url += 'json={' + msg.payload + '}';
} else { }
else {
this.url += 'csv='+msg.payload; this.url += 'csv='+msg.payload;
} }
} }
@ -96,7 +97,8 @@ module.exports = function(RED) {
if (msg.rc === 200) { if (msg.rc === 200) {
try { try {
msg.payload = JSON.parse(msg.payload); msg.payload = JSON.parse(msg.payload);
} catch(err) { }
catch(err) {
// Failed to parse, pass it on // Failed to parse, pass it on
} }
node.send(msg); node.send(msg);

View File

@ -22,7 +22,8 @@ module.exports = function(RED) {
this.client = mqlight.createClient(opts, function(err) { this.client = mqlight.createClient(opts, function(err) {
if (err) { if (err) {
util.log('[mqlight] ['+id+'] not connected to service '+n.service); util.log('[mqlight] ['+id+'] not connected to service '+n.service);
} else { }
else {
util.log('[mqlight] ['+id+'] connected to service '+n.service); util.log('[mqlight] ['+id+'] connected to service '+n.service);
} }
}); });
@ -72,13 +73,15 @@ module.exports = function(RED) {
var subscribeCallback = function(err) { var subscribeCallback = function(err) {
if (err) { if (err) {
node.error("Failed to subscribe: " + err); node.error("Failed to subscribe: " + err);
} else { }
else {
node.log("Subscribed to "+node.topic+(node.share?" ["+node.share+"]":"")); node.log("Subscribed to "+node.topic+(node.share?" ["+node.share+"]":""));
} }
}; };
if (node.share) { if (node.share) {
recvClient.subscribe(node.topic, node.share, subscribeCallback); recvClient.subscribe(node.topic, node.share, subscribeCallback);
} else { }
else {
recvClient.subscribe(node.topic, subscribeCallback); recvClient.subscribe(node.topic, subscribeCallback);
} }
}); });
@ -113,7 +116,8 @@ module.exports = function(RED) {
if (topic === "") { if (topic === "") {
if (msg.topic) { if (msg.topic) {
topic = msg.topic; topic = msg.topic;
} else { }
else {
node.warn("No topic set in MQ Light out node"); node.warn("No topic set in MQ Light out node");
return; return;
} }

View File

@ -45,11 +45,13 @@ module.exports = function(RED) {
if (!Buffer.isBuffer(payload)) { if (!Buffer.isBuffer(payload)) {
if (typeof payload === "object") { if (typeof payload === "object") {
payload = JSON.stringify(payload); payload = JSON.stringify(payload);
} else { }
else {
payload = payload.toString(); payload = payload.toString();
} }
payload += node.addCh; payload += node.addCh;
} else if (node.addCh !== "") { }
else if (node.addCh !== "") {
payload = Buffer.concat([payload,new Buffer(node.addCh)]); payload = Buffer.concat([payload,new Buffer(node.addCh)]);
} }
node.port.write(payload,function(err,res) { node.port.write(payload,function(err,res) {
@ -66,14 +68,16 @@ module.exports = function(RED) {
node.port.on('closed', function() { node.port.on('closed', function() {
node.status({fill:"red",shape:"ring",text:"node-red:common.status.not-connected"}); node.status({fill:"red",shape:"ring",text:"node-red:common.status.not-connected"});
}); });
} else { }
else {
this.error(RED._("serial.errors.missing-conf")); this.error(RED._("serial.errors.missing-conf"));
} }
this.on("close", function(done) { this.on("close", function(done) {
if (this.serialConfig) { if (this.serialConfig) {
serialPool.close(this.serialConfig.serialport,done); serialPool.close(this.serialConfig.serialport,done);
} else { }
else {
done(); done();
} }
}); });
@ -105,7 +109,8 @@ module.exports = function(RED) {
var splitc; var splitc;
if (node.serialConfig.newline.substr(0,2) == "0x") { if (node.serialConfig.newline.substr(0,2) == "0x") {
splitc = new Buffer([parseInt(node.serialConfig.newline)]); splitc = new Buffer([parseInt(node.serialConfig.newline)]);
} else { }
else {
splitc = new Buffer(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0")); // jshint ignore:line splitc = new Buffer(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0")); // jshint ignore:line
} }
@ -169,14 +174,16 @@ module.exports = function(RED) {
this.port.on('closed', function() { this.port.on('closed', function() {
node.status({fill:"red",shape:"ring",text:"node-red:common.status.not-connected"}); node.status({fill:"red",shape:"ring",text:"node-red:common.status.not-connected"});
}); });
} else { }
else {
this.error(RED._("serial.errors.missing-conf")); this.error(RED._("serial.errors.missing-conf"));
} }
this.on("close", function(done) { this.on("close", function(done) {
if (this.serialConfig) { if (this.serialConfig) {
serialPool.close(this.serialConfig.serialport,done); serialPool.close(this.serialConfig.serialport,done);
} else { }
else {
done(); done();
} }
}); });
@ -273,7 +280,8 @@ module.exports = function(RED) {
} }
catch(err) { } catch(err) { }
delete connections[port]; delete connections[port];
} else { }
else {
done(); done();
} }
} }

View File

@ -18,7 +18,8 @@ module.exports = function(RED) {
node.session.get(oids.split(","), function(error, varbinds) { node.session.get(oids.split(","), function(error, varbinds) {
if (error) { if (error) {
node.error(error.toString(),msg); node.error(error.toString(),msg);
} else { }
else {
for (var i = 0; i < varbinds.length; i++) { for (var i = 0; i < varbinds.length; i++) {
if (snmp.isVarbindError(varbinds[i])) { if (snmp.isVarbindError(varbinds[i])) {
node.error(snmp.varbindError(varbinds[i]),msg); node.error(snmp.varbindError(varbinds[i]),msg);
@ -62,7 +63,8 @@ module.exports = function(RED) {
function responseCb(error, table) { function responseCb(error, table) {
if (error) { if (error) {
console.error(error.toString()); console.error(error.toString());
} else { }
else {
var indexes = []; var indexes = [];
for (var index in table) { for (var index in table) {
if (table.hasOwnProperty(index)) { if (table.hasOwnProperty(index)) {

View File

@ -41,7 +41,7 @@ module.exports = function(RED) {
} }
}; };
if (this.serverConfig.vhost) { if (this.serverConfig.vhost) {
this.stompClientOpts.vhost = this.serverConfig.vhost; this.stompClientOpts.vhost = this.serverConfig.vhost;
} }
var node = this; var node = this;
@ -49,7 +49,7 @@ module.exports = function(RED) {
node.client = new StompClient(node.stompClientOpts); node.client = new StompClient(node.stompClientOpts);
node.client.on("connect", function() { node.client.on("connect", function() {
node.status({fill:"green",shape:"dot",text:"connected"}); node.status({fill:"green",shape:"dot",text:"connected"});
}); });
node.client.on("reconnecting", function() { node.client.on("reconnecting", function() {
@ -110,14 +110,14 @@ module.exports = function(RED) {
} }
}; };
if (this.serverConfig.vhost) { if (this.serverConfig.vhost) {
this.stompClientOpts.vhost = this.serverConfig.vhost; this.stompClientOpts.vhost = this.serverConfig.vhost;
} }
var node = this; var node = this;
node.client = new StompClient(node.stompClientOpts); node.client = new StompClient(node.stompClientOpts);
node.client.on("connect", function() { node.client.on("connect", function() {
node.status({fill:"green",shape:"dot",text:"connected"}); node.status({fill:"green",shape:"dot",text:"connected"});
}); });
node.client.on("reconnecting", function() { node.client.on("reconnecting", function() {

View File

@ -22,7 +22,8 @@ module.exports = function(RED) {
node.log("sent WOL magic packet"); node.log("sent WOL magic packet");
} }
}); });
} catch(e) { }
catch(e) {
if (RED.settings.verbose) { node.log("WOL: socket error"); } if (RED.settings.verbose) { node.log("WOL: socket error"); }
} }
} }

View File

@ -28,7 +28,8 @@ module.exports = function(RED) {
else { else {
node.warn("This node only handles strings or buffers."); node.warn("This node only handles strings or buffers.");
} }
} else { node.warn("No payload found to process"); } }
else { node.warn("No payload found to process"); }
}); });
} }
RED.nodes.registerType("base64",Base64Node); RED.nodes.registerType("base64",Base64Node);

View File

@ -29,7 +29,8 @@ module.exports = function(RED) {
if (lt && ln) { if (lt && ln) {
msg.location.geohash = geohash.encode(lt, ln, le); msg.location.geohash = geohash.encode(lt, ln, le);
node.send(msg); node.send(msg);
} else { }
else {
node.warn("lat or lon missing from msg.location"); node.warn("lat or lon missing from msg.location");
} }
} }
@ -62,7 +63,8 @@ module.exports = function(RED) {
if (!isNaN(la) && !isNaN(lo)) { if (!isNaN(la) && !isNaN(lo)) {
msg.payload = geohash.encode(la, lo, li); msg.payload = geohash.encode(la, lo, li);
node.send(msg); node.send(msg);
} else { }
else {
node.warn("Incorrect string format - should be lat,lon"); node.warn("Incorrect string format - should be lat,lon");
} }
} }
@ -79,7 +81,8 @@ module.exports = function(RED) {
if (lat && lon) { if (lat && lon) {
msg.payload.geohash = geohash.encode(lat, lon, len); msg.payload.geohash = geohash.encode(lat, lon, len);
node.send(msg); node.send(msg);
} else { }
else {
node.warn("lat or lon missing from msg.payload"); node.warn("lat or lon missing from msg.payload");
} }
} }

View File

@ -26,7 +26,8 @@ module.exports = function(RED) {
node.send(msg); node.send(msg);
node.status({text:le +" o->b "+ msg.payload.length}); node.status({text:le +" o->b "+ msg.payload.length});
} }
} else { node.warn("No payload found to process"); } }
else { node.warn("No payload found to process"); }
}); });
} }
RED.nodes.registerType("msgpack",MsgPackNode); RED.nodes.registerType("msgpack",MsgPackNode);

View File

@ -7,7 +7,8 @@ module.exports = function(RED) {
RED.nodes.createNode(this, n); RED.nodes.createNode(this, n);
this.lang = n.lang || "en"; this.lang = n.lang || "en";
var credentials = RED.nodes.getCredentials(n.id); var credentials = RED.nodes.getCredentials(n.id);
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; } else { this.error("No what3words API key set"); } if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
else { this.error("No what3words API key set"); }
this.w3w = new What3Words(this.pushkey); this.w3w = new What3Words(this.pushkey);
var node = this; var node = this;
var w1 = /^\*\w{6,31}$/; var w1 = /^\*\w{6,31}$/;
@ -25,7 +26,8 @@ module.exports = function(RED) {
.catch(function(err) { .catch(function(err) {
node.warn(err) node.warn(err)
}); });
} else if (typeof (msg.payload) === "string") { }
else if (typeof (msg.payload) === "string") {
if (msg.payload.split(",").length === 2) { // see if it's 2 comma separated words if (msg.payload.split(",").length === 2) { // see if it's 2 comma separated words
node.w3w.positionToWords({ position:msg.payload, lang:node.lang }) node.w3w.positionToWords({ position:msg.payload, lang:node.lang })
.then(function(response) { .then(function(response) {
@ -36,7 +38,8 @@ module.exports = function(RED) {
.catch(function(err) { .catch(function(err) {
node.warn(err); node.warn(err);
}); });
} else if (msg.payload.match(w3)) { // see if it's 3 dot separated words }
else if (msg.payload.match(w3)) { // see if it's 3 dot separated words
node.w3w.wordsToPosition({ words:msg.payload }) node.w3w.wordsToPosition({ words:msg.payload })
.then(function(response) { .then(function(response) {
if (!msg.hasOwnProperty("location")) { msg.location = {}; } if (!msg.hasOwnProperty("location")) { msg.location = {}; }
@ -47,7 +50,8 @@ module.exports = function(RED) {
.catch(function(err) { .catch(function(err) {
node.warn(err) node.warn(err)
}); });
} else if (msg.payload.match(w1)) { // see if it's a *Oneword }
else if (msg.payload.match(w1)) { // see if it's a *Oneword
node.w3w.wordsToPosition({ words:msg.payload }) node.w3w.wordsToPosition({ words:msg.payload })
.then(function(response) { .then(function(response) {
if (!msg.hasOwnProperty("location")) { msg.location = {}; } if (!msg.hasOwnProperty("location")) { msg.location = {}; }
@ -59,8 +63,10 @@ module.exports = function(RED) {
.catch(function(err) { .catch(function(err) {
node.warn(err); node.warn(err);
}); });
} else { node.warn("No useable data found. See info."); } }
} else { node.warn("No useable data found. See info."); } else { node.warn("No useable data found. See info."); }
}
else { node.warn("No useable data found. See info."); }
}); });
} }
RED.nodes.registerType("what3words", what3wordsNode); RED.nodes.registerType("what3words", what3wordsNode);
@ -71,7 +77,8 @@ module.exports = function(RED) {
var credentials = RED.nodes.getCredentials(req.params.id); var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) { if (credentials) {
res.send(JSON.stringify({hasPassword:(credentials.pushkey && credentials.pushkey !== "")})); res.send(JSON.stringify({hasPassword:(credentials.pushkey && credentials.pushkey !== "")}));
} else { }
else {
res.send(JSON.stringify({})); res.send(JSON.stringify({}));
} }
}); });
@ -91,7 +98,8 @@ module.exports = function(RED) {
var credentials = RED.nodes.getCredentials(req.params.id) || {}; var credentials = RED.nodes.getCredentials(req.params.id) || {};
if (newCreds.pushkey === "") { if (newCreds.pushkey === "") {
delete credentials.pushkey; delete credentials.pushkey;
} else { }
else {
credentials.pushkey = newCreds.pushkey || credentials.pushkey; credentials.pushkey = newCreds.pushkey || credentials.pushkey;
} }
RED.nodes.addCredentials(req.params.id, credentials); RED.nodes.addCredentials(req.params.id, credentials);

View File

@ -45,7 +45,8 @@ module.exports = function(RED) {
// This will be called anytime there is a new dweet for my-thing // This will be called anytime there is a new dweet for my-thing
if (dweet.content.hasOwnProperty("payload")) { if (dweet.content.hasOwnProperty("payload")) {
dweet.payload = dweet.content.payload; dweet.payload = dweet.content.payload;
} else { }
else {
dweet.payload = dweet.content; dweet.payload = dweet.content;
} }
delete dweet.content; delete dweet.content;

View File

@ -19,7 +19,8 @@ module.exports = function(RED) {
try { try {
var globalkeys = RED.settings.email || require(process.env.NODE_RED_HOME+"/../emailkeys.js"); var globalkeys = RED.settings.email || require(process.env.NODE_RED_HOME+"/../emailkeys.js");
} catch(err) { }
catch(err) {
} }
function EmailNode(n) { function EmailNode(n) {
@ -57,7 +58,7 @@ module.exports = function(RED) {
var smtpTransport = nodemailer.createTransport({ var smtpTransport = nodemailer.createTransport({
host: node.outserver, host: node.outserver,
port: node.outport, port: node.outport,
secure: true, secure: node.useSSL,
auth: { auth: {
user: node.userid, user: node.userid,
pass: node.password pass: node.password

View File

@ -1,6 +1,6 @@
{ {
"name": "node-red-node-email", "name": "node-red-node-email",
"version": "0.1.15", "version": "0.1.16",
"description": "Node-RED nodes to send and receive simple emails", "description": "Node-RED nodes to send and receive simple emails",
"dependencies": { "dependencies": {
"nodemailer": "^1.11.0", "nodemailer": "^1.11.0",

View File

@ -15,7 +15,8 @@ module.exports = function(RED) {
var parsedUrl = url.parse(this.url); var parsedUrl = url.parse(this.url);
if (!(parsedUrl.host || (parsedUrl.hostname && parsedUrl.port)) && !parsedUrl.isUnix) { if (!(parsedUrl.host || (parsedUrl.hostname && parsedUrl.port)) && !parsedUrl.isUnix) {
this.error(RED._("feedparse.errors.invalidurl")); this.error(RED._("feedparse.errors.invalidurl"));
} else { }
else {
var getFeed = function() { var getFeed = function() {
var req = request(node.url, {timeout: 10000, pool: false}); var req = request(node.url, {timeout: 10000, pool: false});
//req.setMaxListeners(50); //req.setMaxListeners(50);

View File

@ -33,10 +33,10 @@ module.exports = function(RED) {
} }
RED.nodes.registerType("irc-server",IRCServerNode, { RED.nodes.registerType("irc-server",IRCServerNode, {
credentials: { credentials: {
username: {type:"text"}, username: {type:"text"},
password: {type:"password"} password: {type:"password"}
} }
}); });

View File

@ -62,7 +62,8 @@ module.exports = function(RED) {
pusher.me(function(err, me) { pusher.me(function(err, me) {
if (err) { if (err) {
reject(err); reject(err);
} else { }
else {
resolve(me); resolve(me);
} }
}); });
@ -74,7 +75,8 @@ module.exports = function(RED) {
pusher.history({limit:1}, function(err, res) { pusher.history({limit:1}, function(err, res) {
if (err) { if (err) {
resolve(0); resolve(0);
} else { }
else {
try { try {
resolve(res.pushes[0].modified); resolve(res.pushes[0].modified);
} }
@ -144,7 +146,8 @@ module.exports = function(RED) {
closing = true; closing = true;
try { try {
this.stream.close(); this.stream.close();
} catch(err) { }
catch(err) {
// Ignore error if not connected // Ignore error if not connected
} }
}); });
@ -167,7 +170,8 @@ module.exports = function(RED) {
} }
try { try {
resolve(res.pushes[0].modified); resolve(res.pushes[0].modified);
} catch(ex) { }
catch(ex) {
resolve(last); resolve(last);
} }
}); });
@ -360,7 +364,8 @@ module.exports = function(RED) {
if (me) { if (me) {
deviceid = me.email; deviceid = me.email;
self.pushMsg(pushtype, deviceid, title, msg); self.pushMsg(pushtype, deviceid, title, msg);
} else { }
else {
self.error("Unable to push",msg); self.error("Unable to push",msg);
} }
}); });

View File

@ -39,10 +39,12 @@ module.exports = function(RED) {
if (this.api) { if (this.api) {
this.twilioClient = twilio(this.api.sid,this.api.token); this.twilioClient = twilio(this.api.sid,this.api.token);
this.fromNumber = this.api.from; this.fromNumber = this.api.from;
} else if (twiliokey) { }
else if (twiliokey) {
this.twilioClient = twilio(twiliokey.account, twiliokey.authtoken); this.twilioClient = twilio(twiliokey.account, twiliokey.authtoken);
this.fromNumber = twiliokey.from; this.fromNumber = twiliokey.from;
} else { }
else {
this.error("missing twilio credentials"); this.error("missing twilio credentials");
return; return;
} }
@ -66,7 +68,8 @@ module.exports = function(RED) {
} }
//console.log(response); //console.log(response);
}); });
} else { }
else {
// Send SMS // Send SMS
node.twilioClient.sendMessage( {to: tonum, from: node.fromNumber, body: msg.payload}, function(err, response) { node.twilioClient.sendMessage( {to: tonum, from: node.fromNumber, body: msg.payload}, function(err, response) {
if (err) { if (err) {
@ -76,7 +79,8 @@ module.exports = function(RED) {
}); });
} }
} catch (err) { }
catch (err) {
node.error(err); node.error(err);
} }
}); });

View File

@ -32,7 +32,8 @@ module.exports = function(RED) {
msg.location.lon = msg.tweet.geo.coordinates[1]; msg.location.lon = msg.tweet.geo.coordinates[1];
msg.location.icon = "twitter"; msg.location.icon = "twitter";
} }
} else if (msg.tweet.coordinates) { // otherwise attempt go get it from coordinates }
else if (msg.tweet.coordinates) { // otherwise attempt go get it from coordinates
if (msg.tweet.coordinates.coordinates && msg.tweet.coordinates.coordinates.length === 2) { if (msg.tweet.coordinates.coordinates && msg.tweet.coordinates.coordinates.length === 2) {
if (!msg.location) { msg.location = {}; } if (!msg.location) { msg.location = {}; }
// WARNING! coordinates[1] is lat, coordinates[0] is lon!!! // WARNING! coordinates[1] is lat, coordinates[0] is lon!!!
@ -94,7 +95,8 @@ module.exports = function(RED) {
} }
if (cb[0]) { if (cb[0]) {
node.since_ids[u] = cb[0].id_str; node.since_ids[u] = cb[0].id_str;
} else { }
else {
node.since_ids[u] = '0'; node.since_ids[u] = '0';
} }
node.poll_ids.push(setInterval(function() { node.poll_ids.push(setInterval(function() {
@ -143,7 +145,8 @@ module.exports = function(RED) {
} }
if (cb[0]) { if (cb[0]) {
node.since_id = cb[0].id_str; node.since_id = cb[0].id_str;
} else { }
else {
node.since_id = '0'; node.since_id = '0';
} }
node.poll_ids.push(setInterval(function() { node.poll_ids.push(setInterval(function() {
@ -203,7 +206,8 @@ module.exports = function(RED) {
//console.log("ERRO",rc,tweet); //console.log("ERRO",rc,tweet);
if (rc == 420) { if (rc == 420) {
node.status({fill:"red", shape:"ring", text:RED._("twitter.errors.ratelimit")}); node.status({fill:"red", shape:"ring", text:RED._("twitter.errors.ratelimit")});
} else { }
else {
node.status({fill:"red", shape:"ring", text:" "}); node.status({fill:"red", shape:"ring", text:" "});
node.warn(RED._("twitter.errors.streamerror",{error:tweet.toString(),rc:rc})); node.warn(RED._("twitter.errors.streamerror",{error:tweet.toString(),rc:rc}));
} }
@ -265,7 +269,8 @@ module.exports = function(RED) {
//console.log("ERRO",rc,tweet); //console.log("ERRO",rc,tweet);
if (rc == 420) { if (rc == 420) {
node.status({fill:"red", shape:"ring", text:RED._("twitter.errors.ratelimit")}); node.status({fill:"red", shape:"ring", text:RED._("twitter.errors.ratelimit")});
} else { }
else {
node.status({fill:"red", shape:"ring", text:tweet.toString()}); node.status({fill:"red", shape:"ring", text:tweet.toString()});
node.warn(RED._("twitter.errors.streamerror",{error:tweet.toString(),rc:rc})); node.warn(RED._("twitter.errors.streamerror",{error:tweet.toString(),rc:rc}));
} }
@ -409,13 +414,15 @@ module.exports = function(RED) {
if (err) { if (err) {
node.error(err,msg); node.error(err,msg);
node.status({fill:"red",shape:"ring",text:"twitter.status.failed"}); node.status({fill:"red",shape:"ring",text:"twitter.status.failed"});
} else { }
else {
var response = JSON.parse(body); var response = JSON.parse(body);
if (response.errors) { if (response.errors) {
var errorList = response.errors.map(function(er) { return er.code+": "+er.message }).join(", "); var errorList = response.errors.map(function(er) { return er.code+": "+er.message }).join(", ");
node.error(RED._("twitter.errors.sendfail",{error:errorList}),msg); node.error(RED._("twitter.errors.sendfail",{error:errorList}),msg);
node.status({fill:"red",shape:"ring",text:"twitter.status.failed"}); node.status({fill:"red",shape:"ring",text:"twitter.status.failed"});
} else { }
else {
node.status({}); node.status({});
} }
} }
@ -424,7 +431,8 @@ module.exports = function(RED) {
form.append("status",msg.payload); form.append("status",msg.payload);
form.append("media[]",msg.media,{filename:"image"}); form.append("media[]",msg.media,{filename:"image"});
} else { }
else {
if (typeof msg.params === 'undefined') { msg.params = {}; } if (typeof msg.params === 'undefined') { msg.params = {}; }
twit.updateStatus(msg.payload, msg.params, function (err, data) { twit.updateStatus(msg.payload, msg.params, function (err, data) {
if (err) { if (err) {
@ -460,7 +468,8 @@ module.exports = function(RED) {
var err = {statusCode: 401, data: "dummy error"}; var err = {statusCode: 401, data: "dummy error"};
var resp = RED._("twitter.errors.oautherror",{statusCode: err.statusCode, errorData: err.data}); var resp = RED._("twitter.errors.oautherror",{statusCode: err.statusCode, errorData: err.data});
res.send(resp) res.send(resp)
} else { }
else {
credentials.oauth_token = oauth_token; credentials.oauth_token = oauth_token;
credentials.oauth_token_secret = oauth_token_secret; credentials.oauth_token_secret = oauth_token_secret;
res.redirect('https://api.twitter.com/oauth/authorize?oauth_token='+oauth_token) res.redirect('https://api.twitter.com/oauth/authorize?oauth_token='+oauth_token)
@ -481,7 +490,8 @@ module.exports = function(RED) {
if (error) { if (error) {
RED.log.error(error); RED.log.error(error);
res.send(RED._("twitter.errors.oauthbroke")); res.send(RED._("twitter.errors.oauthbroke"));
} else { }
else {
credentials = {}; credentials = {};
credentials.access_token = oauth_access_token; credentials.access_token = oauth_access_token;
credentials.access_token_secret = oauth_access_token_secret; credentials.access_token_secret = oauth_access_token_secret;

View File

@ -104,7 +104,8 @@ module.exports = function(RED) {
skipPresence : true, skipPresence : true,
reconnect : false reconnect : false
}); });
} catch(e) { }
catch(e) {
node.error("Bad xmpp configuration"); node.error("Bad xmpp configuration");
node.status({fill:"red",shape:"ring",text:"not connected"}); node.status({fill:"red",shape:"ring",text:"not connected"});
} }
@ -180,7 +181,8 @@ module.exports = function(RED) {
skipPresence : true, skipPresence : true,
reconnect : false reconnect : false
}); });
} catch(e) { }
catch(e) {
node.error("Bad xmpp configuration"); node.error("Bad xmpp configuration");
node.status({fill:"red",shape:"ring",text:"not connected"}); node.status({fill:"red",shape:"ring",text:"not connected"});
} }
@ -201,7 +203,8 @@ module.exports = function(RED) {
else if (msg.payload) { else if (msg.payload) {
if (typeof(msg.payload) === "object") { if (typeof(msg.payload) === "object") {
xmpp.send(to, JSON.stringify(msg.payload), node.join); xmpp.send(to, JSON.stringify(msg.payload), node.join);
} else { }
else {
xmpp.send(to, msg.payload.toString(), node.join); xmpp.send(to, msg.payload.toString(), node.join);
} }
} }

View File

@ -55,7 +55,8 @@ module.exports = function(RED) {
if (noerror) { node.error(err); } if (noerror) { node.error(err); }
noerror = false; noerror = false;
node.tout = setTimeout(connectToDB, 10000); node.tout = setTimeout(connectToDB, 10000);
} else { }
else {
node.status({fill:"green",shape:"dot",text:RED._("mongodb.status.connected")}); node.status({fill:"green",shape:"dot",text:RED._("mongodb.status.connected")});
node.clientDb = db; node.clientDb = db;
noerror = true; noerror = true;
@ -67,7 +68,8 @@ module.exports = function(RED) {
if (!node.collection) { if (!node.collection) {
if (msg.collection) { if (msg.collection) {
coll = db.collection(msg.collection); coll = db.collection(msg.collection);
} else { }
else {
node.error(RED._("mongodb.errors.nocollection"),msg); node.error(RED._("mongodb.errors.nocollection"),msg);
return; return;
} }
@ -87,14 +89,16 @@ module.exports = function(RED) {
node.error(err,msg); node.error(err,msg);
} }
}); });
} else { }
else {
coll.save(msg,function(err, item) { coll.save(msg,function(err, item) {
if (err) { if (err) {
node.error(err,msg); node.error(err,msg);
} }
}); });
} }
} else if (node.operation === "insert") { }
else if (node.operation === "insert") {
if (node.payonly) { if (node.payonly) {
if (typeof msg.payload !== "object") { if (typeof msg.payload !== "object") {
msg.payload = {"payload": msg.payload}; msg.payload = {"payload": msg.payload};
@ -107,14 +111,16 @@ module.exports = function(RED) {
node.error(err,msg); node.error(err,msg);
} }
}); });
} else { }
else {
coll.insert(msg, function(err,item) { coll.insert(msg, function(err,item) {
if (err) { if (err) {
node.error(err,msg); node.error(err,msg);
} }
}); });
} }
} else if (node.operation === "update") { }
else if (node.operation === "update") {
if (typeof msg.payload !== "object") { if (typeof msg.payload !== "object") {
msg.payload = {"payload": msg.payload}; msg.payload = {"payload": msg.payload};
} }
@ -132,7 +138,8 @@ module.exports = function(RED) {
node.error(err,msg); node.error(err,msg);
} }
}); });
} else if (node.operation === "delete") { }
else if (node.operation === "delete") {
coll.remove(msg.payload, function(err, items) { coll.remove(msg.payload, function(err, items) {
if (err) { if (err) {
node.error(err,msg); node.error(err,msg);
@ -173,7 +180,8 @@ module.exports = function(RED) {
if (noerror) { node.error(err); } if (noerror) { node.error(err); }
noerror = false; noerror = false;
node.tout = setTimeout(connectToDB, 10000); node.tout = setTimeout(connectToDB, 10000);
} else { }
else {
node.status({fill:"green",shape:"dot",text:RED._("mongodb.status.connected")}); node.status({fill:"green",shape:"dot",text:RED._("mongodb.status.connected")});
node.clientDb = db; node.clientDb = db;
noerror = true; noerror = true;
@ -217,7 +225,8 @@ module.exports = function(RED) {
node.send(msg); node.send(msg);
} }
}); });
} else if (node.operation === "count") { }
else if (node.operation === "count") {
selector = ensureValidSelectorObject(msg.payload); selector = ensureValidSelectorObject(msg.payload);
coll.count(selector, function(err, count) { coll.count(selector, function(err, count) {
if (err) { if (err) {
@ -234,7 +243,8 @@ module.exports = function(RED) {
coll.aggregate(msg.payload, function(err, result) { coll.aggregate(msg.payload, function(err, result) {
if (err) { if (err) {
node.error(err); node.error(err);
} else { }
else {
msg.payload = result; msg.payload = result;
node.send(msg); node.send(msg);
} }

View File

@ -47,7 +47,8 @@ module.exports = function(RED) {
if (this.client.connected) { if (this.client.connected) {
this.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"}); this.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"});
} else { }
else {
this.status({fill:"red",shape:"ring",text:"node-red:common.status.disconnected"},true); this.status({fill:"red",shape:"ring",text:"node-red:common.status.disconnected"},true);
} }
@ -64,23 +65,29 @@ module.exports = function(RED) {
if (k) { if (k) {
if (this.structtype == "string") { if (this.structtype == "string") {
this.client.set(k,RED.util.ensureString(msg.payload)); this.client.set(k,RED.util.ensureString(msg.payload));
} else if (this.structtype == "hash") { }
else if (this.structtype == "hash") {
if (typeof msg.payload == "object") { if (typeof msg.payload == "object") {
this.client.hmset(k,msg.payload); this.client.hmset(k,msg.payload);
} else { }
else {
var r = hashFieldRE.exec(msg.payload); var r = hashFieldRE.exec(msg.payload);
if (r) { if (r) {
this.client.hset(k,r[1],r[2]); this.client.hset(k,r[1],r[2]);
} else { }
else {
this.warn(RED._("redisout.errors.invalidpayload")); this.warn(RED._("redisout.errors.invalidpayload"));
} }
} }
} else if (this.structtype == "set") { }
else if (this.structtype == "set") {
this.client.sadd(k,msg.payload); this.client.sadd(k,msg.payload);
} else if (this.structtype == "list") { }
else if (this.structtype == "list") {
this.client.rpush(k,msg.payload); this.client.rpush(k,msg.payload);
} }
} else { }
else {
this.warn(RED._("redisout.errors.nokey")); this.warn(RED._("redisout.errors.nokey"));
} }
}); });

View File

@ -144,11 +144,13 @@ module.exports = function(RED) {
try { try {
node.emit("input", {payload:"reset"}); node.emit("input", {payload:"reset"});
res.sendStatus(200); res.sendStatus(200);
} catch (err) { }
catch (err) {
res.sendStatus(500); res.sendStatus(500);
node.error("Inject failed:" + err); node.error("Inject failed:" + err);
} }
} else { }
else {
res.sendStatus(404); res.sendStatus(404);
} }
}); });

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-daemon", "name" : "node-red-node-daemon",
"version" : "0.0.10", "version" : "0.0.11",
"description" : "A Node-RED node that runs and monitors a long running system command.", "description" : "A Node-RED node that runs and monitors a long running system command.",
"dependencies" : { "dependencies" : {
}, },

View File

@ -50,13 +50,16 @@ module.exports = function(RED) {
msg.location.lat = latitude; msg.location.lat = latitude;
msg.location.lon = longitude; msg.location.lon = longitude;
return; return;
} else { }
else {
node.log("Invalid longitude data, no location information has been added to the message."); node.log("Invalid longitude data, no location information has been added to the message.");
} }
} else { }
else {
node.log("Invalid latitude data, no location information has been added to the message."); node.log("Invalid latitude data, no location information has been added to the message.");
} }
} else { }
else {
node.log("The location of this image cannot be determined safely so no location information has been added to the message."); node.log("The location of this image cannot be determined safely so no location information has been added to the message.");
} }
} }
@ -68,26 +71,31 @@ module.exports = function(RED) {
new ExifImage({ image : msg.payload }, function (error, exifData) { new ExifImage({ image : msg.payload }, function (error, exifData) {
if (error) { if (error) {
node.log(error.toString()); node.log(error.toString());
} else { }
else {
//msg.payload remains the same buffer //msg.payload remains the same buffer
if ((exifData) && (exifData.hasOwnProperty("gps")) && (Object.keys(exifData.gps).length !== 0)) { if ((exifData) && (exifData.hasOwnProperty("gps")) && (Object.keys(exifData.gps).length !== 0)) {
msg.exif = exifData; msg.exif = exifData;
addMsgLocationDataFromExifGPSData(msg); addMsgLocationDataFromExifGPSData(msg);
} else { }
else {
node.warn("The incoming image did not contain Exif GPS data, nothing to do. "); node.warn("The incoming image did not contain Exif GPS data, nothing to do. ");
} }
} }
node.send(msg); node.send(msg);
}); });
} else { }
else {
node.error("Invalid payload received, the Exif node cannot proceed, no messages sent."); node.error("Invalid payload received, the Exif node cannot proceed, no messages sent.");
return; return;
} }
} else { }
else {
node.error("No payload received, the Exif node cannot proceed, no messages sent."); node.error("No payload received, the Exif node cannot proceed, no messages sent.");
return; return;
} }
} catch (error) { }
catch (error) {
node.error("An error occurred while extracting Exif information. Please check the log for details."); node.error("An error occurred while extracting Exif information. Please check the log for details.");
node.log('Error: '+error.message); node.log('Error: '+error.message);
return; return;