mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Apply consistent style to node-red-nodes
(not updating npm for this yet - just whitespace)
This commit is contained in:
parent
84f61a0466
commit
f497b57b7d
@ -54,7 +54,7 @@ module.exports = function (RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node constructor for bbb-analogue-in
|
// Node constructor for bbb-analogue-in
|
||||||
function AnalogueInputNode(n) {
|
function AnalogueInputNode(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
var node = this;
|
var node = this;
|
||||||
@ -110,7 +110,7 @@ module.exports = function (RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node constructor for bbb-discrete-in
|
// Node constructor for bbb-discrete-in
|
||||||
function DiscreteInputNode(n) {
|
function DiscreteInputNode(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
var node = this;
|
var node = this;
|
||||||
@ -141,7 +141,7 @@ module.exports = function (RED) {
|
|||||||
this.intervalId = null; // Remember the timer ID so we can delete it when we are closed
|
this.intervalId = null; // Remember the timer ID so we can delete it when we are closed
|
||||||
this.currentState = 0; // The pin input state "1" or "0"
|
this.currentState = 0; // The pin input state "1" or "0"
|
||||||
this.lastActiveTime = NaN; // The date (in ms since epoch) when the pin last went high
|
this.lastActiveTime = NaN; // The date (in ms since epoch) when the pin last went high
|
||||||
// switch to process.hrtime()
|
// switch to process.hrtime()
|
||||||
this.totalActiveTime = 0; // The total time in ms that the pin has been high (since reset)
|
this.totalActiveTime = 0; // The total time in ms that the pin has been high (since reset)
|
||||||
this.starting = true;
|
this.starting = true;
|
||||||
this.debouncing = false; // True after a change of state while waiting for the 7ms debounce time to elapse
|
this.debouncing = false; // True after a change of state while waiting for the 7ms debounce time to elapse
|
||||||
@ -285,7 +285,7 @@ module.exports = function (RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node constructor for bbb-pulse-in
|
// Node constructor for bbb-pulse-in
|
||||||
function PulseInputNode(n) {
|
function PulseInputNode(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
var node = this;
|
var node = this;
|
||||||
@ -383,7 +383,7 @@ module.exports = function (RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node constructor for bbb-discrete-out
|
// Node constructor for bbb-discrete-out
|
||||||
function DiscreteOutputNode(n) {
|
function DiscreteOutputNode(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
var node = this;
|
var node = this;
|
||||||
@ -443,7 +443,7 @@ module.exports = function (RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node constructor for bbb-pulse-out
|
// Node constructor for bbb-pulse-out
|
||||||
function PulseOutputNode(n) {
|
function PulseOutputNode(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
var node = this;
|
var node = this;
|
||||||
@ -519,14 +519,14 @@ module.exports = function (RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the nodes by name. This must be called before overriding any of the Node functions.
|
// Register the nodes by name. This must be called before overriding any of the Node functions.
|
||||||
RED.nodes.registerType("bbb-analogue-in", AnalogueInputNode);
|
RED.nodes.registerType("bbb-analogue-in", AnalogueInputNode);
|
||||||
RED.nodes.registerType("bbb-discrete-in", DiscreteInputNode);
|
RED.nodes.registerType("bbb-discrete-in", DiscreteInputNode);
|
||||||
RED.nodes.registerType("bbb-pulse-in", PulseInputNode);
|
RED.nodes.registerType("bbb-pulse-in", PulseInputNode);
|
||||||
RED.nodes.registerType("bbb-discrete-out", DiscreteOutputNode);
|
RED.nodes.registerType("bbb-discrete-out", DiscreteOutputNode);
|
||||||
RED.nodes.registerType("bbb-pulse-out", PulseOutputNode);
|
RED.nodes.registerType("bbb-pulse-out", PulseOutputNode);
|
||||||
|
|
||||||
// On close, detach the interrupt (if we attached one) and clear any active timers
|
// On close, detach the interrupt (if we attached one) and clear any active timers
|
||||||
DiscreteInputNode.prototype.close = function () {
|
DiscreteInputNode.prototype.close = function () {
|
||||||
if (this.interruptAttached) {
|
if (this.interruptAttached) {
|
||||||
bonescript.detachInterrupt(this._pin);
|
bonescript.detachInterrupt(this._pin);
|
||||||
@ -539,7 +539,7 @@ module.exports = function (RED) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// On close, detach the interrupt (if we attached one) and clear the interval (if we set one)
|
// On close, detach the interrupt (if we attached one) and clear the interval (if we set one)
|
||||||
PulseInputNode.prototype.close = function () {
|
PulseInputNode.prototype.close = function () {
|
||||||
if (this.interruptAttached) {
|
if (this.interruptAttached) {
|
||||||
bonescript.detachInterrupt(this._pin);
|
bonescript.detachInterrupt(this._pin);
|
||||||
@ -549,7 +549,7 @@ module.exports = function (RED) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// On close, clear an active pulse timer
|
// On close, clear an active pulse timer
|
||||||
PulseOutputNode.prototype.close = function () {
|
PulseOutputNode.prototype.close = function () {
|
||||||
if (this.pulseTimer !== null) {
|
if (this.pulseTimer !== null) {
|
||||||
clearTimeout(this.pulseTimer);
|
clearTimeout(this.pulseTimer);
|
||||||
|
@ -17,12 +17,12 @@
|
|||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var exec = require('child_process').exec;
|
var exec = require('child_process').exec;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
var gpioCommand = '/usr/local/bin/gpiohb';
|
var gpioCommand = '/usr/local/bin/gpiohb';
|
||||||
|
|
||||||
//if (!fs.existsSync("/sys/devices/soc0/machine")) { // unlikely if not on a Hummingboard
|
//if (!fs.existsSync("/sys/devices/soc0/machine")) { // unlikely if not on a Hummingboard
|
||||||
//throw "Info : Ignoring Hummingboard specific node.";
|
//throw "Info : Ignoring Hummingboard specific node.";
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if (!fs.existsSync(gpioCommand)) { // gpio command not installed
|
if (!fs.existsSync(gpioCommand)) { // gpio command not installed
|
||||||
@ -31,66 +31,66 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
// Map physical P1 pins to Gordon's Wiring-Pi Pins (as they should be V1/V2 tolerant)
|
// Map physical P1 pins to Gordon's Wiring-Pi Pins (as they should be V1/V2 tolerant)
|
||||||
var pintable = {
|
var pintable = {
|
||||||
// Physical : WiringPi
|
// Physical : WiringPi
|
||||||
"11":"0",
|
"11":"0",
|
||||||
"12":"1",
|
"12":"1",
|
||||||
"13":"2",
|
"13":"2",
|
||||||
"15":"3",
|
"15":"3",
|
||||||
"16":"4",
|
"16":"4",
|
||||||
"18":"5",
|
"18":"5",
|
||||||
"22":"6",
|
"22":"6",
|
||||||
"7":"7",
|
"7":"7",
|
||||||
"3":"8",
|
"3":"8",
|
||||||
"5":"9",
|
"5":"9",
|
||||||
"24":"10",
|
"24":"10",
|
||||||
"26":"11",
|
"26":"11",
|
||||||
"19":"12",
|
"19":"12",
|
||||||
"21":"13",
|
"21":"13",
|
||||||
"23":"14",
|
"23":"14",
|
||||||
"8":"15",
|
"8":"15",
|
||||||
"10":"16",
|
"10":"16",
|
||||||
"27":"30",
|
"27":"30",
|
||||||
"28":"31",
|
"28":"31",
|
||||||
"29":"21",
|
"29":"21",
|
||||||
"31":"22",
|
"31":"22",
|
||||||
"32":"26",
|
"32":"26",
|
||||||
"33":"23",
|
"33":"23",
|
||||||
"35":"24",
|
"35":"24",
|
||||||
"36":"27",
|
"36":"27",
|
||||||
"37":"25",
|
"37":"25",
|
||||||
"38":"28",
|
"38":"28",
|
||||||
"40":"29"
|
"40":"29"
|
||||||
}
|
}
|
||||||
var tablepin = {
|
var tablepin = {
|
||||||
// WiringPi : Physical
|
// WiringPi : Physical
|
||||||
"0":"11",
|
"0":"11",
|
||||||
"1":"12",
|
"1":"12",
|
||||||
"2":"13",
|
"2":"13",
|
||||||
"3":"15",
|
"3":"15",
|
||||||
"4":"16",
|
"4":"16",
|
||||||
"5":"18",
|
"5":"18",
|
||||||
"6":"22",
|
"6":"22",
|
||||||
"7":"7",
|
"7":"7",
|
||||||
"8":"3",
|
"8":"3",
|
||||||
"9":"5",
|
"9":"5",
|
||||||
"10":"24",
|
"10":"24",
|
||||||
"11":"26",
|
"11":"26",
|
||||||
"12":"19",
|
"12":"19",
|
||||||
"13":"21",
|
"13":"21",
|
||||||
"14":"23",
|
"14":"23",
|
||||||
"15":"8",
|
"15":"8",
|
||||||
"16":"10",
|
"16":"10",
|
||||||
"30":"27",
|
"30":"27",
|
||||||
"31":"28",
|
"31":"28",
|
||||||
"21":"29",
|
"21":"29",
|
||||||
"22":"31",
|
"22":"31",
|
||||||
"26":"32",
|
"26":"32",
|
||||||
"23":"33",
|
"23":"33",
|
||||||
"24":"35",
|
"24":"35",
|
||||||
"27":"36",
|
"27":"36",
|
||||||
"25":"37",
|
"25":"37",
|
||||||
"28":"38",
|
"28":"38",
|
||||||
"29":"40"
|
"29":"40"
|
||||||
}
|
}
|
||||||
|
|
||||||
function GPIOHBInNode(n) {
|
function GPIOHBInNode(n) {
|
||||||
|
@ -19,7 +19,7 @@ module.exports = function(RED) {
|
|||||||
var util = require("util");
|
var util = require("util");
|
||||||
//var exec = require('child_process').exec;
|
//var exec = require('child_process').exec;
|
||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
var gpioCommand = __dirname+'/nrgpio';
|
var gpioCommand = __dirname+'/nrgpio';
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ module.exports = function(RED) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
var util = require("util");
|
var util = require("util");
|
||||||
var exec = require('child_process').exec;
|
var exec = require('child_process').exec;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
|
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
|
||||||
throw "Info : Ignoring Raspberry Pi specific node.";
|
throw "Info : Ignoring Raspberry Pi specific node.";
|
||||||
@ -30,31 +30,31 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
// Map names of pins to Gordon's gpio PiFace pin numbers
|
// Map names of pins to Gordon's gpio PiFace pin numbers
|
||||||
var pintable = {
|
var pintable = {
|
||||||
// Physical : WiringPi
|
// Physical : WiringPi
|
||||||
"Button S1":"200",
|
"Button S1":"200",
|
||||||
"Button S2":"201",
|
"Button S2":"201",
|
||||||
"Button S3":"202",
|
"Button S3":"202",
|
||||||
"Button S4":"203",
|
"Button S4":"203",
|
||||||
"Input 5":"204",
|
"Input 5":"204",
|
||||||
"Input 6":"205",
|
"Input 6":"205",
|
||||||
"Input 7":"206",
|
"Input 7":"206",
|
||||||
"Input 8":"207",
|
"Input 8":"207",
|
||||||
"Output0":"208",
|
"Output0":"208",
|
||||||
"Output1":"209",
|
"Output1":"209",
|
||||||
"Output2":"210",
|
"Output2":"210",
|
||||||
"Output3":"211",
|
"Output3":"211",
|
||||||
"Output4":"212",
|
"Output4":"212",
|
||||||
"Output5":"213",
|
"Output5":"213",
|
||||||
"Output6":"214",
|
"Output6":"214",
|
||||||
"Output7":"215",
|
"Output7":"215",
|
||||||
"LED 0 / Relay 0":"200",
|
"LED 0 / Relay 0":"200",
|
||||||
"LED 1 / Relay 1":"201",
|
"LED 1 / Relay 1":"201",
|
||||||
"LED 2":"202",
|
"LED 2":"202",
|
||||||
"LED 3":"203",
|
"LED 3":"203",
|
||||||
"LED 4":"204",
|
"LED 4":"204",
|
||||||
"LED 5":"205",
|
"LED 5":"205",
|
||||||
"LED 6":"206",
|
"LED 6":"206",
|
||||||
"LED 7":"207"
|
"LED 7":"207"
|
||||||
}
|
}
|
||||||
|
|
||||||
function PiFACEInNode(n) {
|
function PiFACEInNode(n) {
|
||||||
|
@ -18,7 +18,7 @@ module.exports = function(RED) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
var util = require("util");
|
var util = require("util");
|
||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
var gpioCommand = __dirname+'/nrgpio';
|
var gpioCommand = __dirname+'/nrgpio';
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ module.exports = function(RED) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
var util = require("util");
|
var util = require("util");
|
||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
var gpioCommand = __dirname+'/nrgpio';
|
var gpioCommand = __dirname+'/nrgpio';
|
||||||
|
|
||||||
|
@ -35,38 +35,38 @@ module.exports = function(RED) {
|
|||||||
if (blink1) {
|
if (blink1) {
|
||||||
var r,g,b;
|
var r,g,b;
|
||||||
try {
|
try {
|
||||||
if (p1.test(msg.payload)) {
|
if (p1.test(msg.payload)) {
|
||||||
// if it is a hex colour string
|
// if it is a hex colour string
|
||||||
r = parseInt(msg.payload.slice(1,3),16);
|
r = parseInt(msg.payload.slice(1,3),16);
|
||||||
g = parseInt(msg.payload.slice(3,5),16);
|
g = parseInt(msg.payload.slice(3,5),16);
|
||||||
b = parseInt(msg.payload.slice(5),16);
|
b = parseInt(msg.payload.slice(5),16);
|
||||||
if (node.fade === 0) { blink1.setRGB( r, g, b ); }
|
|
||||||
else { blink1.fadeToRGB(node.fade, r, g, b ); }
|
|
||||||
}
|
|
||||||
else if (p2.test(msg.payload)) {
|
|
||||||
// if it is a r,g,b triple
|
|
||||||
var rgb = msg.payload.split(',');
|
|
||||||
if (node.fade === 0) { blink1.setRGB(parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255); }
|
|
||||||
else { blink1.fadeToRGB(node.fade, parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255); }
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// you can add fancy colours by name here if you want...
|
|
||||||
// these are the @cheerlight ones.
|
|
||||||
var colors = {"red":"#FF0000","green":"#00FF00","blue":"#0000FF","cyan":"#00FFFF",
|
|
||||||
"white":"#FFFFFF","warmwhite":"#FDF5E6","oldlace":"#FDF5E6","purple":"#800080","magenta":"#FF00FF",
|
|
||||||
"yellow":"#FFFF00","amber":"#FFD200","orange":"#FFA500","black":"#000000","pink":"#FF69B4"}
|
|
||||||
if (msg.payload.toLowerCase() in colors) {
|
|
||||||
var c = colors[msg.payload.toLowerCase()];
|
|
||||||
r = parseInt(c.slice(1,3),16);
|
|
||||||
g = parseInt(c.slice(3,5),16);
|
|
||||||
b = parseInt(c.slice(5),16);
|
|
||||||
if (node.fade === 0) { blink1.setRGB( r, g, b ); }
|
if (node.fade === 0) { blink1.setRGB( r, g, b ); }
|
||||||
else { blink1.fadeToRGB(node.fade, r, g, b ); }
|
else { blink1.fadeToRGB(node.fade, r, g, b ); }
|
||||||
}
|
}
|
||||||
else {
|
else if (p2.test(msg.payload)) {
|
||||||
node.warn("Blink1 : invalid msg : "+msg.payload);
|
// if it is a r,g,b triple
|
||||||
|
var rgb = msg.payload.split(',');
|
||||||
|
if (node.fade === 0) { blink1.setRGB(parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255); }
|
||||||
|
else { blink1.fadeToRGB(node.fade, parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255); }
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// you can add fancy colours by name here if you want...
|
||||||
|
// these are the @cheerlight ones.
|
||||||
|
var colors = {"red":"#FF0000","green":"#00FF00","blue":"#0000FF","cyan":"#00FFFF",
|
||||||
|
"white":"#FFFFFF","warmwhite":"#FDF5E6","oldlace":"#FDF5E6","purple":"#800080","magenta":"#FF00FF",
|
||||||
|
"yellow":"#FFFF00","amber":"#FFD200","orange":"#FFA500","black":"#000000","pink":"#FF69B4"}
|
||||||
|
if (msg.payload.toLowerCase() in colors) {
|
||||||
|
var c = colors[msg.payload.toLowerCase()];
|
||||||
|
r = parseInt(c.slice(1,3),16);
|
||||||
|
g = parseInt(c.slice(3,5),16);
|
||||||
|
b = parseInt(c.slice(5),16);
|
||||||
|
if (node.fade === 0) { blink1.setRGB( r, g, b ); }
|
||||||
|
else { blink1.fadeToRGB(node.fade, r, g, b ); }
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
node.warn("Blink1 : invalid msg : "+msg.payload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (e) { node.error("Blink1 : error"); blink1 = null; }
|
} catch (e) { node.error("Blink1 : error"); blink1 = null; }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -148,8 +148,8 @@ module.exports = function(RED) {
|
|||||||
for (var key in message.payload) {
|
for (var key in message.payload) {
|
||||||
if (message.payload.hasOwnProperty(key)) {
|
if (message.payload.hasOwnProperty(key)) {
|
||||||
// Ensure our valid keys contain valid values
|
// Ensure our valid keys contain valid values
|
||||||
switch(key) {
|
switch (key) {
|
||||||
case "runmode" :
|
case "runmode" : {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
hminnode.log("Hit the runmode case");
|
hminnode.log("Hit the runmode case");
|
||||||
}
|
}
|
||||||
@ -158,8 +158,9 @@ module.exports = function(RED) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
//case "holiday" :
|
//case "holiday" : {
|
||||||
//if (DEBUG) {
|
//if (DEBUG) {
|
||||||
//hminnode.log("Hit the holiday case");
|
//hminnode.log("Hit the holiday case");
|
||||||
//}
|
//}
|
||||||
@ -183,8 +184,9 @@ module.exports = function(RED) {
|
|||||||
//message.payload.away_mode = 0;
|
//message.payload.away_mode = 0;
|
||||||
//}
|
//}
|
||||||
//break;
|
//break;
|
||||||
|
// }
|
||||||
|
|
||||||
//case "hotwater" :
|
//case "hotwater" : {
|
||||||
//if (DEBUG) {
|
//if (DEBUG) {
|
||||||
//hminnode.log("Hit the hotwater case");
|
//hminnode.log("Hit the hotwater case");
|
||||||
//}
|
//}
|
||||||
@ -193,8 +195,9 @@ module.exports = function(RED) {
|
|||||||
//return;
|
//return;
|
||||||
//}
|
//}
|
||||||
//break;
|
//break;
|
||||||
|
// }
|
||||||
|
|
||||||
case "heating" :
|
case "heating" : {
|
||||||
// Ensure heating stays last! It's got a multi write scenario
|
// Ensure heating stays last! It's got a multi write scenario
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
hminnode.log("Hit the heating case");
|
hminnode.log("Hit the heating case");
|
||||||
@ -226,9 +229,11 @@ module.exports = function(RED) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default :
|
default : {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Valid set of key messages, construct DCB and write
|
// Valid set of key messages, construct DCB and write
|
||||||
var dcb = message.payload;
|
var dcb = message.payload;
|
||||||
|
@ -55,7 +55,7 @@ function BleScan(n) {
|
|||||||
msg.payload = "not found";
|
msg.payload = "not found";
|
||||||
|
|
||||||
//check for the device name and the UUID (first one from the UUID list)
|
//check for the device name and the UUID (first one from the UUID list)
|
||||||
if(peripheral.advertisement.localName==node.ble_name && peripheral.advertisement.serviceUuids[0]==node.ble_uuid) {
|
if (peripheral.advertisement.localName==node.ble_name && peripheral.advertisement.serviceUuids[0]==node.ble_uuid) {
|
||||||
msg.payload=peripheral.advertisement.localName;
|
msg.payload=peripheral.advertisement.localName;
|
||||||
noble.stopScanning();
|
noble.stopScanning();
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,8 @@ function sensorTagNode(n) {
|
|||||||
var node=this;
|
var node=this;
|
||||||
|
|
||||||
if ( typeof node.stag == "undefined") {
|
if ( typeof node.stag == "undefined") {
|
||||||
//console.log("starting");
|
//console.log("starting");
|
||||||
SensorTag.discover(function(sensorTag){
|
SensorTag.discover(function(sensorTag){
|
||||||
node.stag = sensorTag;
|
node.stag = sensorTag;
|
||||||
sensorTag.connect(function(){
|
sensorTag.connect(function(){
|
||||||
//console.log("connected");
|
//console.log("connected");
|
||||||
@ -49,11 +49,11 @@ function sensorTagNode(n) {
|
|||||||
sensorTag.enableIrTemperature(function(){});
|
sensorTag.enableIrTemperature(function(){});
|
||||||
sensorTag.on('irTemperatureChange',
|
sensorTag.on('irTemperatureChange',
|
||||||
function(objectTemperature, ambientTemperature){
|
function(objectTemperature, ambientTemperature){
|
||||||
var msg = {'topic': node.topic + '/temperature'};
|
var msg = {'topic': node.topic + '/temperature'};
|
||||||
msg.payload = {'object': objectTemperature.toFixed(1),
|
msg.payload = {'object': objectTemperature.toFixed(1),
|
||||||
'ambient':ambientTemperature.toFixed(1)
|
'ambient':ambientTemperature.toFixed(1)
|
||||||
};
|
};
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
});
|
});
|
||||||
sensorTag.enableBarometricPressure(function(){});
|
sensorTag.enableBarometricPressure(function(){});
|
||||||
sensorTag.on('barometricPressureChange', function(pressure){
|
sensorTag.on('barometricPressureChange', function(pressure){
|
||||||
@ -71,34 +71,34 @@ function sensorTagNode(n) {
|
|||||||
});
|
});
|
||||||
sensorTag.enableAccelerometer(function(){});
|
sensorTag.enableAccelerometer(function(){});
|
||||||
sensorTag.on('accelerometerChange', function(x,y,z){
|
sensorTag.on('accelerometerChange', function(x,y,z){
|
||||||
var msg = {'topic': node.topic + '/accelerometer'};
|
var msg = {'topic': node.topic + '/accelerometer'};
|
||||||
msg.payload = {'x': x, 'y': y, 'z': z};
|
msg.payload = {'x': x, 'y': y, 'z': z};
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
});
|
});
|
||||||
sensorTag.enableMagnetometer(function() {});
|
sensorTag.enableMagnetometer(function() {});
|
||||||
sensorTag.on('magnetometerChange', function(x,y,z){
|
sensorTag.on('magnetometerChange', function(x,y,z){
|
||||||
var msg = {'topic': node.topic + '/magnetometer'};
|
var msg = {'topic': node.topic + '/magnetometer'};
|
||||||
msg.payload = {'x': x, 'y': y, 'z': z};
|
msg.payload = {'x': x, 'y': y, 'z': z};
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
});
|
});
|
||||||
sensorTag.enableGyroscope(function(){});
|
sensorTag.enableGyroscope(function(){});
|
||||||
sensorTag.on('gyroscopeChange', function(x,y,z){
|
sensorTag.on('gyroscopeChange', function(x,y,z){
|
||||||
var msg = {'topic': node.topic + '/gyroscope'};
|
var msg = {'topic': node.topic + '/gyroscope'};
|
||||||
msg.payload = {'x': x, 'y': y, 'z': z};
|
msg.payload = {'x': x, 'y': y, 'z': z};
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
});
|
});
|
||||||
sensorTag.on('simpleKeyChange', function(left, right){
|
sensorTag.on('simpleKeyChange', function(left, right){
|
||||||
var msg = {'topic': node.topic + '/keys'};
|
var msg = {'topic': node.topic + '/keys'};
|
||||||
msg.payload = {'left': left, 'right': right};
|
msg.payload = {'left': left, 'right': right};
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
});
|
});
|
||||||
enable(node);
|
enable(node);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},node.uuid);
|
},node.uuid);
|
||||||
} else {
|
} else {
|
||||||
//console.log("reconfig");
|
//console.log("reconfig");
|
||||||
enable(node);
|
enable(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,37 +106,37 @@ function enable(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.keys) {
|
if (node.keys) {
|
||||||
node.stag.notifySimpleKey(function() {});
|
node.stag.notifySimpleKey(function() {});
|
||||||
} else {
|
} else {
|
||||||
node.stag.unnotifySimpleKey(function() {});
|
node.stag.unnotifySimpleKey(function() {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("sensorTag",sensorTagNode);
|
RED.nodes.registerType("sensorTag",sensorTagNode);
|
||||||
|
@ -43,17 +43,17 @@ module.exports = function(RED) {
|
|||||||
else { http = require("http"); }
|
else { http = require("http"); }
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
this.url = this.baseurl + '/input/post.json?';
|
this.url = this.baseurl + '/input/post.json?';
|
||||||
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;
|
||||||
}
|
}
|
||||||
this.url += '&apikey='+this.apikey;
|
this.url += '&apikey='+this.apikey;
|
||||||
var nodegroup = this.nodegroup || msg.nodegroup;
|
var nodegroup = this.nodegroup || msg.nodegroup;
|
||||||
if(nodegroup !== ""){
|
if (nodegroup !== ""){
|
||||||
this.url += '&node=' + nodegroup;
|
this.url += '&node=' + nodegroup;
|
||||||
}
|
}
|
||||||
if(typeof msg.time !== 'undefined'){
|
if (typeof msg.time !== 'undefined'){
|
||||||
this.url += '&time=' + msg.time;
|
this.url += '&time=' + msg.time;
|
||||||
}
|
}
|
||||||
node.log("[emoncms] "+this.url);
|
node.log("[emoncms] "+this.url);
|
||||||
|
@ -39,7 +39,7 @@ module.exports = function(RED) {
|
|||||||
line += data.toString();
|
line += data.toString();
|
||||||
});
|
});
|
||||||
//ex.stderr.on('data', function (data) {
|
//ex.stderr.on('data', function (data) {
|
||||||
//console.log('[ping] stderr: ' + data);
|
//console.log('[ping] stderr: ' + data);
|
||||||
//});
|
//});
|
||||||
ex.on('close', function (code) {
|
ex.on('close', function (code) {
|
||||||
var m = regex.exec(line)||"";
|
var m = regex.exec(line)||"";
|
||||||
|
@ -22,22 +22,22 @@ module.exports = function(RED) {
|
|||||||
function DweetioOutNode(n) {
|
function DweetioOutNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.thing = n.thing;
|
this.thing = n.thing;
|
||||||
if (dweetio == null) { dweetio = new DweetClient(); }
|
if (dweetio == null) { dweetio = new DweetClient(); }
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
this.on("input",function(msg) {
|
this.on("input",function(msg) {
|
||||||
//if (typeof(msg.payload) === 'object') {
|
//if (typeof(msg.payload) === 'object') {
|
||||||
var thing = node.thing || msg.thing;
|
var thing = node.thing || msg.thing;
|
||||||
try {
|
try {
|
||||||
dweetio.dweet_for(thing, {payload:msg.payload}, function(err, dweet) {
|
dweetio.dweet_for(thing, {payload:msg.payload}, function(err, dweet) {
|
||||||
//console.log(dweet.thing); // "my-thing"
|
//console.log(dweet.thing); // "my-thing"
|
||||||
//console.log(dweet.content); // The content of the dweet
|
//console.log(dweet.content); // The content of the dweet
|
||||||
//console.log(dweet.created); // The create date of the dweet
|
//console.log(dweet.created); // The create date of the dweet
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
node.log(err);
|
node.log(err);
|
||||||
}
|
}
|
||||||
//} else { node.warn("Dweetio only sends payload objects."); }
|
//} else { node.warn("Dweetio only sends payload objects."); }
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ module.exports = function(RED) {
|
|||||||
function DweetioInNode(n) {
|
function DweetioInNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.thing = n.thing;
|
this.thing = n.thing;
|
||||||
if (dweetio == null) { dweetio = new DweetClient(); }
|
if (dweetio == null) { dweetio = new DweetClient(); }
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
dweetio.listen_for(node.thing, function(dweet){
|
dweetio.listen_for(node.thing, function(dweet){
|
||||||
@ -55,7 +55,7 @@ module.exports = function(RED) {
|
|||||||
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;
|
||||||
node.send(dweet);
|
node.send(dweet);
|
||||||
|
@ -32,7 +32,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
else { msg.payload = msg.payload.toString(); }
|
else { msg.payload = msg.payload.toString(); }
|
||||||
if (node.pushkey) {
|
if (node.pushkey) {
|
||||||
nma({
|
nma({
|
||||||
"apikey": node.pushkey,
|
"apikey": node.pushkey,
|
||||||
"application": "Node-RED",
|
"application": "Node-RED",
|
||||||
"event": titl,
|
"event": titl,
|
||||||
|
@ -24,9 +24,9 @@ module.exports = function(RED) {
|
|||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
function onError(err, node) {
|
function onError(err, node) {
|
||||||
if(err && node) {
|
if (err && node) {
|
||||||
if(node.emitter) {
|
if (node.emitter) {
|
||||||
if(!node.emitter.emit('error', err)) {
|
if (!node.emitter.emit('error', err)) {
|
||||||
node.error(err);
|
node.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,11 +61,11 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
// sort migration from old node
|
// sort migration from old node
|
||||||
var apikey;
|
var apikey;
|
||||||
if(this.n._migrate) {
|
if (this.n._migrate) {
|
||||||
apikey = this.n._apikey;
|
apikey = this.n._apikey;
|
||||||
this.credentials = {apikey:apikey};
|
this.credentials = {apikey:apikey};
|
||||||
}
|
}
|
||||||
else if(this.credentials) {
|
else if (this.credentials) {
|
||||||
apikey = this.credentials.apikey;
|
apikey = this.credentials.apikey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ module.exports = function(RED) {
|
|||||||
// get 'me' info
|
// get 'me' info
|
||||||
this.me = when.promise(function(resolve, reject) {
|
this.me = when.promise(function(resolve, reject) {
|
||||||
pusher.me(function(err, me) {
|
pusher.me(function(err, me) {
|
||||||
if(err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
resolve(me);
|
resolve(me);
|
||||||
@ -87,7 +87,7 @@ module.exports = function(RED) {
|
|||||||
// get latest timestamp
|
// get latest timestamp
|
||||||
this.last = when.promise(function(resolve) {
|
this.last = when.promise(function(resolve) {
|
||||||
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 {
|
||||||
@ -121,13 +121,13 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
PushbulletConfig.prototype.setupStream = function() {
|
PushbulletConfig.prototype.setupStream = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
if(this.pusher) {
|
if (this.pusher) {
|
||||||
var stream = this.pusher.stream();
|
var stream = this.pusher.stream();
|
||||||
stream.on('message', function(res) {
|
stream.on('message', function(res) {
|
||||||
if(res.type === 'tickle') {
|
if (res.type === 'tickle') {
|
||||||
self.handleTickle(res);
|
self.handleTickle(res);
|
||||||
}
|
}
|
||||||
else if(res.type === 'push') {
|
else if (res.type === 'push') {
|
||||||
self.pushMsg(res.push);
|
self.pushMsg(res.push);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -144,7 +144,7 @@ module.exports = function(RED) {
|
|||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
this.on("close",function() {
|
this.on("close",function() {
|
||||||
try {
|
try {
|
||||||
this.stream.close();
|
this.stream.close();
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
// Ignore error if not connected
|
// Ignore error if not connected
|
||||||
}
|
}
|
||||||
@ -156,16 +156,16 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
PushbulletConfig.prototype.handleTickle = function(ticklemsg) {
|
PushbulletConfig.prototype.handleTickle = function(ticklemsg) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if(this.pusher && ticklemsg.subtype === "push") {
|
if (this.pusher && ticklemsg.subtype === "push") {
|
||||||
var lastprom = this.last;
|
var lastprom = this.last;
|
||||||
this.last = when.promise(function(resolve) {
|
this.last = when.promise(function(resolve) {
|
||||||
when(lastprom).then(function(last) {
|
when(lastprom).then(function(last) {
|
||||||
self.pusher.history({modified_after: last}, function(err, res) {
|
self.pusher.history({modified_after: last}, function(err, res) {
|
||||||
if(err) {
|
if (err) {
|
||||||
resolve(last);
|
resolve(last);
|
||||||
return onError(err);
|
return onError(err);
|
||||||
}
|
}
|
||||||
for(var i=0;i<res.pushes.length; i++) {
|
for (var i=0;i<res.pushes.length; i++) {
|
||||||
self.pushMsg(res.pushes[i]);
|
self.pushMsg(res.pushes[i]);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -180,7 +180,7 @@ module.exports = function(RED) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PushbulletConfig.prototype.pushMsg = function(incoming) {
|
PushbulletConfig.prototype.pushMsg = function(incoming) {
|
||||||
if(this._inputNodes.length === 0) {
|
if (this._inputNodes.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,48 +189,48 @@ module.exports = function(RED) {
|
|||||||
data: incoming
|
data: incoming
|
||||||
}
|
}
|
||||||
|
|
||||||
if(incoming.dismissed === true) {
|
if (incoming.dismissed === true) {
|
||||||
msg.pushtype = 'dismissal';
|
msg.pushtype = 'dismissal';
|
||||||
msg.topic = 'Push dismissed';
|
msg.topic = 'Push dismissed';
|
||||||
msg.payload = incoming.iden;
|
msg.payload = incoming.iden;
|
||||||
}
|
}
|
||||||
else if(incoming.active === false && incoming.type === undefined) {
|
else if (incoming.active === false && incoming.type === undefined) {
|
||||||
msg.pushtype = 'delete';
|
msg.pushtype = 'delete';
|
||||||
msg.topic = 'Push deleted';
|
msg.topic = 'Push deleted';
|
||||||
msg.payload = incoming.iden;
|
msg.payload = incoming.iden;
|
||||||
}
|
}
|
||||||
else if(incoming.type === 'clip') {
|
else if (incoming.type === 'clip') {
|
||||||
msg.topic = 'Clipboard content';
|
msg.topic = 'Clipboard content';
|
||||||
msg.payload = incoming.body;
|
msg.payload = incoming.body;
|
||||||
}
|
}
|
||||||
else if(incoming.type === 'note') {
|
else if (incoming.type === 'note') {
|
||||||
msg.topic = incoming.title;
|
msg.topic = incoming.title;
|
||||||
msg.payload = incoming.body;
|
msg.payload = incoming.body;
|
||||||
}
|
}
|
||||||
else if(incoming.type === 'link') {
|
else if (incoming.type === 'link') {
|
||||||
msg.topic = incoming.title;
|
msg.topic = incoming.title;
|
||||||
msg.payload = incoming.url;
|
msg.payload = incoming.url;
|
||||||
msg.message = incoming.body;
|
msg.message = incoming.body;
|
||||||
}
|
}
|
||||||
else if(incoming.type === 'address') {
|
else if (incoming.type === 'address') {
|
||||||
msg.topic = incoming.name;
|
msg.topic = incoming.name;
|
||||||
msg.payload = incoming.address;
|
msg.payload = incoming.address;
|
||||||
}
|
}
|
||||||
else if(incoming.type === 'list') {
|
else if (incoming.type === 'list') {
|
||||||
msg.topic = incoming.title;
|
msg.topic = incoming.title;
|
||||||
msg.payload = incoming.items;
|
msg.payload = incoming.items;
|
||||||
}
|
}
|
||||||
else if(incoming.type === 'file') {
|
else if (incoming.type === 'file') {
|
||||||
msg.topic = incoming.file_name;
|
msg.topic = incoming.file_name;
|
||||||
msg.payload = incoming.file_url;
|
msg.payload = incoming.file_url;
|
||||||
msg.message = incoming.body;
|
msg.message = incoming.body;
|
||||||
}
|
}
|
||||||
// Android specific, untested
|
// Android specific, untested
|
||||||
else if(incoming.type === 'mirror') {
|
else if (incoming.type === 'mirror') {
|
||||||
msg.topic = incoming.title;
|
msg.topic = incoming.title;
|
||||||
msg.payload = incoming.body;
|
msg.payload = incoming.body;
|
||||||
}
|
}
|
||||||
else if(incoming.type === 'dismissal') {
|
else if (incoming.type === 'dismissal') {
|
||||||
msg.topic = "dismissal";
|
msg.topic = "dismissal";
|
||||||
msg.topic = "Push dismissed";
|
msg.topic = "Push dismissed";
|
||||||
msg.payload = incoming.iden;
|
msg.payload = incoming.iden;
|
||||||
@ -246,14 +246,14 @@ module.exports = function(RED) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PushbulletConfig.prototype.registerInputNode = function(/*Node*/handler) {
|
PushbulletConfig.prototype.registerInputNode = function(/*Node*/handler) {
|
||||||
if(!this.stream) {
|
if (!this.stream) {
|
||||||
this.setupStream();
|
this.setupStream();
|
||||||
}
|
}
|
||||||
this._inputNodes.push(handler);
|
this._inputNodes.push(handler);
|
||||||
};
|
};
|
||||||
|
|
||||||
function migrateOldSettings(n) {
|
function migrateOldSettings(n) {
|
||||||
if(n.config === undefined) {
|
if (n.config === undefined) {
|
||||||
var newid, config, apikey, deviceid, pushkeys;
|
var newid, config, apikey, deviceid, pushkeys;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -264,10 +264,10 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
var cred = RED.nodes.getCredentials(n.id);
|
var cred = RED.nodes.getCredentials(n.id);
|
||||||
// get old apikey
|
// get old apikey
|
||||||
if(cred && cred.hasOwnProperty("pushkey")) {
|
if (cred && cred.hasOwnProperty("pushkey")) {
|
||||||
apikey = cred.pushkey;
|
apikey = cred.pushkey;
|
||||||
}
|
}
|
||||||
else if(pushkeys) {
|
else if (pushkeys) {
|
||||||
apikey = pushkeys.pushbullet;
|
apikey = pushkeys.pushbullet;
|
||||||
}
|
}
|
||||||
// get old device
|
// get old device
|
||||||
@ -278,7 +278,7 @@ module.exports = function(RED) {
|
|||||||
deviceid = pushkeys.deviceid;
|
deviceid = pushkeys.deviceid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(apikey) {
|
if (apikey) {
|
||||||
newid = (1+Math.random()*4294967295).toString(16);
|
newid = (1+Math.random()*4294967295).toString(16);
|
||||||
config = new PushbulletConfig({
|
config = new PushbulletConfig({
|
||||||
id: newid,
|
id: newid,
|
||||||
@ -289,7 +289,7 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(apikey || deviceid)) {
|
if (!(apikey || deviceid)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +317,7 @@ module.exports = function(RED) {
|
|||||||
this.pusher = null;
|
this.pusher = null;
|
||||||
|
|
||||||
var configNode;
|
var configNode;
|
||||||
if(this.migrated) {
|
if (this.migrated) {
|
||||||
this.warn('Settings migrated from previous version of Pushbullet Node, please edit node to update settings.');
|
this.warn('Settings migrated from previous version of Pushbullet Node, please edit node to update settings.');
|
||||||
this.status({fill: 'yellow', shape: 'ring', text: 'Node migrated'});
|
this.status({fill: 'yellow', shape: 'ring', text: 'Node migrated'});
|
||||||
this.deviceid = this.migrated.deviceid;
|
this.deviceid = this.migrated.deviceid;
|
||||||
@ -332,7 +332,7 @@ module.exports = function(RED) {
|
|||||||
catch(err){}
|
catch(err){}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(configNode) {
|
if (configNode) {
|
||||||
configNode.initialise();
|
configNode.initialise();
|
||||||
this.pusher = configNode.pusher;
|
this.pusher = configNode.pusher;
|
||||||
configNode.onConfig('error', function(err) {
|
configNode.onConfig('error', function(err) {
|
||||||
@ -341,23 +341,23 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
var title = self.title || msg.topic || "Node-RED";
|
var title = self.title || msg.topic || "Node-RED";
|
||||||
var deviceid = (self.deviceid === '_msg_')? (msg.deviceid || ""): (self.deviceid || "");
|
var deviceid = (self.deviceid === '_msg_')? (msg.deviceid || ""): (self.deviceid || "");
|
||||||
var pushtype = self.pushtype || msg.pushtype || "note";
|
var pushtype = self.pushtype || msg.pushtype || "note";
|
||||||
var channel = self.chan || msg.channel;
|
var channel = self.chan || msg.channel;
|
||||||
|
|
||||||
if (typeof(msg.payload) === 'object') {
|
if (typeof(msg.payload) === 'object') {
|
||||||
msg.payload = JSON.stringify(msg.payload);
|
msg.payload = JSON.stringify(msg.payload);
|
||||||
}
|
}
|
||||||
else if(msg.payload) {
|
else if (msg.payload) {
|
||||||
msg.payload = msg.payload.toString();
|
msg.payload = msg.payload.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(['delete', 'dismissal', 'updatelist', '_rawupdate_'].indexOf(pushtype) === -1) {
|
if (['delete', 'dismissal', 'updatelist', '_rawupdate_'].indexOf(pushtype) === -1) {
|
||||||
if (channel) {
|
if (channel) {
|
||||||
deviceid = { channel_tag : channel };
|
deviceid = { channel_tag : channel };
|
||||||
}
|
}
|
||||||
else if(deviceid === "") {
|
else if (deviceid === "") {
|
||||||
try {
|
try {
|
||||||
when(configNode.me).then(function(me) {
|
when(configNode.me).then(function(me) {
|
||||||
if (me) {
|
if (me) {
|
||||||
@ -392,24 +392,24 @@ module.exports = function(RED) {
|
|||||||
if (this.pusher) {
|
if (this.pusher) {
|
||||||
var handleErr = function(msg){
|
var handleErr = function(msg){
|
||||||
return function(err) {
|
return function(err) {
|
||||||
if(err) {
|
if (err) {
|
||||||
self.error(msg);
|
self.error(msg);
|
||||||
onError(err, self);
|
onError(err, self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deviceid) {
|
if (deviceid) {
|
||||||
if(pushtype === 'note') {
|
if (pushtype === 'note') {
|
||||||
this.pusher.note(deviceid, title, msg.payload, handleErr('Unable to push note'));
|
this.pusher.note(deviceid, title, msg.payload, handleErr('Unable to push note'));
|
||||||
}
|
}
|
||||||
else if(pushtype === 'address') {
|
else if (pushtype === 'address') {
|
||||||
this.pusher.address(deviceid, title, msg.payload, handleErr('Unable to push address'));
|
this.pusher.address(deviceid, title, msg.payload, handleErr('Unable to push address'));
|
||||||
}
|
}
|
||||||
else if(pushtype === 'list') {
|
else if (pushtype === 'list') {
|
||||||
this.pusher.list(deviceid, title, JSON.parse(msg.payload), handleErr('Unable to push list'));
|
this.pusher.list(deviceid, title, JSON.parse(msg.payload), handleErr('Unable to push list'));
|
||||||
}
|
}
|
||||||
else if(pushtype === 'link') {
|
else if (pushtype === 'link') {
|
||||||
this.pusher.push(deviceid, {
|
this.pusher.push(deviceid, {
|
||||||
type: 'link',
|
type: 'link',
|
||||||
title: title,
|
title: title,
|
||||||
@ -417,31 +417,31 @@ module.exports = function(RED) {
|
|||||||
url: msg.payload
|
url: msg.payload
|
||||||
}, handleErr('Unable to push link'));
|
}, handleErr('Unable to push link'));
|
||||||
}
|
}
|
||||||
else if(pushtype === 'file') {
|
else if (pushtype === 'file') {
|
||||||
// Workaround for Pushbullet dep not handling error on file open
|
// Workaround for Pushbullet dep not handling error on file open
|
||||||
if(fs.existsSync(msg.payload)) {
|
if (fs.existsSync(msg.payload)) {
|
||||||
this.pusher.file(deviceid, msg.payload, title, handleErr('Unable to push file'));
|
this.pusher.file(deviceid, msg.payload, title, handleErr('Unable to push file'));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.error('File does not exist!');
|
this.error('File does not exist!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(pushtype === '_raw_') {
|
else if (pushtype === '_raw_') {
|
||||||
this.pusher.push(deviceid, msg.raw, handleErr('Unable to push raw data'));
|
this.pusher.push(deviceid, msg.raw, handleErr('Unable to push raw data'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(msg.data && msg.data.iden) {
|
if (msg.data && msg.data.iden) {
|
||||||
if(pushtype === 'delete') {
|
if (pushtype === 'delete') {
|
||||||
this.pusher.deletePush(msg.data.iden, handleErr('Unable to delete push'));
|
this.pusher.deletePush(msg.data.iden, handleErr('Unable to delete push'));
|
||||||
}
|
}
|
||||||
else if(pushtype === 'dismissal') {
|
else if (pushtype === 'dismissal') {
|
||||||
this.pusher.updatePush(msg.data.iden, {dismissed: true}, handleErr('Unable to dismiss push'));
|
this.pusher.updatePush(msg.data.iden, {dismissed: true}, handleErr('Unable to dismiss push'));
|
||||||
}
|
}
|
||||||
else if(pushtype === 'updatelist') {
|
else if (pushtype === 'updatelist') {
|
||||||
try {
|
try {
|
||||||
var data = JSON.parse(msg.payload);
|
var data = JSON.parse(msg.payload);
|
||||||
if(msg.data.type && msg.data.type !== 'list') {
|
if (msg.data.type && msg.data.type !== 'list') {
|
||||||
this.warn('Trying to update list items in non list push');
|
this.warn('Trying to update list items in non list push');
|
||||||
}
|
}
|
||||||
this.pusher.updatePush(msg.data.iden, {items: data}, handleErr('Unable to update list'));
|
this.pusher.updatePush(msg.data.iden, {items: data}, handleErr('Unable to update list'));
|
||||||
@ -450,7 +450,7 @@ module.exports = function(RED) {
|
|||||||
this.warn("Invalid list");
|
this.warn("Invalid list");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(pushtype === '_rawupdate_') {
|
else if (pushtype === '_rawupdate_') {
|
||||||
this.pusher.updatePush(msg.data.iden, msg.raw, handleErr('Unable to update raw data'));
|
this.pusher.updatePush(msg.data.iden, msg.raw, handleErr('Unable to update raw data'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -462,13 +462,13 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
RED.httpAdmin.get('/pushbullet/:id/migrate', function(req, res) {
|
RED.httpAdmin.get('/pushbullet/:id/migrate', function(req, res) {
|
||||||
var node = RED.nodes.getNode(req.params.id);
|
var node = RED.nodes.getNode(req.params.id);
|
||||||
if(node && node.migrated) {
|
if (node && node.migrated) {
|
||||||
if(req.query.save) {
|
if (req.query.save) {
|
||||||
var promise;
|
var promise;
|
||||||
if(node.migrated.apikey) {
|
if (node.migrated.apikey) {
|
||||||
promise = RED.nodes.addCredentials(node.migrated.id, {apikey: node.migrated.apikey});
|
promise = RED.nodes.addCredentials(node.migrated.id, {apikey: node.migrated.apikey});
|
||||||
}
|
}
|
||||||
if(node.migrated.deviceid) {
|
if (node.migrated.deviceid) {
|
||||||
when(promise).then(function() {
|
when(promise).then(function() {
|
||||||
RED.nodes.addCredentials(req.params.id, {deviceid: node.migrated.deviceid});
|
RED.nodes.addCredentials(req.params.id, {deviceid: node.migrated.deviceid});
|
||||||
});
|
});
|
||||||
@ -486,29 +486,29 @@ module.exports = function(RED) {
|
|||||||
var cred = RED.nodes.getCredentials(req.params.id);
|
var cred = RED.nodes.getCredentials(req.params.id);
|
||||||
var pb;
|
var pb;
|
||||||
|
|
||||||
if(config && config.pusher) {
|
if (config && config.pusher) {
|
||||||
config.pusher.devices(function(err, chans) {
|
config.pusher.devices(function(err, chans) {
|
||||||
if(err) {
|
if (err) {
|
||||||
res.send("[]");
|
res.send("[]");
|
||||||
return onError(err, config);
|
return onError(err, config);
|
||||||
}
|
}
|
||||||
res.send(JSON.stringify(chans.devices));
|
res.send(JSON.stringify(chans.devices));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if(cred && cred.apikey) {
|
else if (cred && cred.apikey) {
|
||||||
pb = new PushBullet(cred.apikey);
|
pb = new PushBullet(cred.apikey);
|
||||||
pb.devices(function(err, chans) {
|
pb.devices(function(err, chans) {
|
||||||
if(err) {
|
if (err) {
|
||||||
res.send("[]");
|
res.send("[]");
|
||||||
return onError(err, config);
|
return onError(err, config);
|
||||||
}
|
}
|
||||||
res.send(JSON.stringify(chans.devices));
|
res.send(JSON.stringify(chans.devices));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if(req.query.apikey) {
|
else if (req.query.apikey) {
|
||||||
pb = new PushBullet(req.query.apikey);
|
pb = new PushBullet(req.query.apikey);
|
||||||
pb.devices(function(err, chans) {
|
pb.devices(function(err, chans) {
|
||||||
if(err) {
|
if (err) {
|
||||||
res.send("[]");
|
res.send("[]");
|
||||||
return onError(err, config);
|
return onError(err, config);
|
||||||
}
|
}
|
||||||
@ -524,7 +524,7 @@ module.exports = function(RED) {
|
|||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
var self = this;
|
var self = this;
|
||||||
var config = RED.nodes.getNode(n.config);
|
var config = RED.nodes.getNode(n.config);
|
||||||
if(config) {
|
if (config) {
|
||||||
config.initialise();
|
config.initialise();
|
||||||
config.registerInputNode(this);
|
config.registerInputNode(this);
|
||||||
config.onConfig('error', function(err) {
|
config.onConfig('error', function(err) {
|
||||||
@ -550,8 +550,8 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
PushbulletIn.prototype.emitPush = function(msg) {
|
PushbulletIn.prototype.emitPush = function(msg) {
|
||||||
try {
|
try {
|
||||||
if(this.credentials.filters.length > 0) {
|
if (this.credentials.filters.length > 0) {
|
||||||
if( (this.credentials.filters.indexOf(msg.data.source_device_iden) > -1) ||
|
if ( (this.credentials.filters.indexOf(msg.data.source_device_iden) > -1) ||
|
||||||
(this.credentials.filters.indexOf(msg.data.target_device_iden) > -1) ||
|
(this.credentials.filters.indexOf(msg.data.target_device_iden) > -1) ||
|
||||||
(!msg.data.target_device_iden && !msg.data.source_device_iden)) { /* All */
|
(!msg.data.target_device_iden && !msg.data.source_device_iden)) { /* All */
|
||||||
this.send(msg);
|
this.send(msg);
|
||||||
|
@ -23,7 +23,7 @@ module.exports = function(RED) {
|
|||||||
var PusherClient = require('pusher-client');
|
var PusherClient = require('pusher-client');
|
||||||
|
|
||||||
//node for subscribing to an event/channel
|
//node for subscribing to an event/channel
|
||||||
function PusherNode(n) {
|
function PusherNode(n) {
|
||||||
// Create a RED node
|
// Create a RED node
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
|
||||||
@ -88,9 +88,9 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
this.on("close", function() {
|
this.on("close", function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//debugging on the output:
|
//debugging on the output:
|
||||||
var displayResult = function(result) {
|
var displayResult = function(result) {
|
||||||
node.log(result);
|
node.log(result);
|
||||||
};
|
};
|
||||||
|
@ -73,7 +73,7 @@ module.exports = function(RED) {
|
|||||||
try {
|
try {
|
||||||
// decide if we are to Send SMS
|
// decide if we are to Send SMS
|
||||||
var tonum = node.number || msg.topic;
|
var tonum = node.number || msg.topic;
|
||||||
if( this.twilioType == "call" ) {
|
if ( this.twilioType == "call" ) {
|
||||||
// Make a call
|
// Make a call
|
||||||
var twimlurl = node.url || msg.payload;
|
var twimlurl = node.url || msg.payload;
|
||||||
node.twilioClient.makeCall( {to: tonum, from: node.fromNumber, url: twimlurl}, function(err, response) {
|
node.twilioClient.makeCall( {to: tonum, from: node.fromNumber, url: twimlurl}, function(err, response) {
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var XMPP = require('simple-xmpp');
|
var XMPP = require('simple-xmpp');
|
||||||
|
|
||||||
function XMPPServerNode(n) {
|
function XMPPServerNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.server = n.server;
|
this.server = n.server;
|
||||||
this.port = n.port;
|
this.port = n.port;
|
||||||
@ -29,7 +29,7 @@ function XMPPServerNode(n) {
|
|||||||
this.password = credentials.password;
|
this.password = credentials.password;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("xmpp-server",XMPPServerNode,{
|
RED.nodes.registerType("xmpp-server",XMPPServerNode,{
|
||||||
credentials: {
|
credentials: {
|
||||||
user: {type:"text"},
|
user: {type:"text"},
|
||||||
password: {type: "password"}
|
password: {type: "password"}
|
||||||
@ -37,7 +37,7 @@ RED.nodes.registerType("xmpp-server",XMPPServerNode,{
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function XmppInNode(n) {
|
function XmppInNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.server = n.server;
|
this.server = n.server;
|
||||||
|
|
||||||
@ -75,9 +75,9 @@ function XmppInNode(n) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//xmpp.on('chatstate', function(from, state) {
|
//xmpp.on('chatstate', function(from, state) {
|
||||||
//console.log('%s is currently %s', from, state);
|
//console.log('%s is currently %s', from, state);
|
||||||
//var msg = { topic:from, payload:state };
|
//var msg = { topic:from, payload:state };
|
||||||
//node.send([null,msg]);
|
//node.send([null,msg]);
|
||||||
//});
|
//});
|
||||||
|
|
||||||
xmpp.on('buddy', function(jid, state, statusText) {
|
xmpp.on('buddy', function(jid, state, statusText) {
|
||||||
@ -102,10 +102,10 @@ function XmppInNode(n) {
|
|||||||
// Now actually make the connection
|
// Now actually make the connection
|
||||||
try {
|
try {
|
||||||
xmpp.connect({
|
xmpp.connect({
|
||||||
jid : node.userid,
|
jid : node.userid,
|
||||||
password : node.password,
|
password : node.password,
|
||||||
host : node.host,
|
host : node.host,
|
||||||
port : node.port,
|
port : node.port,
|
||||||
skipPresence : true,
|
skipPresence : true,
|
||||||
reconnect : false
|
reconnect : false
|
||||||
});
|
});
|
||||||
@ -121,9 +121,9 @@ function XmppInNode(n) {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("xmpp in",XmppInNode);
|
RED.nodes.registerType("xmpp in",XmppInNode);
|
||||||
|
|
||||||
function XmppOutNode(n) {
|
function XmppOutNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.server = n.server;
|
this.server = n.server;
|
||||||
|
|
||||||
@ -166,10 +166,10 @@ function XmppOutNode(n) {
|
|||||||
// Now actually make the connection
|
// Now actually make the connection
|
||||||
try {
|
try {
|
||||||
xmpp.connect({
|
xmpp.connect({
|
||||||
jid : node.userid,
|
jid : node.userid,
|
||||||
password : node.password,
|
password : node.password,
|
||||||
host : node.host,
|
host : node.host,
|
||||||
port : node.port,
|
port : node.port,
|
||||||
skipPresence : true,
|
skipPresence : true,
|
||||||
reconnect : false
|
reconnect : false
|
||||||
});
|
});
|
||||||
@ -207,6 +207,6 @@ function XmppOutNode(n) {
|
|||||||
xmpp = null;
|
xmpp = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("xmpp out",XmppOutNode);
|
RED.nodes.registerType("xmpp out",XmppOutNode);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user