Skip to content

Commit 8604a78

Browse files
authored
Added to wol node: num_packets and interval options (#819)
1 parent 761bb30 commit 8604a78

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

io/wol/39-wol.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
<label for="node-input-udpport" style="width:120px;"><i class="fa fa-random"></i> Target UDP Port</label>
1313
<input type="number" id="node-input-udpport" placeholder="9">
1414
</div>
15+
<div class="form-row">
16+
<label for="node-input-numpackets" style="width:120px;"><i class="fa fa-envelope"></i> Number of Packets</label>
17+
<input type="number" id="node-input-numpackets" placeholder="3">
18+
</div>
19+
<div class="form-row">
20+
<label for="node-input-interval" style="width:120px;"><i class="fa fa-clock-o"></i> Interval Between Packets (ms)</label>
21+
<input type="number" id="node-input-interval" placeholder="100">
22+
</div>
1523
<div class="form-row">
1624
<label for="node-input-name" style="width:120px;"><i class="fa fa-tag"></i> Name</label>
1725
<input type="text" id="node-input-name" placeholder="Name">
@@ -23,10 +31,10 @@
2331
<p>Sends a Wake-On-LAN magic packet to the mac address specified.</p>
2432
<p>You may instead set <code>msg.mac</code> to dynamically set the target device mac to wake up.</p>
2533
<p>The address of the target machine can optionally be set using <code>msg.host</code></p>
26-
<p>You can likewise set the destination UDP port using <code>msg.udpport</code></p>
34+
<p>You can likewise set the destination UDP port, number of packets sent, and interval between packets using <code>msg.udpport</code>, <code>msg.numpackets</code>, <code>msg.interval</code>.</p>
2735
<p>Setting the target address to the broadcast address of the subnet that the target machine is attached to works best.
2836
For a class C address this is usually just the first three parts of the ip address followed by 255. eg 192.168.1.255.</p>
29-
<p>You can specify the target UDP port, default is 9.</p>
37+
<p>You can specify the target UDP port (default 9), number of packets sent (default 3), and interval between packets (default 100ms).</p>
3038
</script>
3139

3240
<script type="text/javascript">
@@ -37,6 +45,8 @@
3745
mac: {value:""},
3846
host: {value:""},
3947
udpport: {value:9, validate:RED.validators.number()},
48+
numpackets: {value:3},
49+
interval: {value:100},
4050
name: {value:""}
4151
},
4252
inputs:1,

io/wol/39-wol.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,32 @@ module.exports = function(RED) {
99
this.mac = n.mac.trim();
1010
this.host = n.host;
1111
this.udpport = n.udpport;
12+
this.numpackets = n.numpackets;
13+
this.interval = n.interval;
1214
var node = this;
1315

1416
this.on("input", function(msg) {
1517
var mac = this.mac || msg.mac || null;
1618
var host = this.host || msg.host || '255.255.255.255';
1719
var udpport = Number(msg.udpport || this.udpport || '9');
20+
var numpackets = Number(msg.numpackets || this.numpackets || '3');
21+
var interval = Number(msg.interval || this.interval || '100');
1822
if (udpport < 1 || udpport > 65535) {
1923
node.warn("WOL: UDP port must be within 1 and 65535; it has been reset to 9.");
2024
udpport = 9;
21-
}
25+
}
26+
if (numpackets < 1 || numpackets > 500) {
27+
node.warn("WOL: Number of packets must be within 1 and 500; it has been reset to 3.");
28+
numpackets = 3;
29+
}
30+
if (interval < 1 || interval > 3600000) {
31+
node.warn("WOL: Interval between packets must be within 1 and 3600000; it has been reset to 100.");
32+
interval = 100;
33+
}
2234
if (mac != null) {
2335
if (chk.test(mac)) {
2436
try {
25-
wol.wake(mac, {address: host, port: udpport}, function(error) {
37+
wol.wake(mac, {address: host, port: udpport, num_packets: numpackets, interval: interval}, function(error) {
2638
if (error) {
2739
node.warn(error);
2840
node.status({fill:"red",shape:"ring",text:" "});

io/wol/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name" : "node-red-node-wol",
3-
"version" : "0.1.0",
3+
"version" : "0.2.0",
44
"description" : "A Node-RED node to send Wake-On-LAN (WOL) magic packets",
55
"dependencies" : {
66
"wake_on_lan" : "1.0.0"

0 commit comments

Comments
 (0)