Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion button-pressed.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
color: '#F3EC14',
defaults: {
name: {value:"Dash Button"},
mac: {value:""}
mac: {value:""},
iface: {value:""},
debounce: {value:""},
protocol: {value:""}
},
inputs:0,
outputs:1,
Expand All @@ -27,6 +30,25 @@
<input type="text" id="node-input-mac" placeholder="00:00:00:00:00:00">
</div>

<div class="form-row">
<label for="node-input-iface">Capturing interface</label>
<input type="text" id="node-input-iface" placeholder="all">
</div>

<div class="form-row">
<label for="node-input-debounce">Timeout (ms)</label>
<input type="number" id="node-input-debounce" placeholder="5000">
</div>

<div class="form-row">
<label for="node-input-protocol">Protocol</label>
<select id="node-input-protocol" style="width:70%">
<option value="arp">arp</option>
<option value="udp">udp</option>
<option value="all">all</option>
</select>
</div>

</script>

<script type="text/x-red" data-help-name="ButtonPressed">
Expand Down
29 changes: 18 additions & 11 deletions button-pressed.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var dash_button = require('node-dash-button'),
_ = require('underscore');
var dash_button = require('node-dash-button');

module.exports = function(RED) {
function node (config) {
Expand All @@ -8,18 +7,26 @@ module.exports = function(RED) {
var node = this;

var mac = config.mac || '';

console.log(mac);
var iface = config.iface || null;
var debounce = config.debounce || null;
var protocol = config.protocol || null;

node.log("Listening to " + mac + " dash button" + (iface ? ' on ' + iface + ' interface' : ''));

var dash = dash_button(mac, iface, debounce, protocol);

var dash = dash_button(mac);
var found = function () {
console.log('Button Pressed: ' + mac);
node.on("close", function () {
if (typeof(dash) !== "undefined" && dash) {
dash.emit('close');
}
});

dash.on("detected", function (dash_id) {
console.log('Dash button Pressed: ' + dash_id);
var msg = {};
node.send(msg);
};

dash.on("detected", _.debounce(found, 5000, true));
});
};

RED.nodes.registerType("ButtonPressed",node);
RED.nodes.registerType("ButtonPressed", node);
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
}
},
"dependencies": {
"node-dash-button": "^0.3.0",
"underscore": "^1.8.3"
"node-dash-button": "git+https://github.com/Neonox31/node-dash-button.git#feature/close-session"
}
}