Merge branch 'master' of github.com:node-red/node-red

This commit is contained in:
Nicholas O'Leary 2013-10-02 19:43:01 +01:00
commit 914c84e234
4 changed files with 57 additions and 37 deletions

View File

@ -32,8 +32,10 @@
<script type="text/x-red" data-help-name="prowl">
<p>Uses Prowl to push the <b>msg.payload</b> to an Apple device that has the prowl app installed.</p>
<p>Optionally uses <b>msg.topic</b> to set the title. You can also set <b>msg.priority</b> to confgure the urgency from -2 (low), through 0 (normal) to 2 (urgent).</p>
<p>You MUST configure your prowl API key into the pushkey.js file in the directory above node-red.</p>
<p><pre>module.exports = { prowl:'My-API-KEY' }</pre></p>
<p>You MUST configure your prowl API key into either the settings.js file like this</p>
<p><pre>prowl: { prowlkey:'My-API-KEY' },</pre></p>
<p>Or into a pushkey.js file in the directory <b>above</b> node-red.</p>
<p><pre>module.exports = { prowlkey:'My-API-KEY' }</pre></p>
<p>Uses Prowl so see <i><a href="https://www.prowlapp.com" target="_new">this link</a></i> for more details.</p>
</script>

View File

@ -16,17 +16,23 @@
var RED = require("../../red/red");
var Prowl = require('node-prowl');
var util = require('util');
// pushkey.js just needs to be like (with the quotes)
// module.exports = {prowl:'My-API-KEY'}
// 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) {
throw new Error("Failed to load Prowl credentials");
}
catch(err) {
util.log("[57-prowl.js] Error: Failed to load Prowl credentials");
}
var prowl = new Prowl(pushkey.prowl);
if (pushkey) {
var prowl = new Prowl(pushkey.prowlkey);
}
function ProwlNode(n) {
RED.nodes.createNode(this,n);
@ -41,14 +47,19 @@ function ProwlNode(n) {
if (typeof(msg.payload) == 'object') {
msg.payload = JSON.stringify(msg.payload);
}
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.' );
});
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);
}
}
catch (err) {
node.error(err);
else {
node.warn("Prowl credentials not set/found. See node info.");
}
});
}

View File

@ -16,13 +16,9 @@
<script type="text/x-red" data-template-name="pushbullet">
<div class="form-row">
<label for="node-input-title"><i class="icon-tag"></i> Title</label>
<label for="node-input-title"><i class="icon-flag"></i> Title</label>
<input type="text" id="node-input-title" placeholder="Node-RED">
</div>
<div class="form-row">
<label for="node-input-priority"><i class="icon-tag"></i> Priority</label>
<input type="text" id="node-input-priority" placeholder="0">
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
@ -31,9 +27,11 @@
<script type="text/x-red" data-help-name="pushbullet">
<p>Uses PushBullet to push the <b>msg.payload</b> to an Android device that has PushBullet app installed.</p>
<p>Optionally uses <b>msg.topic</b> to set the title.</p>
<p>You MUST configure both your API key and the target device ID into the pushkey.js file in the directory above node-red.<p>
<p><pre>>module.exports = { pushbullet:'My-API-KEY', deviceid:'12345' }</pre</p>
<p>Optionally uses <b>msg.topic</b> to set the title, if not already set in the properties.</p>
<p>You MUST configure both your API key and the target device ID. Either into settings.js like this</p>
<p><pre>pushbullet: { pushbullet:'My-API-KEY', deviceid:'12345' },</pre></p>
<p>Or as a pushkey.js file in the directory <b>above</b> node-red.<p>
<p><pre>module.exports = { pushbullet:'My-API-KEY', deviceid:'12345' }</pre></p>
</script>
<script type="text/javascript">
@ -41,7 +39,6 @@
category: 'output',
defaults: {
title: {value:""},
priority: {value:0,required:true,validate:RED.validators.number()},
name: {value:""}
},
color:"#a7c9a0",

View File

@ -16,37 +16,47 @@
var RED = require("../../red/red");
var PushBullet = require('pushbullet');
var util = require('util');
// pushkey.js just needs to be like (with the quotes)
// module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'}
// 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) {
throw new Error("Failed to load PushBullet credentials");
}
catch(err) {
util.log("[57-pushbullet.js] Error: Failed to load PushBullet credentials");
}
var pusher = new PushBullet(pushkey.pushbullet);
var deviceId = pushkey.deviceid;
if (pushkey) {
var pusher = new PushBullet(pushkey.pushbullet);
var deviceId = pushkey.deviceid;
}
function PushbulletNode(n) {
RED.nodes.createNode(this,n);
this.title = n.title;
this.device
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);
}
try {
pusher.note(deviceId, titl, msg.payload, function(err, response) {
if ( err ) node.error(err);
node.log( JSON.stringify(response) );
});
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);
}
}
catch (err) {
node.error(err);
else {
node.warn("Pushbullet credentials not set/found. See node info.");
}
});
}