From 5ec8147eb12cfb8b897b5dd632f259869caa6040 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Fri, 25 Oct 2013 18:22:45 +0100 Subject: [PATCH 01/22] Use environment variable to set path for nodes.... --- hardware/Pi/37-rpi-piface.html | 14 +-- hardware/Pi/37-rpi-piface.js | 192 ++++++++++++++++----------------- hardware/Pi/78-ledborg.html | 8 +- hardware/Pi/78-ledborg.js | 50 ++++----- io/ping/88-ping.js | 64 +++++------ time/79-suncalc.js | 3 +- 6 files changed, 166 insertions(+), 165 deletions(-) diff --git a/hardware/Pi/37-rpi-piface.html b/hardware/Pi/37-rpi-piface.html index 3e3ac043..36e91117 100644 --- a/hardware/Pi/37-rpi-piface.html +++ b/hardware/Pi/37-rpi-piface.html @@ -52,10 +52,10 @@ + + + + diff --git a/io/wol/39-wol.js b/io/wol/39-wol.js new file mode 100644 index 00000000..497474fc --- /dev/null +++ b/io/wol/39-wol.js @@ -0,0 +1,41 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require(process.env.NODE_RED_HOME+"/red/red"); +var wol = require('wake_on_lan'); +var chk = /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/; + +function WOLnode(n) { + RED.nodes.createNode(this,n); + this.mac = n.mac + var node = this; + + this.on("input", function(msg) { + if (msg != null) { + var mac = this.mac || msg.mac || null; + if (mac != null) { + if (chk.test(mac)) { + wol.wake(mac, function(error) { + if (error) { node.warn(error); } + }); + } + else { node.warn("WOL: bad mac address "+mac); } + } + else { node.warn("WOL: no mac address specified"); } + } + }); +} +RED.nodes.registerType("wake on lan",WOLnode); From 75aaaab1a9343a730157d8d4e0ca20230e352ef4 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Sat, 26 Oct 2013 22:19:43 +0100 Subject: [PATCH 03/22] update path to red.js to use environmnet variable --- hardware/digiRGB/78-digiRGB.js | 12 +++---- hardware/scanBLE/101-scanBLE.js | 50 +++++++++++++++--------------- hardware/sensorTag/79-sensorTag.js | 17 +++------- 3 files changed, 35 insertions(+), 44 deletions(-) diff --git a/hardware/digiRGB/78-digiRGB.js b/hardware/digiRGB/78-digiRGB.js index 717da0a3..226fc864 100644 --- a/hardware/digiRGB/78-digiRGB.js +++ b/hardware/digiRGB/78-digiRGB.js @@ -17,7 +17,7 @@ // Sample Node-RED node file // Require main module -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var HID = require('node-hid'); var device; var node; @@ -27,7 +27,7 @@ function DigiRGBNode(n) { // Create a RED node RED.nodes.createNode(this,n); node=this; - + var devices = HID.devices(0x16c0,0x05df); for (var i=0; i< devices.length; i++) { if (devices[i].product == 'DigiUSB') { @@ -39,13 +39,13 @@ function DigiRGBNode(n) { } catch (e) { node.log(e) } - } + } } - + var p1 = /^\#[A-Fa-f0-9]{6}$/ var p2 = /[0-9]+,[0-9]+,[0-9]+/ - - if (device) { + + if (device) { this.on("input", function(msg) { if (msg != null) { if (p1.test(msg.payload)) { diff --git a/hardware/scanBLE/101-scanBLE.js b/hardware/scanBLE/101-scanBLE.js index 04a308b5..24532e37 100644 --- a/hardware/scanBLE/101-scanBLE.js +++ b/hardware/scanBLE/101-scanBLE.js @@ -19,52 +19,52 @@ **/ //might need to modify accordingly -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); //import noble var noble = require('noble'); // The main node definition - most things happen in here function BleScan(n) { - // Create a RED node - RED.nodes.createNode(this,n); + // Create a RED node + RED.nodes.createNode(this,n); var msg = {}; - var ble_name; - var node = this; - + var ble_name; + var node = this; + //get name and uuid from user this.ble_name = n.ble_name; this.ble_uuid = n.ble_uuid; this.on("input", function(msg){ - noble.startScanning(); + noble.startScanning(); }); noble.on('scanStart', function(msg) { - var msg = {}; - msg.topic = node.topic; - msg.payload = "Scanning initiated..." //debugging - //console.log('scanning initiated...'); - node.send(msg); + var msg = {}; + msg.topic = node.topic; + msg.payload = "Scanning initiated..." //debugging + //console.log('scanning initiated...'); + node.send(msg); }); noble.on('discover', function(peripheral) { - var msg = {}; - msg.topic = node.topic; - msg.payload = "not found"; - - //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) { - msg.payload=peripheral.advertisement.localName; - noble.stopScanning(); } - node.send(msg); + var msg = {}; + msg.topic = node.topic; + msg.payload = "not found"; + + //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) { + msg.payload=peripheral.advertisement.localName; + noble.stopScanning(); } + node.send(msg); }); - this.on("close", function() { - try { noble.stopScanning(); } - catch (err) { console.log(err); } - }); + this.on("close", function() { + try { noble.stopScanning(); } + catch (err) { console.log(err); } + }); } // Register the node by name. This must be called before overriding any of the diff --git a/hardware/sensorTag/79-sensorTag.js b/hardware/sensorTag/79-sensorTag.js index 92555099..c1252983 100644 --- a/hardware/sensorTag/79-sensorTag.js +++ b/hardware/sensorTag/79-sensorTag.js @@ -14,17 +14,14 @@ * limitations under the License. **/ -// Sample Node-RED node file - // Require main module -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var SensorTag = require('sensortag'); var stag; var node; // The main node definition - most things happen in here function sensorTagNode(n) { - // Create a RED node RED.nodes.createNode(this,n); this.name = n.name; this.topic = n.topic; @@ -36,16 +33,16 @@ function sensorTagNode(n) { this.gyroscope = n.gyroscope; this.keys = n.keys; node=this; - + if ( typeof stag == "undefined") { //console.log("starting"); - SensorTag.discover(function(sensorTag){ + SensorTag.discover(function(sensorTag){ stag = sensorTag; sensorTag.connect(function(){ //console.log("connected"); sensorTag.discoverServicesAndCharacteristics(function(){ sensorTag.enableIrTemperature(function(){}); - sensorTag.on('irTemperatureChange', + sensorTag.on('irTemperatureChange', function(objectTemperature, ambientTemperature){ var msg = {'topic': node.topic + '/tempature'}; msg.payload = {'object': objectTemperature.toFixed(1), @@ -98,8 +95,6 @@ function sensorTagNode(n) { //console.log("reconfig"); enable(); } - - } function enable() { @@ -139,8 +134,4 @@ function enable() { stag.unnotifySimpleKey(function() {}); } } - -// Register the node by name. This must be called before overriding any of the -// Node functions. RED.nodes.registerType("sensorTag",sensorTagNode); - From 6a0d248f5a4598c3d2c8e8e12544a1a11e1e2f4e Mon Sep 17 00:00:00 2001 From: Nicholas O'Leary Date: Wed, 30 Oct 2013 20:38:23 +0000 Subject: [PATCH 04/22] Move nodes over from main repo --- analysis/wordpos/72-wordpos.html | 57 +++++++++++++ analysis/wordpos/72-wordpos.js | 34 ++++++++ hardware/blink/76-blinkstick.html | 50 +++++++++++ hardware/blink/76-blinkstick.js | 62 ++++++++++++++ hardware/blink/77-blink1.html | 52 ++++++++++++ hardware/blink/77-blink1.js | 60 +++++++++++++ social/notify/57-notify.html | 55 ++++++++++++ social/notify/57-notify.js | 39 +++++++++ social/prowl/57-prowl.html | 63 ++++++++++++++ social/prowl/57-prowl.js | 67 +++++++++++++++ social/prowl/icons/prowl.png | Bin 0 -> 1554 bytes social/pushbullet/57-pushbullet.html | 57 +++++++++++++ social/pushbullet/57-pushbullet.js | 64 ++++++++++++++ social/pushbullet/icons/bullet.png | Bin 0 -> 1075 bytes social/xmpp/92-xmpp.html | 80 ++++++++++++++++++ social/xmpp/92-xmpp.js | 118 ++++++++++++++++++++++++++ social/xmpp/icons/xmpp.png | Bin 0 -> 2358 bytes storage/leveldb/67-leveldb.html | 122 +++++++++++++++++++++++++++ storage/leveldb/67-leveldb.js | 93 ++++++++++++++++++++ 19 files changed, 1073 insertions(+) create mode 100644 analysis/wordpos/72-wordpos.html create mode 100644 analysis/wordpos/72-wordpos.js create mode 100644 hardware/blink/76-blinkstick.html create mode 100644 hardware/blink/76-blinkstick.js create mode 100644 hardware/blink/77-blink1.html create mode 100644 hardware/blink/77-blink1.js create mode 100644 social/notify/57-notify.html create mode 100644 social/notify/57-notify.js create mode 100644 social/prowl/57-prowl.html create mode 100644 social/prowl/57-prowl.js create mode 100644 social/prowl/icons/prowl.png create mode 100644 social/pushbullet/57-pushbullet.html create mode 100644 social/pushbullet/57-pushbullet.js create mode 100644 social/pushbullet/icons/bullet.png create mode 100644 social/xmpp/92-xmpp.html create mode 100644 social/xmpp/92-xmpp.js create mode 100644 social/xmpp/icons/xmpp.png create mode 100644 storage/leveldb/67-leveldb.html create mode 100644 storage/leveldb/67-leveldb.js diff --git a/analysis/wordpos/72-wordpos.html b/analysis/wordpos/72-wordpos.html new file mode 100644 index 00000000..b50156ea --- /dev/null +++ b/analysis/wordpos/72-wordpos.html @@ -0,0 +1,57 @@ + + + + + + + diff --git a/analysis/wordpos/72-wordpos.js b/analysis/wordpos/72-wordpos.js new file mode 100644 index 00000000..0725cb1e --- /dev/null +++ b/analysis/wordpos/72-wordpos.js @@ -0,0 +1,34 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require("../../red/red"); +var util = require("util"); +var WordPos = require('wordpos'); + +var wordpos = new WordPos(); + +function WordPOSNode(n) { + RED.nodes.createNode(this,n); + this.on("input", function(msg) { + var node = this; + wordpos.getPOS(msg.payload, function (result) { + msg.pos = result; + node.send(msg); + }); + }); +} + +RED.nodes.registerType("wordpos",WordPOSNode); diff --git a/hardware/blink/76-blinkstick.html b/hardware/blink/76-blinkstick.html new file mode 100644 index 00000000..1bef4306 --- /dev/null +++ b/hardware/blink/76-blinkstick.html @@ -0,0 +1,50 @@ + + + + + + + diff --git a/hardware/blink/76-blinkstick.js b/hardware/blink/76-blinkstick.js new file mode 100644 index 00000000..cae30ca8 --- /dev/null +++ b/hardware/blink/76-blinkstick.js @@ -0,0 +1,62 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require("../../red/red"); +var blinkstick = require("blinkstick"); + +Object.size = function(obj) { + var size = 0, key; + for (key in obj) { if (obj.hasOwnProperty(key)) size++; } + return size; +}; + +function BlinkStick(n) { + RED.nodes.createNode(this,n); + var p1 = /^\#[A-Fa-f0-9]{6}$/ + var p2 = /[0-9]+,[0-9]+,[0-9]+/ + this.led = blinkstick.findFirst(); // maybe try findAll() (one day) + var node = this; + + this.on("input", function(msg) { + if (msg != null) { + if (Object.size(node.led) !== 0) { + try { + if (p2.test(msg.payload)) { + var rgb = msg.payload.split(","); + node.led.setColor(parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255); + } + else { + node.led.setColor(msg.payload.toLowerCase().replace(/\s+/g,'')); + } + } + catch (err) { + node.warn("BlinkStick missing ?"); + node.led = blinkstick.findFirst(); + } + } + else { + //node.warn("No BlinkStick found"); + node.led = blinkstick.findFirst(); + } + } + }); + if (Object.size(node.led) === 0) { + node.error("No BlinkStick found"); + } + +} + +RED.nodes.registerType("blinkstick",BlinkStick); diff --git a/hardware/blink/77-blink1.html b/hardware/blink/77-blink1.html new file mode 100644 index 00000000..00579ce8 --- /dev/null +++ b/hardware/blink/77-blink1.html @@ -0,0 +1,52 @@ + + + + + + + diff --git a/hardware/blink/77-blink1.js b/hardware/blink/77-blink1.js new file mode 100644 index 00000000..236683ed --- /dev/null +++ b/hardware/blink/77-blink1.js @@ -0,0 +1,60 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require("../../red/red"); +var Blink1 = require("node-blink1"); + +function Blink1Node(n) { + RED.nodes.createNode(this,n); + this.fade = n.fade||0; + var node = this; + + try { + var p1 = /^\#[A-Fa-f0-9]{6}$/ + var p2 = /[0-9]+,[0-9]+,[0-9]+/ + this.on("input", function(msg) { + if (blink1) { + if (p1.test(msg.payload)) { + // if it is a hex colour string + var r = parseInt(msg.payload.slice(1,3),16); + var g = parseInt(msg.payload.slice(3,5),16); + var 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 do fancy colours by name here if you want... + node.warn("Blink1 : invalid msg : "+msg.payload); + } + } + else { + node.warn("No Blink1 found"); + } + }); + var blink1 = new Blink1.Blink1(); + } + catch(e) { + node.error("No Blink1 found"); + } +} + +RED.nodes.registerType("blink1",Blink1Node); diff --git a/social/notify/57-notify.html b/social/notify/57-notify.html new file mode 100644 index 00000000..67c04cbf --- /dev/null +++ b/social/notify/57-notify.html @@ -0,0 +1,55 @@ + + + + + + + diff --git a/social/notify/57-notify.js b/social/notify/57-notify.js new file mode 100644 index 00000000..9330966d --- /dev/null +++ b/social/notify/57-notify.js @@ -0,0 +1,39 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require("../../red/red"); +var growl = require('growl'); +var imagefile = __dirname+"/../../public/mqtt-node-red.png"; + +function NotifyNode(n) { + RED.nodes.createNode(this,n); + this.title = n.title; + var node = this; + this.on("input",function(msg) { + var titl = this.title||msg.topic; + if (typeof(msg.payload) == 'object') { + msg.payload = JSON.stringify(msg.payload); + } + if (typeof(titl) != 'undefined') { + growl(msg.payload, { title: titl, image: imagefile }); + } + else { + growl(msg.payload, { image: imagefile }); + } + }); +} + +RED.nodes.registerType("notify",NotifyNode); diff --git a/social/prowl/57-prowl.html b/social/prowl/57-prowl.html new file mode 100644 index 00000000..6a897f79 --- /dev/null +++ b/social/prowl/57-prowl.html @@ -0,0 +1,63 @@ + + + + + + + diff --git a/social/prowl/57-prowl.js b/social/prowl/57-prowl.js new file mode 100644 index 00000000..d59dc2a3 --- /dev/null +++ b/social/prowl/57-prowl.js @@ -0,0 +1,67 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require("../../red/red"); +var Prowl = require('node-prowl'); +var util = require('util'); + +// Either add a line like this to settings.js +// prowl: {prowlkey:'My-API-KEY'}, +// or create pushkey.js in dir ABOVE node-red, it just needs to be like +// module.exports = {prowlkey:'My-API-KEY'} + +try { + var pushkey = require("../../settings").prowl || require("../../../pushkey.js"); +} +catch(err) { + util.log("[57-prowl.js] Error: Failed to load Prowl credentials"); +} + +if (pushkey) { + var prowl = new Prowl(pushkey.prowlkey); +} + +function ProwlNode(n) { + RED.nodes.createNode(this,n); + this.title = n.title; + this.priority = parseInt(n.priority); + if (this.priority > 2) this.priority = 2; + if (this.priority < -2) this.priority = -2; + var node = this; + this.on("input",function(msg) { + var titl = this.title||msg.topic||"Node-RED"; + var pri = msg.priority||this.priority; + if (typeof(msg.payload) == 'object') { + msg.payload = JSON.stringify(msg.payload); + } + if (pushkey) { + try { + prowl.push(msg.payload, titl, { priority: pri }, function(err, remaining) { + if (err) node.error(err); + node.log( remaining + ' calls to Prowl api during current hour.' ); + }); + } + catch (err) { + node.error(err); + } + } + else { + node.warn("Prowl credentials not set/found. See node info."); + } + }); +} + +RED.nodes.registerType("prowl",ProwlNode); diff --git a/social/prowl/icons/prowl.png b/social/prowl/icons/prowl.png new file mode 100644 index 0000000000000000000000000000000000000000..43f3225338e677de420d20538f35a006a4586f53 GIT binary patch literal 1554 zcmV+t2JQKYP)Px#24YJ`L;wH)0002_L%V+f000SaNLh0L01m_e01m_fl`9S#000H0Nkl(h!@%mg;d0wim@oD&O=dEaneXw!b?Px>l61~Qz37II1ACuu z?{~jzt#_^U!JFg%d9-bNi~7$0)#2;Zht!{_BUkF2<|1o11Dn*X>KFg(0Ft~A%{c>T+xBxw?pC(}M}Vh+fh5b-HA&V1BfyM01)NPXUO-*~9tIvw za(GTANb*bdL%_l$XVpI^c@2sv1z^1wbs4ZM$tqyA`hzb-*UzjwFu*N9&fI3Sm`&mw_jMzX3DlFDHOeU<) z^hLu^{YH{u;8W^bk}NMr8?W0hSBH~K0e`QJPpa1@8B6jka6mm){~t>7C~$w0*tE01xePZS5>6!Pjc{bg@_WOd)u}Z z_&|X;SKdEW`ha>h@UbLM0*BR;z?LK%fbB^Jfxi~8OAFB~;&fkixh?!099tKt~-1UIk7h`6e(~GJR$)$!IpeI0hV352)*s{7C(2k{Q5%>5)`) zyfGU{3lbpH$6NB~sp{8lh^j#0MZQB9%B-x+j6TrQ|lfVz#wtf37 zYzzRK+qNC(3qaepO_Gl!xd)g6{s26Zcf>i{~u9@>NouY zXw^R^c}3j`d>FX3){X*G>RMoXj|oPS3?x}JmvH`%C}^6dRlidk?Jgh>7S+=gUa8F2 z9ZQOVB}tmTi_#=BZQFh~$%8=KG|g+Zw4${9bmjZ54=e{30L%JjpeF-PRTT7&u@aVp zN%r;3uPFT=Rh#*6!VAgnyMUd*@yhF6&G=H;ei&E|Y?yZdZQG6jcO_W^JeB0(9&@d# zT;He*l6?9~Ft8oi4LqOZ=_H2=*h=-fD$PwYqRu}9N$#o4_f(PxdY0}=vc6O>YNu+1 z8|DpwdJS-Wl4IWuEw9Z!Bg}NGehq|sG0E0<}tNos= zxmzk3jV2i?%BL$&%v6Wetr4yPKHJX+icZ;gy!rxwUDXLK?6EoJh~4J&^(0lD^xPQe zZd4(bo=q2314_@0shY7n*)7wS_Tz*vR2e<0E~&YNNv5jR9`DV5>g!K;&oa}T8Tf_z zT;2G#ZuwPh*ihZF?PaWoHLE&GKR!T`Zvz{FkE$=KODp>=D{r3$()}#ZbLhYA)29;t zPJIlRR6h^ARqa$8Hl3vV1?~K2s=A?xH@`E#IWBkn6XpOq7a08AMgRZ+07*qoM6N<$ Eg64YG`~Uy| literal 0 HcmV?d00001 diff --git a/social/pushbullet/57-pushbullet.html b/social/pushbullet/57-pushbullet.html new file mode 100644 index 00000000..32020297 --- /dev/null +++ b/social/pushbullet/57-pushbullet.html @@ -0,0 +1,57 @@ + + + + + + + diff --git a/social/pushbullet/57-pushbullet.js b/social/pushbullet/57-pushbullet.js new file mode 100644 index 00000000..b839e893 --- /dev/null +++ b/social/pushbullet/57-pushbullet.js @@ -0,0 +1,64 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require("../../red/red"); +var PushBullet = require('pushbullet'); +var util = require('util'); + +// Either add a line like this to settings.js +// pushbullet: {pushbullet:'My-API-KEY', deviceid:'12345'}, +// or create pushkey.js in dir ABOVE node-red, it just needs to be like +// module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'} + +try { + var pushkey = require("../../settings").pushbullet || require("../../../pushkey.js"); +} +catch(err) { + util.log("[57-pushbullet.js] Error: Failed to load PushBullet credentials"); +} + +if (pushkey) { + var pusher = new PushBullet(pushkey.pushbullet); + var deviceId = pushkey.deviceid; +} + +function PushbulletNode(n) { + RED.nodes.createNode(this,n); + this.title = n.title; + var node = this; + this.on("input",function(msg) { + var titl = this.title||msg.topic||"Node-RED"; + if (typeof(msg.payload) == 'object') { + msg.payload = JSON.stringify(msg.payload); + } + if (pushkey) { + try { + pusher.note(deviceId, titl, msg.payload, function(err, response) { + if (err) node.error(err); + console.log(response); + }); + } + catch (err) { + node.error(err); + } + } + else { + node.warn("Pushbullet credentials not set/found. See node info."); + } + }); +} + +RED.nodes.registerType("pushbullet",PushbulletNode); diff --git a/social/pushbullet/icons/bullet.png b/social/pushbullet/icons/bullet.png new file mode 100644 index 0000000000000000000000000000000000000000..3cf11b3f86c822c535da593bf142c7fb892dd533 GIT binary patch literal 1075 zcmV-31kC%1P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2i*o3 z7C8+N2LVI?00Xm0L_t(o!|hnRjub}}J*RqR8GBdOY5`#k4)6oXNDx4dgpmWwvVXv- zGbBEPfWQ%f|G}AK%f^TwK*$+#=H(&8V~v1acFu9Iw{~lKdWL3dabj*V-96R!aqhjR zZZ+^u{v%=Eg|>&bj{rDF@&bU5Z6}g{*}hKlw(YwqrAoNstEtoarjw)b821`~twi$~FXmH2|M= zRd;H&Q@&pXFxm%ZTmkT5L_fi1gRVX%c?iIJwN`BpNxmOC$DL58lmx)>!isIUDDegI z3joYSA}N)HmdgB+Z1&zGYKsei0K5u?&VfxBCdnY4H2^0f*qWdbft<0uLeiZ(R)#^+ zMM)2XfwucnE(L~<&?a?5f7#~{3AO~gA$6SkFg=U@iK!W`XwlD_~L)Bo4 z^`J|ZEw#&Bx!K=_w9y-M?89$ooNb}Uj()yC@+aF%wZ&x{B%cGgMDmXqht-Zakrc@f z0GupdL}h_JC3zt3HFppIFedpY$*s!b0?8!+O`n-70cdP5zsX5sR!(id${R(e;ew{} z@Ag#bFLpfIRozLMY$cQAW~Je>mo<+vcb~;IYoIP<6~N({PeAv=gN#Rb%K9$%SVb* zna8MNk{rcpad|FfhDRF!HjC3^Ik1hRO0!erAewQ@p@w9p-X{Pa&;7t=JJ~)!@;d521*k-x19h0002ovPDHLkV1j^} + + + + + + diff --git a/social/xmpp/92-xmpp.js b/social/xmpp/92-xmpp.js new file mode 100644 index 00000000..15f95795 --- /dev/null +++ b/social/xmpp/92-xmpp.js @@ -0,0 +1,118 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var orig=console.warn; +console.warn=(function() { // suppress warning from stringprep when not needed) + var orig=console.warn; + return function() { + //orig.apply(console, arguments); + }; +})(); + +var RED = require("../../red/red"); +var xmpp = require('simple-xmpp'); +console.warn = orig; + +try { + var xmppkey = require("../../settings").xmpp || require("../../../xmppkeys.js"); +} catch(err) { + throw new Error("Failed to load XMPP credentials"); +} + +function XmppNode(n) { + RED.nodes.createNode(this,n); + this.server = n.server; + this.port = n.port; + this.join = n.join || false; + this.nick = n.nick || "Node-RED"; + this.sendAll = n.sendObject; + this.to = n.to || ""; + var node = this; + + setTimeout(function() { + xmpp.connect({ + jid : xmppkey.jid, + password : xmppkey.password, + host : this.server, + port : this.port, + skipPresence : true, + reconnect : false + }); + }, 5000); + + xmpp.on('online', function() { + node.log('connected to '+node.server); + xmpp.setPresence('online', node.nick+' online'); + if (node.join) { + xmpp.join(node.to+'/'+node.nick); + } + }); + + xmpp.on('chat', function(from, message) { + var msg = { topic:from, payload:message }; + node.send([msg,null]); + }); + + xmpp.on('groupchat', function(conference, from, message, stamp) { + var msg = { topic:from, payload:message, room:conference }; + if (from != node.nick) { node.send([msg,null]); } + }); + + //xmpp.on('chatstate', function(from, state) { + //console.log('%s is currently %s', from, state); + //var msg = { topic:from, payload:state }; + //node.send([null,msg]); + //}); + + xmpp.on('buddy', function(jid, state, statusText) { + node.log(jid+" is "+state+" : "+statusText); + var msg = { topic:jid, payload: { presence:state, status:statusText} }; + node.send([null,msg]); + }); + + xmpp.on('error', function(err) { + console.error(err); + }); + + xmpp.on('close', function(err) { + node.log('connection closed'); + }); + + xmpp.on('subscribe', function(from) { + xmpp.acceptSubscription(from); + }); + + this.on("input", function(msg) { + var to = msg.topic; + if (node.to != "") { to = node.to; } + if (node.sendAll) { + xmpp.send(to, JSON.stringify(msg), node.join); + } + else { + xmpp.send(to, msg.payload, node.join); + } + }); + + this.on("close", function() { + xmpp.setPresence('offline'); + //xmpp.conn.end(); + // TODO - DCJ NOTE... this is not good. It leaves the connection up over a restart - which will end up with bad things happening... + // (but requires the underlying xmpp lib to be fixed (which does have an open bug request on fixing the close method)). + this.warn("Due to an underlying bug in the xmpp library this does not disconnect old sessions. This is bad... A restart would be better."); + }); +} + +RED.nodes.registerType("xmpp",XmppNode); diff --git a/social/xmpp/icons/xmpp.png b/social/xmpp/icons/xmpp.png new file mode 100644 index 0000000000000000000000000000000000000000..57e43fc43f1ed502352dcb68468a080d340483dd GIT binary patch literal 2358 zcmV-63CZ?}P)FV00001b5ch_0Itp) z=>Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2i*n; z6(cr7e*1j@00_28L_t(&-tAdkj9pa~{=U7>J@-zfv?HB6oj?17I6!GDwuX@MVqyUy zS}BBRh$f;Bs4>LogFYDI3kh$=gcu(HL0>e8U=v{~wrGo}p-`*|w6>N?JA%4(?0SbT5GC z>-GAc_tNMzO;-Zg0AO%rWMt*&=;+lUgw-SsNs#ny0F6fDsHFV>mKQhsvn=b6qUaV$ z2aPd9-uoAgF^44`CHYU1qvzA$BuN&L90(!w09Y#N8UQz0YgacK4HL&Pj4>!SH~}!x z1`tKjQDe;OwmrJ@2K)fN7FP)~{c$Qvi@0mh_9_ zA(T7fy)OaqUA(YJ(g)_%3XoP(EQv+9fNx7lr^>Rdyq=TXO7hJ%*;K=U&K~q+2}?9Yi4+~BtK41PnQY&8yo8Zo{gz%*^v>a9L zXObkBOIiWIRBKDoIw;R`Mo|PwUnlw3X0xd|0cbXx-dg*rq;HZu?wmuO=b?0W8AbqV zBnKs}^WMj2(%I3`AxZZD_;A^>6b+i`RIOY$AEpS&ogHNDct7m10N$Y_(cQ)AZ$nGIw=#b%pZ+ z006qWx(<+hP|~lQb1Ye@Y&D9*c2m-4z4yyc!)z-^-c7PzF&>hbWf}84f6Y1fSiN3< zy4h@=(=pY|hWDDy=1YtN%Xa5^o>q3U^u(%WsEUtk|clj-ham!^YWrai;@dsdOSQl+&w-%e)IVF_?D@u zsgqfjl|7%bEK{E6AIm_m-l|l zo;`aOpU?Ho`BIdo>B2Nk*VXIwk63Fv3#NI)d%wSO&K+2_YSo6Kkvo6?(9Bg@t(GC# zDEgWW0KQ0aHGnRXBLE(E&K-}U=q_vRa*_eSJ^zA|NR?lwb~uVn2#0>-9Z3P7anl{{z3BC%sJ_K z1(0P~kEAb1`gk!vdI`YpTCMhX09i4`K4aKfYZoU;vMP?_>!T>T!5Fg&zzBc`NdC6? z1LMC2AePhzU~w_cK2GvPyxY60!`N4X<-UVQ>_dWw~&=~Vptyc56C>Q0T c{C~*50UKj+*#!VvMgRZ+07*qoM6N<$f=caJ6#xJL literal 0 HcmV?d00001 diff --git a/storage/leveldb/67-leveldb.html b/storage/leveldb/67-leveldb.html new file mode 100644 index 00000000..bca7afb0 --- /dev/null +++ b/storage/leveldb/67-leveldb.html @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + diff --git a/storage/leveldb/67-leveldb.js b/storage/leveldb/67-leveldb.js new file mode 100644 index 00000000..050d456b --- /dev/null +++ b/storage/leveldb/67-leveldb.js @@ -0,0 +1,93 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require("../../red/red"); +var lvldb = require('level'); + +function LevelNode(n) { + RED.nodes.createNode(this,n); + this.dbname = n.db; + var node = this; + lvldb(this.dbname, function(err, db) { + if (err) node.error(err); + node.db = db; + }); +} +RED.nodes.registerType("leveldbase",LevelNode); +LevelNode.prototype.close = function() { + this.db.close(); +} + +function LevelDBNodeIn(n) { + RED.nodes.createNode(this,n); + this.level = n.level; + this.levelConfig = RED.nodes.getNode(this.level); + + if (this.levelConfig) { + var node = this; + node.on("input", function(msg) { + if (typeof msg.topic === 'string') { + node.levelConfig.db.get(msg.topic, function(err, value) { + if (err) { + //node.warn(err); + // for some reason they treat nothing found as an error... + msg.payload = null; // so we should return null + } + else { msg.payload = value; } + node.send(msg); + }); + } + else { + if (typeof msg.topic !== 'string') node.error("msg.topic (the key is not defined"); + } + }); + } + else { + this.error("LevelDB database name not configured"); + } +} +RED.nodes.registerType("leveldb in",LevelDBNodeIn); + + +function LevelDBNodeOut(n) { + RED.nodes.createNode(this,n); + this.level = n.level; + this.operation = n.operation; + this.levelConfig = RED.nodes.getNode(this.level); + + if (this.levelConfig) { + var node = this; + node.on("input", function(msg) { + if (typeof msg.topic === 'string') { + if (node.operation === "delete") { + node.levelConfig.db.del(msg.topic); + } + else { + node.levelConfig.db.put(msg.topic, msg.payload, function(err) { + if (err) node.error(err); + }); + } + } + else { + if (typeof msg.topic !== 'string') node.error("msg.topic (the key is not defined"); + } + }); + } + else { + this.error("LevelDB database name not configured"); + } +} +RED.nodes.registerType("leveldb out",LevelDBNodeOut); From 6f7487f393cdd3bc86370de76a4c663e0e1a90b2 Mon Sep 17 00:00:00 2001 From: Nicholas O'Leary Date: Wed, 30 Oct 2013 21:34:54 +0000 Subject: [PATCH 05/22] Use process.env.NODE_RED_HOME to locate modules --- analysis/wordpos/72-wordpos.js | 2 +- hardware/blink/76-blinkstick.js | 2 +- hardware/blink/77-blink1.js | 2 +- hardware/digiRGB/78-digiRGB.js | 2 +- hardware/scanBLE/101-scanBLE.js | 2 +- hardware/sensorTag/79-sensorTag.js | 2 +- social/notify/57-notify.js | 4 ++-- social/prowl/57-prowl.js | 4 ++-- social/pushbullet/57-pushbullet.js | 4 ++-- social/xmpp/92-xmpp.js | 4 ++-- storage/leveldb/67-leveldb.js | 2 +- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/analysis/wordpos/72-wordpos.js b/analysis/wordpos/72-wordpos.js index 0725cb1e..ca6739b9 100644 --- a/analysis/wordpos/72-wordpos.js +++ b/analysis/wordpos/72-wordpos.js @@ -14,7 +14,7 @@ * limitations under the License. **/ -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var util = require("util"); var WordPos = require('wordpos'); diff --git a/hardware/blink/76-blinkstick.js b/hardware/blink/76-blinkstick.js index cae30ca8..ebbdacc7 100644 --- a/hardware/blink/76-blinkstick.js +++ b/hardware/blink/76-blinkstick.js @@ -14,7 +14,7 @@ * limitations under the License. **/ -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var blinkstick = require("blinkstick"); Object.size = function(obj) { diff --git a/hardware/blink/77-blink1.js b/hardware/blink/77-blink1.js index 236683ed..54e7a3be 100644 --- a/hardware/blink/77-blink1.js +++ b/hardware/blink/77-blink1.js @@ -14,7 +14,7 @@ * limitations under the License. **/ -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var Blink1 = require("node-blink1"); function Blink1Node(n) { diff --git a/hardware/digiRGB/78-digiRGB.js b/hardware/digiRGB/78-digiRGB.js index 717da0a3..6826b0f2 100644 --- a/hardware/digiRGB/78-digiRGB.js +++ b/hardware/digiRGB/78-digiRGB.js @@ -17,7 +17,7 @@ // Sample Node-RED node file // Require main module -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var HID = require('node-hid'); var device; var node; diff --git a/hardware/scanBLE/101-scanBLE.js b/hardware/scanBLE/101-scanBLE.js index 04a308b5..da8478cd 100644 --- a/hardware/scanBLE/101-scanBLE.js +++ b/hardware/scanBLE/101-scanBLE.js @@ -19,7 +19,7 @@ **/ //might need to modify accordingly -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); //import noble var noble = require('noble'); diff --git a/hardware/sensorTag/79-sensorTag.js b/hardware/sensorTag/79-sensorTag.js index 92555099..8c7a3309 100644 --- a/hardware/sensorTag/79-sensorTag.js +++ b/hardware/sensorTag/79-sensorTag.js @@ -17,7 +17,7 @@ // Sample Node-RED node file // Require main module -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var SensorTag = require('sensortag'); var stag; var node; diff --git a/social/notify/57-notify.js b/social/notify/57-notify.js index 9330966d..db4b2e20 100644 --- a/social/notify/57-notify.js +++ b/social/notify/57-notify.js @@ -14,9 +14,9 @@ * limitations under the License. **/ -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var growl = require('growl'); -var imagefile = __dirname+"/../../public/mqtt-node-red.png"; +var imagefile = process.env.NODE_RED_HOME+"/public/mqtt-node-red.png"; function NotifyNode(n) { RED.nodes.createNode(this,n); diff --git a/social/prowl/57-prowl.js b/social/prowl/57-prowl.js index d59dc2a3..df07759e 100644 --- a/social/prowl/57-prowl.js +++ b/social/prowl/57-prowl.js @@ -14,7 +14,7 @@ * limitations under the License. **/ -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var Prowl = require('node-prowl'); var util = require('util'); @@ -24,7 +24,7 @@ var util = require('util'); // module.exports = {prowlkey:'My-API-KEY'} try { - var pushkey = require("../../settings").prowl || require("../../../pushkey.js"); + var pushkey = require(process.env.NODE_RED_HOME+"/settings").prowl || require(process.env.NODE_RED_HOME+"/../pushkey.js"); } catch(err) { util.log("[57-prowl.js] Error: Failed to load Prowl credentials"); diff --git a/social/pushbullet/57-pushbullet.js b/social/pushbullet/57-pushbullet.js index b839e893..75f774af 100644 --- a/social/pushbullet/57-pushbullet.js +++ b/social/pushbullet/57-pushbullet.js @@ -14,7 +14,7 @@ * limitations under the License. **/ -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var PushBullet = require('pushbullet'); var util = require('util'); @@ -24,7 +24,7 @@ var util = require('util'); // module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'} try { - var pushkey = require("../../settings").pushbullet || require("../../../pushkey.js"); + var pushkey = require(process.env.NODE_RED_HOME+"/settings").pushbullet || require(process.env.NODE_RED_HOME+"/../pushkey.js"); } catch(err) { util.log("[57-pushbullet.js] Error: Failed to load PushBullet credentials"); diff --git a/social/xmpp/92-xmpp.js b/social/xmpp/92-xmpp.js index 15f95795..90f53531 100644 --- a/social/xmpp/92-xmpp.js +++ b/social/xmpp/92-xmpp.js @@ -22,12 +22,12 @@ console.warn=(function() { // suppress warning from stringprep when not needed) }; })(); -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var xmpp = require('simple-xmpp'); console.warn = orig; try { - var xmppkey = require("../../settings").xmpp || require("../../../xmppkeys.js"); + var xmppkey = require(process.env.NODE_RED_HOME+"/settings").xmpp || require(process.env.NODE_RED_HOME+"/../xmppkeys.js"); } catch(err) { throw new Error("Failed to load XMPP credentials"); } diff --git a/storage/leveldb/67-leveldb.js b/storage/leveldb/67-leveldb.js index 050d456b..3289a961 100644 --- a/storage/leveldb/67-leveldb.js +++ b/storage/leveldb/67-leveldb.js @@ -14,7 +14,7 @@ * limitations under the License. **/ -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var lvldb = require('level'); function LevelNode(n) { From 553c978d87df18b16ece7545a290313503844189 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Thu, 31 Oct 2013 09:44:32 +0000 Subject: [PATCH 06/22] Added icons for wake on lan and suncalc to this project --- io/wol/icons/onoff.png | Bin 0 -> 993 bytes time/icons/sun.png | Bin 0 -> 383 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 io/wol/icons/onoff.png create mode 100644 time/icons/sun.png diff --git a/io/wol/icons/onoff.png b/io/wol/icons/onoff.png new file mode 100644 index 0000000000000000000000000000000000000000..ba3d9cb9e47d1cc7c74302b1944a835d4d452b03 GIT binary patch literal 993 zcmV<710MW|P)C3<00001b5ch_0Itp) z=>Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_000AYNklegC&Z+O5+tR3w z+8fe<@welIKnrNkXRX!{@N5RoOZxhCv+^m=TNmg67hflspB<1MF!R5<30UA>7up(Q zl9D}NJs99~;IO2+E181*GT<2SEwFA_u6Q5#!(yWc6u?FsJ8SO+Py$`+e+PJAeTB_E zG%tMtJ_`Yw!Te<7zt?~nH`}fo2lz9%xtW`Q?UK$*>RMOUkV4YE0j|Q$lbg3y(j?HD z4I>+jiNa1;+VctUkF$%+^ukSh=EgItGr$cXHD%^+JDuD~lccjLrR5DTz-~$FCEb@) z+I;NBt&w!12`hiuDSE-*dn#;enF)3mjA_r*G_bfIkkv+G;Q|m~UyXfJFbS9p2b=+J z=e$-m>6`(`lRCiZKHwXHG28Wauxy|ASzBei)Qmg9J*$TS#_YdzA&{lwc$MMDft3RI zZouNR1+&uW){6sI-G;pu>A0~Us;*$rl@xAXy>Uu++)c&1FoM};2EOldN~zyQH%#10 zNgYYk4KSUuJ-k4!iWJ7+qM<`2lF zuK>*6u!G6S z04H*?n?6s0Ul(fZEwRDciqXH9!wQE{tE1=L5euXCrndh8nTFEaJ?nq7 P00000NkvXXu0mjfbH~ci literal 0 HcmV?d00001 diff --git a/time/icons/sun.png b/time/icons/sun.png new file mode 100644 index 0000000000000000000000000000000000000000..c4918e5621be46bb2484c7430a498b7e17341648 GIT binary patch literal 383 zcmeAS@N?(olHy`uVBq!ia0vp^%0O(y!3HF+1t+BgDaPU;cPEB*=VV?2Ic!PZ?k+$Y z2!1;6t_M<_1s;*b3=G`DAk4@xYmNj^i;$;_V@Sl|x6{w^HXHD?eqOZBL4WD%f>Z{! zL{7Gq5v#vk>br3GwQ2~5>O*x2iyylc6d&2x9}hEd3lwn;P>z(}e`^JrzJS;@IcfMwv=XLJan@I)gBI!HSr(FpNI`PKHbB=6$ zQ`x)rOHO<<56o8gGE$D5nB!Tdvj5%9UEgoYt(`f!ra+E=(#|Opx?ZnXHf!l?&89B#&@BLCW>9A;T=I9K0ANBZ%9e+*~!^a$@qcKS*G;9?cepMRvyvlTBOk> a^pO4dse`}D&T;dDg3i;`&t;ucLK6T#V4E}m literal 0 HcmV?d00001 From 7c3b1d7ff4a4648c8dbba4c4b56076e90469fb5d Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Thu, 31 Oct 2013 09:52:15 +0000 Subject: [PATCH 07/22] Copy over "sample" node files freo main project as this is where most people will be adding extra nodes. --- 99-sample.html.demo | 77 +++++++++++++++++++++++++++++++++++++++++++++ 99-sample.js.demo | 52 ++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 99-sample.html.demo create mode 100644 99-sample.js.demo diff --git a/99-sample.html.demo b/99-sample.html.demo new file mode 100644 index 00000000..e26197aa --- /dev/null +++ b/99-sample.html.demo @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + diff --git a/99-sample.js.demo b/99-sample.js.demo new file mode 100644 index 00000000..c591185a --- /dev/null +++ b/99-sample.js.demo @@ -0,0 +1,52 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +// If you use this as a template, replace IBM Corp. with your own name. + +// Sample Node-RED node file + +// Require main module +var RED = require(process.env.NODE_RED_HOME+"/red/red"); + +// The main node definition - most things happen in here +function SampleNode(n) { + // Create a RED node + RED.nodes.createNode(this,n); + + // Store local copies of the node configuration (as defined in the .html) + this.topic = n.topic; + + // Do whatever you need to do in here - declare callbacks etc + // Note: this sample doesn't do anything much - it will only send + // this message once at startup... + // Look at other real nodes for some better ideas of what to do.... + var msg = {}; + msg.topic = this.topic; + msg.payload = "Hello world !" + + // send out the message to the rest of the workspace. + this.send(msg); + + this.on("close", function() { + // Called when the node is shutdown - eg on redeploy. + // Allows ports to be closed, connections dropped etc. + // eg: this.client.disconnect(); + }); +} + +// Register the node by name. This must be called before overriding any of the +// Node functions. +RED.nodes.registerType("sample",SampleNode); From 5e67f4111445ebe0150ea6bdc82b5564db01260f Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Sun, 3 Nov 2013 21:29:20 +0000 Subject: [PATCH 08/22] Add rawserial, mpd, mysql and swearfilter nodes. --- analysis/swearfilter/74-swearfilter.html | 46 +++++++ analysis/swearfilter/74-swearfilter.js | 28 +++++ io/rawserial/26-rawserial.html | 102 ++++++++++++++++ io/rawserial/26-rawserial.js | 112 +++++++++++++++++ social/music/69-mpd.html | 80 ++++++++++++ social/music/69-mpd.js | 84 +++++++++++++ social/music/icons/music.png | Bin 0 -> 1103 bytes storage/mysql/68-mysql.html | 147 +++++++++++++++++++++++ storage/mysql/68-mysql.js | 108 +++++++++++++++++ 9 files changed, 707 insertions(+) create mode 100644 analysis/swearfilter/74-swearfilter.html create mode 100644 analysis/swearfilter/74-swearfilter.js create mode 100644 io/rawserial/26-rawserial.html create mode 100644 io/rawserial/26-rawserial.js create mode 100644 social/music/69-mpd.html create mode 100644 social/music/69-mpd.js create mode 100644 social/music/icons/music.png create mode 100644 storage/mysql/68-mysql.html create mode 100644 storage/mysql/68-mysql.js diff --git a/analysis/swearfilter/74-swearfilter.html b/analysis/swearfilter/74-swearfilter.html new file mode 100644 index 00000000..fd0abeb5 --- /dev/null +++ b/analysis/swearfilter/74-swearfilter.html @@ -0,0 +1,46 @@ + + + + + + + diff --git a/analysis/swearfilter/74-swearfilter.js b/analysis/swearfilter/74-swearfilter.js new file mode 100644 index 00000000..e1a32568 --- /dev/null +++ b/analysis/swearfilter/74-swearfilter.js @@ -0,0 +1,28 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require("../../red/red"); +var badwords = require('badwords'); + +function BadwordsNode(n) { + RED.nodes.createNode(this,n); + var node = this; + this.on("input", function(msg) { + if (badwords.ok(msg.payload)) { node.send(msg); } + }); +} + +RED.nodes.registerType("badwords",BadwordsNode); diff --git a/io/rawserial/26-rawserial.html b/io/rawserial/26-rawserial.html new file mode 100644 index 00000000..55c622f9 --- /dev/null +++ b/io/rawserial/26-rawserial.html @@ -0,0 +1,102 @@ + + + + + + + + + + + + + diff --git a/io/rawserial/26-rawserial.js b/io/rawserial/26-rawserial.js new file mode 100644 index 00000000..9bccefac --- /dev/null +++ b/io/rawserial/26-rawserial.js @@ -0,0 +1,112 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require("../../red/red"); +var settings = RED.settings; +var util = require("util"); +var fs = require('fs'); +var plat = require('os').platform(); +var pre = "\\\\.\\"; + +if (! plat.match(/^win/)) { + util.log("[26-rawserial.js] Advise: Only really needed for Windows boxes without serialport npm module installed."); + pre = ""; +} + +function RawSerialInNode(n) { + RED.nodes.createNode(this,n); + this.port = n.port; + this.split = n.split||null; + if (this.split == '\\n') this.split = "\n"; + if (this.split == '\\r') this.split = "\r"; + var node = this; + + var setupSerial = function() { + node.inp = fs.createReadStream(pre+node.port); + node.inp.setEncoding('utf8'); + var line = ""; + node.inp.on('data', function (data) { + if (node.split != null) { + if (data == node.split) { + node.send({payload:line}); + line = ""; + } + else { line += data; } + } + else { node.send({payload:data}); } + }); + //node.inp.on('end', function (error) {console.log("End", error);}); + node.inp.on('close', function (error) { + util.log("[rawserial] "+node.port+" closed"); + node.tout = setTimeout(function() { + setupSerial(); + },settings.serialReconnectTime); + }); + node.inp.on('error', function(error) { + if (error.code == "ENOENT") { util.log("[rawserial] port "+node.port+" not found"); } + else { util.log("[rawserial] "+node.port+" error "+error); } + node.tout = setTimeout(function() { + setupSerial(); + },settings.serialReconnectTime); + }); + } + setupSerial(); + + node.on('close', function() { + if (node.tout) { clearTimeout(node.tout); } + if (node.inp) { node.inp.pause(); } + }); + +} +RED.nodes.registerType("rawserial in",RawSerialInNode); + + +function RawSerialOutNode(n) { + RED.nodes.createNode(this,n); + this.port = n.port; + var node = this; + + var setupSerial = function() { + node.oup = fs.createWriteStream(pre+node.port,{ flags:'w', encoding:'utf8', mode:0666 }); + node.on("input", function(msg) { + if (msg.payload != null) { + node.oup.write(msg.payload); + } + }); + node.oup.on('open', function (error) { util.log("[rawserial] opened "+node.port); }); + node.oup.on('end', function (error) { console.log("End",error); }); + node.oup.on('close', function (error) { + util.log("[rawserial] "+node.port+" closed"); + node.tout = setTimeout(function() { + setupSerial(); + },settings.serialReconnectTime); + }); + node.oup.on('error', function(error) { + if (error.code == "EACCES") { util.log("[rawserial] can't access port "+node.port); } + else if (error.code == "EIO") { util.log("[rawserial] can't write to port "+node.port); } + else { util.log("[rawserial] "+node.port+" error "+error); } + node.tout = setTimeout(function() { + setupSerial(); + },settings.serialReconnectTime); + }); + } + setupSerial(); + + node.on('close', function() { + if (node.tout) { clearTimeout(node.tout); } + }); +} +RED.nodes.registerType("rawserial out",RawSerialOutNode); diff --git a/social/music/69-mpd.html b/social/music/69-mpd.html new file mode 100644 index 00000000..5ca4f60b --- /dev/null +++ b/social/music/69-mpd.html @@ -0,0 +1,80 @@ + + + + + + + + + + + + + diff --git a/social/music/69-mpd.js b/social/music/69-mpd.js new file mode 100644 index 00000000..2afc91fd --- /dev/null +++ b/social/music/69-mpd.js @@ -0,0 +1,84 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require(process.env.NODE_RED_HOME+"/red/red"); +var komponist = require('komponist'); + +var mpc = ""; +komponist.createConnection(6600, 'localhost', function(err, client) { + if (err) node.error("MPD: Failed to connect to MPD server"); + mpc = client; +}); + +function MPDOut(n) { + RED.nodes.createNode(this,n); + var node = this; + node.mpc = mpc; + + this.on("input", function(msg) { + if (msg != null) { + console.log(msg); + try { + //node.mpc.command(msg.payload); + node.mpc.command(msg.payload, msg.param, function(err, results) { + if (err) { console.log("MPD: Error:",err); } + else { node.error(results); } + }); + } catch(err) { console.log("MPD: Error:",err); } + } + }); + + node.mpc.on('error', function(err) { + console.log("MPD: Error:",err); + }); +} +RED.nodes.registerType("mpd out",MPDOut); + +function MPDIn(n) { + RED.nodes.createNode(this,n); + var node = this; + node.mpc = mpc; + var oldMsg = ""; + + getSong(); + + function getSong() { + node.mpc.currentsong(function(err, info) { + if (err) console.log(err); + else { + var msg = {payload:{},topic:"music"}; + msg.payload.Artist = info.Artist; + msg.payload.Album = info.Album; + msg.payload.Title = info.Title; + msg.payload.Genre = info.Genre; + msg.payload.Date = info.Date; + if (JSON.stringify(msg) != oldMsg) { + node.send(msg); + oldMsg = JSON.stringify(msg); + } + } + }); + } + + node.mpc.on('changed', function(system) { + getSong(); + }); + + this.on("close", function() { + // node.mpc.command("stop"); + }); +} +RED.nodes.registerType("mpd in",MPDIn); diff --git a/social/music/icons/music.png b/social/music/icons/music.png new file mode 100644 index 0000000000000000000000000000000000000000..4e99a1bf3f678deb6ac950a03e10309d313a1d8e GIT binary patch literal 1103 zcmV-V1hD&wP)Px#24YJ`L;wH)0002_L%V+f000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2i*$+ z2^S&jBV1wt00YlSL_t(o!|j+$h#XZEhQCu&-I*Z?f*40!ge;VR2w7+}32qd@5H%1) z%|=8a_}UoIfFXo{Ac8wr3Bu@ z_eeSo^!)>Bg}V)ahk!2}*k0frV76|tv;lBEa2IgKf8Xk~(@nyxal$<*z_JOJfevsV z@RGM(2`m8DT`Vs)Q6yz;888Pt2^{gZ^}t8K?od?OC@;1V;=;2lUcD!QeWCqz;E-3i z)*=T99?Jdt47d$gbWqPodcr@VGAFZ^yjP6762Sff+~PDO;5p!a5C2T)r?vrFl8c>W z;(fqh{(K6!I;=*6G_TtVu?6q-{I1}o1Hs#8Tm{9Isd0d5?wkj10QNg4ZgHS;8afX= z?SM7_&xem_R4l}tE5yQ^t_@TB5qK0h=akb0jsn{q=oKOKt%i8d5c=2xyan9u|95~B zA?F@%lV%1bIe5^kvkN>Dir{cqQO*KCc%KK%Y;Jw1xB z{si14X*N`JwVE-r9`FWm`J|@;$x4#}-v$t;J#7{poQ*0HxvL*`CDOF~>btVO7q|p? z0a%x4KpO^7KxSr3k{)YOVfTSo0;rx>?pS-0qP(wd7+{uAM{yKley?1e@)pq}Yy<{J_V-4UzI*cY?^ifA6(>kyInFxm19lhV0tW82!IX1ap3nM z@8C-LBybt002ovPDHLkV1jK|@Z + + + + + + + + + + + + + + diff --git a/storage/mysql/68-mysql.js b/storage/mysql/68-mysql.js new file mode 100644 index 00000000..01bf646b --- /dev/null +++ b/storage/mysql/68-mysql.js @@ -0,0 +1,108 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require(process.env.NODE_RED_HOME+"/red/red"); +var mysqldb = require('mysql'); + +function MySQLNode(n) { + RED.nodes.createNode(this,n); + this.host = n.host; + this.port = n.port; + this.user = n.user; + this.password = n.pass; + this.dbname = n.db; + var node = this; + + node.connection = mysqldb.createConnection({ + host : node.host, + port : node.port, + user : node.user, + password : node.password, + database : node.dbname + }); + + node.connection.connect(function(err) { + if (err) node.error(err); + }); + + node.on('close', function () { + node.connection.end(function(err) { + if (err) node.error(err); + }); + }); +} +RED.nodes.registerType("MySQLdatabase",MySQLNode); + + +function MysqlDBNodeIn(n) { + RED.nodes.createNode(this,n); + this.mydb = n.mydb; + this.mydbConfig = RED.nodes.getNode(this.mydb); + + if (this.mydbConfig) { + var node = this; + node.on("input", function(msg) { + if (typeof msg.topic === 'string') { + //console.log("query:",msg.topic); + node.mydbConfig.connection.query(msg.topic, function(err, rows) { + if (err) { node.warn(err); } + else { + msg.payload = rows; + node.send(msg); + } + }); + } + else { + if (typeof msg.topic !== 'string') node.error("msg.topic : the query is not defined as a string"); + } + }); + } + else { + this.error("MySQL database not configured"); + } +} +RED.nodes.registerType("mysql",MysqlDBNodeIn); + + +//function MysqlDBNodeOut(n) { + //RED.nodes.createNode(this,n); + //this.level = n.level; + //this.operation = n.operation; + //this.levelConfig = RED.nodes.getNode(this.level); + + //if (this.levelConfig) { + //var node = this; + //node.on("input", function(msg) { + //if (typeof msg.topic === 'string') { + //if (node.operation === "delete") { + //node.levelConfig.db.del(msg.topic); + //} + //else { + //node.levelConfig.db.put(msg.topic, msg.payload, function(err) { + //if (err) node.error(err); + //}); + //} + //} + //else { + //if (typeof msg.topic !== 'string') node.error("msg.topic : the key is not defined"); + //} + //}); + //} + //else { + //this.error("MySQL database not configured"); + //} +//} +//RED.nodes.registerType("mysql out",MysqlDBNodeOut); From ab168fe26f4ab17ad5d94851932dfd470e02a8e1 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Mon, 4 Nov 2013 08:45:37 +0000 Subject: [PATCH 09/22] Fix paths to red to use env variable --- analysis/swearfilter/74-swearfilter.js | 12 ++++++------ io/rawserial/26-rawserial.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/analysis/swearfilter/74-swearfilter.js b/analysis/swearfilter/74-swearfilter.js index e1a32568..f8b445b3 100644 --- a/analysis/swearfilter/74-swearfilter.js +++ b/analysis/swearfilter/74-swearfilter.js @@ -14,15 +14,15 @@ * limitations under the License. **/ -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var badwords = require('badwords'); function BadwordsNode(n) { - RED.nodes.createNode(this,n); - var node = this; - this.on("input", function(msg) { - if (badwords.ok(msg.payload)) { node.send(msg); } - }); + RED.nodes.createNode(this,n); + var node = this; + this.on("input", function(msg) { + if (badwords.ok(msg.payload)) { node.send(msg); } + }); } RED.nodes.registerType("badwords",BadwordsNode); diff --git a/io/rawserial/26-rawserial.js b/io/rawserial/26-rawserial.js index 9bccefac..6fcefc2d 100644 --- a/io/rawserial/26-rawserial.js +++ b/io/rawserial/26-rawserial.js @@ -14,7 +14,7 @@ * limitations under the License. **/ -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var settings = RED.settings; var util = require("util"); var fs = require('fs'); From 28e82c1351f19695a03b7736c039e989ca584414 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Mon, 4 Nov 2013 20:35:49 +0000 Subject: [PATCH 10/22] remove excess console.log from mpd music node --- social/music/69-mpd.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/social/music/69-mpd.js b/social/music/69-mpd.js index 2afc91fd..298d4cf4 100644 --- a/social/music/69-mpd.js +++ b/social/music/69-mpd.js @@ -35,9 +35,9 @@ function MPDOut(n) { //node.mpc.command(msg.payload); node.mpc.command(msg.payload, msg.param, function(err, results) { if (err) { console.log("MPD: Error:",err); } - else { node.error(results); } + //else { console.log(results); } }); - } catch(err) { console.log("MPD: Error:",err); } + } catch (err) { console.log("MPD: Error:",err); } } }); From 6425bd75cb7d6f019929cb03fc0faa946440fdab Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Sat, 9 Nov 2013 17:12:19 +0000 Subject: [PATCH 11/22] Make bad word filter only operate on strings - drop anything else. --- analysis/swearfilter/74-swearfilter.html | 4 ++-- analysis/swearfilter/74-swearfilter.js | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/analysis/swearfilter/74-swearfilter.html b/analysis/swearfilter/74-swearfilter.html index fd0abeb5..69f01bfd 100644 --- a/analysis/swearfilter/74-swearfilter.html +++ b/analysis/swearfilter/74-swearfilter.html @@ -22,7 +22,8 @@ diff --git a/analysis/swearfilter/74-swearfilter.js b/analysis/swearfilter/74-swearfilter.js index f8b445b3..29ba7534 100644 --- a/analysis/swearfilter/74-swearfilter.js +++ b/analysis/swearfilter/74-swearfilter.js @@ -14,15 +14,16 @@ * limitations under the License. **/ -var RED = require(process.env.NODE_RED_HOME+"/red/red"); +var RED = require("../../red/red"); var badwords = require('badwords'); function BadwordsNode(n) { RED.nodes.createNode(this,n); var node = this; this.on("input", function(msg) { - if (badwords.ok(msg.payload)) { node.send(msg); } + if (typeof msg.payload == "string") { + if (badwords.ok(msg.payload)) { node.send(msg); } + } }); } - RED.nodes.registerType("badwords",BadwordsNode); From 793fd3c7fd7c6c00be65417fc186c13f85f1552f Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Sun, 10 Nov 2013 17:01:19 +0000 Subject: [PATCH 12/22] Added list of Nodes to he ReadME so people can see what's there without digging... Bunch of cleanups to node-red-nodes... mainly just removing tabs -> spaces and stuff. No code changes... --- README.md | 67 +++++++++- analysis/swearfilter/74-swearfilter.html | 2 +- analysis/wordpos/72-wordpos.html | 17 ++- analysis/wordpos/72-wordpos.js | 13 +- hardware/Pi/78-ledborg.js | 3 +- hardware/blink/77-blink1.html | 4 +- hardware/blink/77-blink1.js | 73 +++++----- hardware/digiRGB/78-digiRGB.html | 45 ++----- hardware/digiRGB/78-digiRGB.js | 89 ++++++------- io/ping/88-ping.html | 24 ++-- io/ping/88-ping.js | 2 - io/rawserial/26-rawserial.html | 40 +++--- social/music/69-mpd.html | 2 +- storage/leveldb/67-leveldb.html | 162 +++++++++++------------ storage/leveldb/67-leveldb.js | 121 ++++++++--------- storage/mysql/68-mysql.html | 51 ------- 16 files changed, 340 insertions(+), 375 deletions(-) diff --git a/README.md b/README.md index 28c37f0c..c0563a87 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Node-RED Nodes -A collection of nodes for [Node-RED](http://nodered.org). +A collection of nodes for [Node-RED](http://nodered.org). See below for a list. ## Installation @@ -27,9 +27,9 @@ The key points are: ### Contributor License Agreement In order for us to accept pull-requests, the contributor must first complete -a Contributor License Agreement (CLA). This clarifies the intellectual -property license granted with any contribution. It is for your protection as a -Contributor as well as the protection of IBM and its customers; it does not +a Contributor License Agreement (CLA). This clarifies the intellectual +property license granted with any contribution. It is for your protection as a +Contributor as well as the protection of IBM and its customers; it does not change your rights to use your own Contributions for any other purpose. Once you have created a pull-request, we'll provide a link to the appropriate @@ -42,3 +42,62 @@ slightly different. ## Copyright and license Copyright 2013 IBM Corp. under [the Apache 2.0 license](LICENSE). + +# Extra Node Information + +### Analysis + +**72-wordpos** - Analyses the payload and classifies the part-of-speech of each word. The resulting message has msg.pos added with the results. A word may appear in multiple categories (eg, 'great' is both a noun and an adjective). + +**74-swearfilter** - Analyses the payload and tries to filter out any messages containing bad swear words. This only operates on payloads of type string. Everything else is blocked. + +### Hardware + +**37-rpi-piface** - Adds support for the PiFace interface module for Raspberry Pi. + +**78-ledborg** - A simple driver for the LEDborg plug on module for Raspberry Pi. + +**76-blinkstick** - Provides support for the BlinkStick USB LED device. + +**77-blink1** - Provides support for the Blink1 USB LED from ThingM. + +**78-digiRGB** - Provides support for the DigiPark RGB USB LED. + +**79-sensorTag** - Reads data from the Ti BLE SensorTag device. + +**101-scanBLE** - Scans for a particular Bluetooth Low Energy (BLE) device. + +### IO + +**26-rawserial** - Only really needed for Windows boxes without serialport npm module installed. +Uses a simple read of the serial port as a file to input data. You **must** set the baud rate etc externally *before* starting Node-RED. This node does not implement pooling of connections so only one instance of each port may be used - so in **or** out but **not** both. + +**39-wol** - Sends a Wake-On-LAN magic packet to the mac address specified. You may instead set msg.mac to dynamically set the target device mac to wake up. + +**88-ping** - Pings a machine and returns the trip time in mS. Returns false if no response received within 3 seconds, or if the host is unresolveable. Default ping is every 20 seconds but can be configured. + +### Social + +**69-mpd** - MPD music control nodes. Output node expects payload to be a valid mpc command. Currently only simple commands that expect no reply are supported. Input node creates a payload object with Artist, Album, Title, Genre and Date. + +**57-notify** - Uses Growl to provide a desktop popup containing the payload. Only useful on the local machine. + +**57-prowl** - Uses Prowl to push the payload to an Apple device that has the Prowl app installed. + +**57-pushbullet** - Uses PushBullet to push the payload to an Android device that has the PushBullet app installed. + +**92-xmpp** - Connects to an XMPP server to send and receive messages. + +### Storage + +**67-leveldb** - Uses LevelDB for a simple key value pair database. + +**68-mysql** - Allows basic access to a MySQL database. This node uses the **query** operation against the configured database. This does allow both INSERTS and DELETES. By it's very nature it allows SQL injection... *so be careful out there...* + +### Time + +**79-suncalc** - Uses the suncalc module to generate an output at sunrise and sunset based on a specified location. Several choices of definition of sunrise and sunset are available, + +### Misc + +**99-sample** - A sample node with more comments than most to try to help you get started without any other docs... diff --git a/analysis/swearfilter/74-swearfilter.html b/analysis/swearfilter/74-swearfilter.html index 69f01bfd..34379f9b 100644 --- a/analysis/swearfilter/74-swearfilter.html +++ b/analysis/swearfilter/74-swearfilter.html @@ -31,7 +31,7 @@ category: 'analysis-function', color:"#E6E0F8", defaults: { - name: {value:""}, + name: {value:""} }, inputs:1, outputs:1, diff --git a/analysis/wordpos/72-wordpos.html b/analysis/wordpos/72-wordpos.html index b50156ea..6b098990 100644 --- a/analysis/wordpos/72-wordpos.html +++ b/analysis/wordpos/72-wordpos.html @@ -24,14 +24,14 @@ @@ -53,5 +53,4 @@ return this.name?"node_label_italic":""; } }); - diff --git a/analysis/wordpos/72-wordpos.js b/analysis/wordpos/72-wordpos.js index ca6739b9..6f472781 100644 --- a/analysis/wordpos/72-wordpos.js +++ b/analysis/wordpos/72-wordpos.js @@ -15,20 +15,17 @@ **/ var RED = require(process.env.NODE_RED_HOME+"/red/red"); -var util = require("util"); var WordPos = require('wordpos'); - var wordpos = new WordPos(); function WordPOSNode(n) { RED.nodes.createNode(this,n); this.on("input", function(msg) { - var node = this; - wordpos.getPOS(msg.payload, function (result) { - msg.pos = result; - node.send(msg); - }); + var node = this; + wordpos.getPOS(msg.payload, function (result) { + msg.pos = result; + node.send(msg); + }); }); } - RED.nodes.registerType("wordpos",WordPOSNode); diff --git a/hardware/Pi/78-ledborg.js b/hardware/Pi/78-ledborg.js index 4c153d05..8d47db04 100644 --- a/hardware/Pi/78-ledborg.js +++ b/hardware/Pi/78-ledborg.js @@ -20,7 +20,7 @@ var fs = require('fs'); // check if /dev/ledborg exists - if not then don't even show the node. if (!fs.existsSync("/dev/ledborg")) { - util.log("[78-ledborg.js] Error: PiBorg hardware : LedBorg not found"); + util.log("[78-ledborg.js] Warning: PiBorg hardware : LedBorg not found"); return; } @@ -49,5 +49,4 @@ function LedBorgNode(n) { } }); } - RED.nodes.registerType("ledborg",LedBorgNode); diff --git a/hardware/blink/77-blink1.html b/hardware/blink/77-blink1.html index 00579ce8..25ebf6b9 100644 --- a/hardware/blink/77-blink1.html +++ b/hardware/blink/77-blink1.html @@ -27,7 +27,7 @@ diff --git a/hardware/blink/77-blink1.js b/hardware/blink/77-blink1.js index 54e7a3be..580e1060 100644 --- a/hardware/blink/77-blink1.js +++ b/hardware/blink/77-blink1.js @@ -18,43 +18,42 @@ var RED = require(process.env.NODE_RED_HOME+"/red/red"); var Blink1 = require("node-blink1"); function Blink1Node(n) { - RED.nodes.createNode(this,n); - this.fade = n.fade||0; - var node = this; + RED.nodes.createNode(this,n); + this.fade = n.fade||0; + var node = this; - try { - var p1 = /^\#[A-Fa-f0-9]{6}$/ - var p2 = /[0-9]+,[0-9]+,[0-9]+/ - this.on("input", function(msg) { - if (blink1) { - if (p1.test(msg.payload)) { - // if it is a hex colour string - var r = parseInt(msg.payload.slice(1,3),16); - var g = parseInt(msg.payload.slice(3,5),16); - var 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 do fancy colours by name here if you want... - node.warn("Blink1 : invalid msg : "+msg.payload); - } - } - else { - node.warn("No Blink1 found"); - } - }); - var blink1 = new Blink1.Blink1(); - } - catch(e) { - node.error("No Blink1 found"); - } + try { + var p1 = /^\#[A-Fa-f0-9]{6}$/ + var p2 = /[0-9]+,[0-9]+,[0-9]+/ + this.on("input", function(msg) { + if (blink1) { + if (p1.test(msg.payload)) { + // if it is a hex colour string + var r = parseInt(msg.payload.slice(1,3),16); + var g = parseInt(msg.payload.slice(3,5),16); + var 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... + node.warn("Blink1 : invalid msg : "+msg.payload); + } + } + else { + node.warn("No Blink1 found"); + } + }); + var blink1 = new Blink1.Blink1(); + } + catch(e) { + node.error("No Blink1 found"); + } } - RED.nodes.registerType("blink1",Blink1Node); diff --git a/hardware/digiRGB/78-digiRGB.html b/hardware/digiRGB/78-digiRGB.html index a8f0b309..bbb2a128 100644 --- a/hardware/digiRGB/78-digiRGB.html +++ b/hardware/digiRGB/78-digiRGB.html @@ -14,55 +14,34 @@ limitations under the License. --> - - - - - - - diff --git a/io/ping/88-ping.js b/io/ping/88-ping.js index 72e875c0..301aea4c 100644 --- a/io/ping/88-ping.js +++ b/io/ping/88-ping.js @@ -51,7 +51,5 @@ function PingNode(n) { this.on("close", function() { clearInterval(this.tout); }); - } - RED.nodes.registerType("ping",PingNode); diff --git a/io/rawserial/26-rawserial.html b/io/rawserial/26-rawserial.html index 55c622f9..c7b7c362 100644 --- a/io/rawserial/26-rawserial.html +++ b/io/rawserial/26-rawserial.html @@ -15,18 +15,18 @@ --> diff --git a/storage/leveldb/67-leveldb.html b/storage/leveldb/67-leveldb.html index bca7afb0..72ead707 100644 --- a/storage/leveldb/67-leveldb.html +++ b/storage/leveldb/67-leveldb.html @@ -15,108 +15,108 @@ --> diff --git a/storage/leveldb/67-leveldb.js b/storage/leveldb/67-leveldb.js index 3289a961..f4a91db6 100644 --- a/storage/leveldb/67-leveldb.js +++ b/storage/leveldb/67-leveldb.js @@ -18,76 +18,77 @@ var RED = require(process.env.NODE_RED_HOME+"/red/red"); var lvldb = require('level'); function LevelNode(n) { - RED.nodes.createNode(this,n); - this.dbname = n.db; - var node = this; - lvldb(this.dbname, function(err, db) { - if (err) node.error(err); - node.db = db; - }); + RED.nodes.createNode(this,n); + this.dbname = n.db; + var node = this; + lvldb(this.dbname, function(err, db) { + if (err) node.error(err); + node.db = db; + }); + this.on('close', function() { + if (node.db) { node.db.close(); } + }); } RED.nodes.registerType("leveldbase",LevelNode); -LevelNode.prototype.close = function() { - this.db.close(); -} + function LevelDBNodeIn(n) { - RED.nodes.createNode(this,n); - this.level = n.level; - this.levelConfig = RED.nodes.getNode(this.level); + RED.nodes.createNode(this,n); + this.level = n.level; + this.levelConfig = RED.nodes.getNode(this.level); - if (this.levelConfig) { - var node = this; - node.on("input", function(msg) { - if (typeof msg.topic === 'string') { - node.levelConfig.db.get(msg.topic, function(err, value) { - if (err) { - //node.warn(err); - // for some reason they treat nothing found as an error... - msg.payload = null; // so we should return null - } - else { msg.payload = value; } - node.send(msg); - }); - } - else { - if (typeof msg.topic !== 'string') node.error("msg.topic (the key is not defined"); - } - }); - } - else { - this.error("LevelDB database name not configured"); - } + if (this.levelConfig) { + var node = this; + node.on("input", function(msg) { + if (typeof msg.topic === 'string') { + node.levelConfig.db.get(msg.topic, function(err, value) { + if (err) { + //node.warn(err); + // for some reason they treat nothing found as an error... + msg.payload = null; // so we should return null + } + else { msg.payload = value; } + node.send(msg); + }); + } + else { + if (typeof msg.topic !== 'string') node.error("msg.topic (the key is not defined"); + } + }); + } + else { + this.error("LevelDB database name not configured"); + } } RED.nodes.registerType("leveldb in",LevelDBNodeIn); function LevelDBNodeOut(n) { - RED.nodes.createNode(this,n); - this.level = n.level; - this.operation = n.operation; - this.levelConfig = RED.nodes.getNode(this.level); + RED.nodes.createNode(this,n); + this.level = n.level; + this.operation = n.operation; + this.levelConfig = RED.nodes.getNode(this.level); - if (this.levelConfig) { - var node = this; - node.on("input", function(msg) { - if (typeof msg.topic === 'string') { - if (node.operation === "delete") { - node.levelConfig.db.del(msg.topic); - } - else { - node.levelConfig.db.put(msg.topic, msg.payload, function(err) { - if (err) node.error(err); - }); - } - } - else { - if (typeof msg.topic !== 'string') node.error("msg.topic (the key is not defined"); - } - }); - } - else { - this.error("LevelDB database name not configured"); - } + if (this.levelConfig) { + var node = this; + node.on("input", function(msg) { + if (typeof msg.topic === 'string') { + if (node.operation === "delete") { + node.levelConfig.db.del(msg.topic); + } + else { + node.levelConfig.db.put(msg.topic, msg.payload, function(err) { + if (err) node.error(err); + }); + } + } + else { + if (typeof msg.topic !== 'string') node.error("msg.topic (the key is not defined"); + } + }); + } + else { + this.error("LevelDB database name not configured"); + } } RED.nodes.registerType("leveldb out",LevelDBNodeOut); diff --git a/storage/mysql/68-mysql.html b/storage/mysql/68-mysql.html index 2b805133..11c6fd80 100644 --- a/storage/mysql/68-mysql.html +++ b/storage/mysql/68-mysql.html @@ -54,7 +54,6 @@ - - - From 4375b32b84e566dbbedad435e5955a8ec40d13c3 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Sun, 10 Nov 2013 20:58:14 +0000 Subject: [PATCH 13/22] Couple of typos in DigiSpark node and swearfilter node --- analysis/swearfilter/74-swearfilter.js | 2 +- hardware/digiRGB/78-digiRGB.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/analysis/swearfilter/74-swearfilter.js b/analysis/swearfilter/74-swearfilter.js index 29ba7534..765e497b 100644 --- a/analysis/swearfilter/74-swearfilter.js +++ b/analysis/swearfilter/74-swearfilter.js @@ -14,7 +14,7 @@ * limitations under the License. **/ -var RED = require("../../red/red"); +var RED = require(process.env.NODE_RED_HOME+"/red/red"); var badwords = require('badwords'); function BadwordsNode(n) { diff --git a/hardware/digiRGB/78-digiRGB.js b/hardware/digiRGB/78-digiRGB.js index aa1e76a5..cb2cf0cf 100644 --- a/hardware/digiRGB/78-digiRGB.js +++ b/hardware/digiRGB/78-digiRGB.js @@ -63,6 +63,7 @@ function DigiRGBNode(n) { } this.on('close', function() { - if (device) { device.close(); }); + if (device) { device.close(); } + }); } RED.nodes.registerType("digiRGB",DigiRGBNode); From 6ed75458c964b7f9900e21a1428306a7eb870939 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Sun, 10 Nov 2013 20:58:36 +0000 Subject: [PATCH 14/22] Add Wemo node and update READ.me --- README.md | 4 +- hardware/wemo/60-wemo.html | 90 ++++++++++++++++++++++++++++++++++++++ hardware/wemo/60-wemo.js | 60 +++++++++++++++++++++++++ 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 hardware/wemo/60-wemo.html create mode 100644 hardware/wemo/60-wemo.js diff --git a/README.md b/README.md index c0563a87..5c150f4c 100644 --- a/README.md +++ b/README.md @@ -57,11 +57,13 @@ Copyright 2013 IBM Corp. under [the Apache 2.0 license](LICENSE). **78-ledborg** - A simple driver for the LEDborg plug on module for Raspberry Pi. +**60-wemo** - Basic node to drive a WeMo socket and switch. Does not use discovery. + **76-blinkstick** - Provides support for the BlinkStick USB LED device. **77-blink1** - Provides support for the Blink1 USB LED from ThingM. -**78-digiRGB** - Provides support for the DigiPark RGB USB LED. +**78-digiRGB** - Provides support for the DigiSpark RGB USB LED. **79-sensorTag** - Reads data from the Ti BLE SensorTag device. diff --git a/hardware/wemo/60-wemo.html b/hardware/wemo/60-wemo.html new file mode 100644 index 00000000..b282ea73 --- /dev/null +++ b/hardware/wemo/60-wemo.html @@ -0,0 +1,90 @@ + + + + + + + + + + + + + diff --git a/hardware/wemo/60-wemo.js b/hardware/wemo/60-wemo.js new file mode 100644 index 00000000..34391dee --- /dev/null +++ b/hardware/wemo/60-wemo.js @@ -0,0 +1,60 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require(process.env.NODE_RED_HOME+"/red/red"); +var WeMo = new require('wemo'); + +function WeMoOut(n) { + RED.nodes.createNode(this,n); + this.ipaddr = n.ipaddr; + this.wemoSwitch = new WeMo(n.ipaddr); + var node = this; + + this.on("input", function(msg) { + if (msg != null) { + var state = 0; + if ( msg.payload == 1 || msg.payload == true || msg.payload == "on" ) { var state = 1; } + node.wemoSwitch.setBinaryState(state, function(err, result) { + if (err) node.warn(err); + //else { node.log(result); } + }); + } + }); +} +RED.nodes.registerType("wemo out",WeMoOut); + +function WeMoIn(n) { + RED.nodes.createNode(this,n); + this.ipaddr = n.ipaddr; + this.wemoSwitch = new WeMo(n.ipaddr); + this.wemoSwitch.state = 0; + var node = this; + + var tick = setInterval(function() { + wemoSwitch.getBinaryState(function(err, result) { + if (err) node.warn(err); + if (parseInt(result) != wemoSwitch.state) { + wemoSwitch.state = parseInt(result); + node.send({payload:wemoSwitch.state,topic:"wemo/"+node.ipaddr}); + } + }); + }, 2000); + + this.on("close", function() { + clearInterval(tick); + }); +} +RED.nodes.registerType("wemo in",WeMoOut); From 8b29841f972f785c73c60906129d110fa72f0bd1 Mon Sep 17 00:00:00 2001 From: Andrew Lindsay Date: Wed, 13 Nov 2013 21:27:35 +0000 Subject: [PATCH 15/22] twilio node first commit --- social/twilio/56-twilio.html | 58 ++++++++++++++++++++++++++++++ social/twilio/56-twilio.js | 64 +++++++++++++++++++++++++++++++++ social/twilio/icons/twilio.png | Bin 0 -> 717 bytes 3 files changed, 122 insertions(+) create mode 100644 social/twilio/56-twilio.html create mode 100644 social/twilio/56-twilio.js create mode 100644 social/twilio/icons/twilio.png diff --git a/social/twilio/56-twilio.html b/social/twilio/56-twilio.html new file mode 100644 index 00000000..21badcb7 --- /dev/null +++ b/social/twilio/56-twilio.html @@ -0,0 +1,58 @@ + + + + + + + diff --git a/social/twilio/56-twilio.js b/social/twilio/56-twilio.js new file mode 100644 index 00000000..c3f2bb7f --- /dev/null +++ b/social/twilio/56-twilio.js @@ -0,0 +1,64 @@ +/** + * Copyright 2013 Andrew D Lindsay @AndrewDLindsay + * http://blog.thiseldo.co.uk + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require(process.env.NODE_RED_HOME+"/red/red"); +var util = require('util'); + +// Either add a line like this to settings.js +// twilio: { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN',from:'FROM-NUMBER' }, +// Or as a twiliokey.js file in the directory ABOVE node-red. +// module.exports = { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN',from:'FROM-NUMBER' } + +try { + var twiliokey = require(process.env.NODE_RED_HOME+"/settings").twilio || require(process.env.NODE_RED_HOME+"/../twiliokey.js"); +} +catch(err) { + util.log("[56-twilio.js] Error: Failed to load Twilio credentials"); +} + +if (twiliokey) { + var twilioClient = require('twilio')(twiliokey.account, twiliokey.authtoken); + var fromNumber = twiliokey.from; +} + +function TwilioOutNode(n) { + RED.nodes.createNode(this,n); + this.title = n.title; + var node = this; + this.on("input",function(msg) { + if (typeof(msg.payload) == 'object') { + msg.payload = JSON.stringify(msg.payload); + } + if (twiliokey) { + try { + // Send SMS + twilioClient.sendMessage( {to: msg.topic, from: fromNumber, body: msg.payload}, function(err, response) { + if (err) node.error(err); + //console.log(response); + }); + } + catch (err) { + node.error(err); + } + } + else { + node.warn("Twilio credentials not set/found. See node info."); + } + }); +} + +RED.nodes.registerType("twilio out",TwilioOutNode); diff --git a/social/twilio/icons/twilio.png b/social/twilio/icons/twilio.png new file mode 100644 index 0000000000000000000000000000000000000000..7404be1d01ab4df8d5027bd7eda04b7855d3f2d8 GIT binary patch literal 717 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=3?wxlRx|@CmUKs7M+S!VC(K#9UIO`&C9V-A z!TD(=<%vb942~)JNvR5+xryniL8*x;m4zo$ZGeg<2l#}z{{R2~&!0d4{{8z41W%v+ z`}Y0cuV4Rx>{qY<{rK_s`3sOVko)@0-)GPN|NHm<&)XWC>e*E}(;o_x#A3t8bcKz?u=l{Nby?y8IojZ5`y?+mMk4!GZ0ig2?OM?7@fn1UR zgZwN%MFs}OW=|K#kcwMVriD*Ctia>Sy5q>p%hm7a{#~E<=wM=tO3$I`C5Lz;Y(zhl zFh~ z-t|8`KuYlRs@)o0#Xj+?O`izNzBcn<-nn1i+gMrZKVE!rrtSW-qOS)k8=2>=zjnjE zqfA|?O*wRn`l19KcRP-x6wT!Cy0>_Jjs6%ZEWOdRWQKV0oAdX)nbe-x^?km!CaoYy z(D%`zlq;^DfjS%CZDqZ7ktsT*Lejmb^`fyuj%S+A#-iTy3+>W;*L^gcYPC7?^Tltg zvK}2?dUf%kw8z)~{{Hv+qaX9h!!Ms+{kgX24d-sY{qN_^i+@qTYRw Date: Wed, 13 Nov 2013 22:23:26 +0000 Subject: [PATCH 16/22] Updated way main RED settings loaded --- social/twilio/56-twilio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/social/twilio/56-twilio.js b/social/twilio/56-twilio.js index c3f2bb7f..6f301f71 100644 --- a/social/twilio/56-twilio.js +++ b/social/twilio/56-twilio.js @@ -24,7 +24,7 @@ var util = require('util'); // module.exports = { account:'My-ACCOUNT-SID', authtoken:'TWILIO-TOKEN',from:'FROM-NUMBER' } try { - var twiliokey = require(process.env.NODE_RED_HOME+"/settings").twilio || require(process.env.NODE_RED_HOME+"/../twiliokey.js"); + var twiliokey = RED.settings.twilio || require(process.env.NODE_RED_HOME+"/../twiliokey.js"); } catch(err) { util.log("[56-twilio.js] Error: Failed to load Twilio credentials"); From 3f2433ee7f9e95319194111e0238a1ac8d285acb Mon Sep 17 00:00:00 2001 From: Nicholas O'Leary Date: Wed, 13 Nov 2013 22:24:02 +0000 Subject: [PATCH 17/22] PushBullet should not load settings file directly --- social/pushbullet/57-pushbullet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/social/pushbullet/57-pushbullet.js b/social/pushbullet/57-pushbullet.js index 75f774af..fa39d94b 100644 --- a/social/pushbullet/57-pushbullet.js +++ b/social/pushbullet/57-pushbullet.js @@ -24,7 +24,7 @@ var util = require('util'); // module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'} try { - var pushkey = require(process.env.NODE_RED_HOME+"/settings").pushbullet || require(process.env.NODE_RED_HOME+"/../pushkey.js"); + var pushkey = RED.settings.pushbullet || require(process.env.NODE_RED_HOME+"/../pushkey.js"); } catch(err) { util.log("[57-pushbullet.js] Error: Failed to load PushBullet credentials"); From ea398f9e66daa62048ec2c8f016d9c472a37f3d9 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Fri, 15 Nov 2013 21:28:18 +0000 Subject: [PATCH 18/22] Added INFO abour settings for xmpp. (Apologies for missing in first place...). NOTE:... there is still a bug in the underlying simple-xmpp npm.. see https://github.com/simple-xmpp/node-simple-xmpp/issues/12 for both the probem and the fix (not yet pulled). --- social/xmpp/92-xmpp.html | 16 ++-- social/xmpp/92-xmpp.js | 154 ++++++++++++++++++++------------------- 2 files changed, 90 insertions(+), 80 deletions(-) diff --git a/social/xmpp/92-xmpp.html b/social/xmpp/92-xmpp.html index daaa2715..b16f4c5a 100644 --- a/social/xmpp/92-xmpp.html +++ b/social/xmpp/92-xmpp.html @@ -47,11 +47,17 @@ diff --git a/storage/mysql/68-mysql.js b/storage/mysql/68-mysql.js index 7d1564fd..312ab31e 100644 --- a/storage/mysql/68-mysql.js +++ b/storage/mysql/68-mysql.js @@ -17,13 +17,65 @@ var RED = require(process.env.NODE_RED_HOME+"/red/red"); var reconnect = RED.settings.mysqlReconnectTime || 30000; var mysqldb = require('mysql'); +var querystring = require('querystring'); + +RED.app.get('/MySQLdatabase/:id',function(req,res) { + var credentials = RED.nodes.getCredentials(req.params.id); + if (credentials) { + res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")})); + } else { + res.send(JSON.stringify({})); + } +}); + +RED.app.delete('/MySQLdatabase/:id',function(req,res) { + RED.nodes.deleteCredentials(req.params.id); + res.send(200); +}); + +RED.app.post('/MySQLdatabase/:id',function(req,res) { + var body = ""; + req.on('data', function(chunk) { + body+=chunk; + }); + req.on('end', function(){ + var newCreds = querystring.parse(body); + var credentials = RED.nodes.getCredentials(req.params.id)||{}; + if (newCreds.user == null || newCreds.user == "") { + delete credentials.user; + } else { + credentials.user = newCreds.user; + } + if (newCreds.password == "") { + delete credentials.password; + } else { + credentials.password = newCreds.password||credentials.password; + } + RED.nodes.addCredentials(req.params.id,credentials); + res.send(200); + }); +}); + function MySQLNode(n) { RED.nodes.createNode(this,n); this.host = n.host; this.port = n.port; - this.user = n.user; - this.password = n.pass; + if (n.user) { + var credentials = {}; + credentials.user = n.user; + credentials.password = n.pass; + RED.nodes.addCredentials(n.id,credentials); + this.user = n.user; + this.password = n.pass; + } else { + var credentials = RED.nodes.getCredentials(n.id); + if (credentials) { + this.user = credentials.user; + this.password = credentials.password; + } + } + this.dbname = n.db; var node = this; From 34b3c635f306c5e0b06f9ef5acd7ce44ba233d52 Mon Sep 17 00:00:00 2001 From: Nicholas O'Leary Date: Fri, 22 Nov 2013 20:49:31 +0000 Subject: [PATCH 22/22] Lazily connect mysql node If there is a mysqldatabase config node, but no actual users of it, we don't need to connect to the database. --- storage/mysql/68-mysql.js | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/storage/mysql/68-mysql.js b/storage/mysql/68-mysql.js index 312ab31e..d01d6f92 100644 --- a/storage/mysql/68-mysql.js +++ b/storage/mysql/68-mysql.js @@ -61,6 +61,10 @@ function MySQLNode(n) { RED.nodes.createNode(this,n); this.host = n.host; this.port = n.port; + + this.connected = false; + this.connecting = false; + if (n.user) { var credentials = {}; credentials.user = n.user; @@ -80,6 +84,7 @@ function MySQLNode(n) { var node = this; function doConnect() { + node.connecting = true; node.connection = mysqldb.createConnection({ host : node.host, port : node.port, @@ -90,13 +95,17 @@ function MySQLNode(n) { }); node.connection.connect(function(err) { + node.connecting = false; if (err) { - node.warn("mysql: "+err); + node.warn(err); node.tick = setTimeout(doConnect, reconnect); + } else { + node.connected = true; } }); node.connection.on('error', function(err) { + node.connected = false; if (err.code === 'PROTOCOL_CONNECTION_LOST') { doConnect(); // silently reconnect... } else { @@ -105,13 +114,20 @@ function MySQLNode(n) { } }); } - doConnect(); - - node.on('close', function () { - if (node.tick) { clearTimeout(node.tick); } - node.connection.end(function(err) { - if (err) node.error(err); - }); + + this.connect = function() { + if (!this.connected && !this.connecting) { + doConnect(); + } + } + + this.on('close', function () { + if (this.tick) { clearTimeout(this.tick); } + if (this.connection) { + node.connection.end(function(err) { + if (err) node.error(err); + }); + } }); } RED.nodes.registerType("MySQLdatabase",MySQLNode); @@ -123,6 +139,7 @@ function MysqlDBNodeIn(n) { this.mydbConfig = RED.nodes.getNode(this.mydb); if (this.mydbConfig) { + this.mydbConfig.connect(); var node = this; node.on("input", function(msg) { if (typeof msg.topic === 'string') {