mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
jsHint passing versions of BBB, scanBLE and wemo nodes.
Also fixe and in vs out issue on wemo... no way it could have been working previously..
This commit is contained in:
parent
c14364d752
commit
999874f2b5
@ -14,8 +14,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
// Require main module
|
module.exports = function(RED) {
|
||||||
var RED = require(process.env.NODE_RED_HOME + "/red/red");
|
"use strict";
|
||||||
var bonescript = require("bonescript");
|
var bonescript = require("bonescript");
|
||||||
|
|
||||||
// Node constructor for bbb-analogue-in
|
// Node constructor for bbb-analogue-in
|
||||||
@ -81,10 +81,12 @@ function DiscreteInputNode(n) {
|
|||||||
// Store local copies of the node configuration (as defined in the .html)
|
// Store local copies of the node configuration (as defined in the .html)
|
||||||
this.topic = n.topic; // the topic is not currently used
|
this.topic = n.topic; // the topic is not currently used
|
||||||
this.pin = n.pin; // The Beaglebone Black pin identifying string
|
this.pin = n.pin; // The Beaglebone Black pin identifying string
|
||||||
if (n.activeLow) // Set the 'active' state 0 or 1 as appropriate
|
if (n.activeLow) { // Set the 'active' state 0 or 1 as appropriate
|
||||||
this.activeState = 0;
|
this.activeState = 0;
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
this.activeState = 1;
|
this.activeState = 1;
|
||||||
|
}
|
||||||
this.updateInterval = n.updateInterval * 1000; // How often to send totalActiveTime messages
|
this.updateInterval = n.updateInterval * 1000; // How often to send totalActiveTime messages
|
||||||
this.debounce = n.debounce; // Enable switch contact debouncing algorithm
|
this.debounce = n.debounce; // Enable switch contact debouncing algorithm
|
||||||
if (n.outputOn === "rising") {
|
if (n.outputOn === "rising") {
|
||||||
@ -184,7 +186,7 @@ function DiscreteInputNode(n) {
|
|||||||
// payload, if possible. Otherwise clear the totalActiveTime (so we start counting
|
// payload, if possible. Otherwise clear the totalActiveTime (so we start counting
|
||||||
// from zero again)
|
// from zero again)
|
||||||
var inputCallback = function (ipMsg) {
|
var inputCallback = function (ipMsg) {
|
||||||
if (String(ipMsg.topic).search(/load/i) < 0 || isFinite(ipMsg.payload) == false) {
|
if (String(ipMsg.topic).search(/load/i) < 0 || isFinite(ipMsg.payload) === false) {
|
||||||
node.totalActiveTime = 0;
|
node.totalActiveTime = 0;
|
||||||
} else {
|
} else {
|
||||||
node.totalActiveTime = Number(ipMsg.payload);
|
node.totalActiveTime = Number(ipMsg.payload);
|
||||||
@ -277,7 +279,7 @@ function PulseInputNode(n) {
|
|||||||
// insensitive) and the payload is a valid number, set the count to that
|
// insensitive) and the payload is a valid number, set the count to that
|
||||||
// number, otherwise set it to zero
|
// number, otherwise set it to zero
|
||||||
var inputCallback = function (msg) {
|
var inputCallback = function (msg) {
|
||||||
if (String(msg.topic).search(/load/i) < 0 || isFinite(msg.payload) == false) {
|
if (String(msg.topic).search(/load/i) < 0 || isFinite(msg.payload) === false) {
|
||||||
node.pulseCount = 0;
|
node.pulseCount = 0;
|
||||||
} else {
|
} else {
|
||||||
node.pulseCount = Number(msg.payload);
|
node.pulseCount = Number(msg.payload);
|
||||||
@ -500,3 +502,4 @@ PulseOutputNode.prototype.close = function () {
|
|||||||
clearTimeout(this.pulseTimer);
|
clearTimeout(this.pulseTimer);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
@ -40,8 +40,9 @@ function BleScan(n) {
|
|||||||
this.on("input", function(msg){
|
this.on("input", function(msg){
|
||||||
noble.startScanning();
|
noble.startScanning();
|
||||||
});
|
});
|
||||||
|
|
||||||
noble.on('scanStart', function(msg) {
|
noble.on('scanStart', function(msg) {
|
||||||
var msg = {};
|
msg = {};
|
||||||
msg.topic = node.topic;
|
msg.topic = node.topic;
|
||||||
msg.payload = "Scanning initiated..." //debugging
|
msg.payload = "Scanning initiated..." //debugging
|
||||||
//console.log('scanning initiated...');
|
//console.log('scanning initiated...');
|
||||||
@ -49,7 +50,6 @@ function BleScan(n) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
noble.on('discover', function(peripheral) {
|
noble.on('discover', function(peripheral) {
|
||||||
|
|
||||||
var msg = {};
|
var msg = {};
|
||||||
msg.topic = node.topic;
|
msg.topic = node.topic;
|
||||||
msg.payload = "not found";
|
msg.payload = "not found";
|
||||||
@ -57,7 +57,8 @@ function BleScan(n) {
|
|||||||
//check for the device name and the UUID (first one from the UUID list)
|
//check for the device name and the UUID (first one from the UUID list)
|
||||||
if(peripheral.advertisement.localName==node.ble_name && peripheral.advertisement.serviceUuids[0]==node.ble_uuid) {
|
if(peripheral.advertisement.localName==node.ble_name && peripheral.advertisement.serviceUuids[0]==node.ble_uuid) {
|
||||||
msg.payload=peripheral.advertisement.localName;
|
msg.payload=peripheral.advertisement.localName;
|
||||||
noble.stopScanning(); }
|
noble.stopScanning();
|
||||||
|
}
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -16,12 +16,12 @@
|
|||||||
|
|
||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var WeMo = new require('wemo');
|
var Wemo = require('wemo');
|
||||||
|
|
||||||
function WeMoOut(n) {
|
function WemoOut(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.ipaddr = n.ipaddr;
|
this.ipaddr = n.ipaddr;
|
||||||
this.wemoSwitch = new WeMo(n.ipaddr);
|
this.wemoSwitch = new Wemo(n.ipaddr);
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
@ -35,9 +35,9 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("wemo out",WeMoOut);
|
RED.nodes.registerType("wemo out",WemoOut);
|
||||||
|
|
||||||
function WeMoIn(n) {
|
function WemoIn(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.ipaddr = n.ipaddr;
|
this.ipaddr = n.ipaddr;
|
||||||
this.wemoSwitch = new WeMo(n.ipaddr);
|
this.wemoSwitch = new WeMo(n.ipaddr);
|
||||||
@ -58,5 +58,5 @@ module.exports = function(RED) {
|
|||||||
clearInterval(tick);
|
clearInterval(tick);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("wemo in",WeMoOut);
|
RED.nodes.registerType("wemo in",WemoIn);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user