mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Added to wol node: num_packets and interval options (#819)
This commit is contained in:
parent
761bb30ada
commit
8604a783a4
@ -12,6 +12,14 @@
|
||||
<label for="node-input-udpport" style="width:120px;"><i class="fa fa-random"></i> Target UDP Port</label>
|
||||
<input type="number" id="node-input-udpport" placeholder="9">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-numpackets" style="width:120px;"><i class="fa fa-envelope"></i> Number of Packets</label>
|
||||
<input type="number" id="node-input-numpackets" placeholder="3">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-interval" style="width:120px;"><i class="fa fa-clock-o"></i> Interval Between Packets (ms)</label>
|
||||
<input type="number" id="node-input-interval" placeholder="100">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name" style="width:120px;"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
@ -23,10 +31,10 @@
|
||||
<p>Sends a Wake-On-LAN magic packet to the mac address specified.</p>
|
||||
<p>You may instead set <code>msg.mac</code> to dynamically set the target device mac to wake up.</p>
|
||||
<p>The address of the target machine can optionally be set using <code>msg.host</code></p>
|
||||
<p>You can likewise set the destination UDP port using <code>msg.udpport</code></p>
|
||||
<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>
|
||||
<p>Setting the target address to the broadcast address of the subnet that the target machine is attached to works best.
|
||||
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>
|
||||
<p>You can specify the target UDP port, default is 9.</p>
|
||||
<p>You can specify the target UDP port (default 9), number of packets sent (default 3), and interval between packets (default 100ms).</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -37,6 +45,8 @@
|
||||
mac: {value:""},
|
||||
host: {value:""},
|
||||
udpport: {value:9, validate:RED.validators.number()},
|
||||
numpackets: {value:3},
|
||||
interval: {value:100},
|
||||
name: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
|
@ -9,20 +9,32 @@ module.exports = function(RED) {
|
||||
this.mac = n.mac.trim();
|
||||
this.host = n.host;
|
||||
this.udpport = n.udpport;
|
||||
this.numpackets = n.numpackets;
|
||||
this.interval = n.interval;
|
||||
var node = this;
|
||||
|
||||
this.on("input", function(msg) {
|
||||
var mac = this.mac || msg.mac || null;
|
||||
var host = this.host || msg.host || '255.255.255.255';
|
||||
var udpport = Number(msg.udpport || this.udpport || '9');
|
||||
var numpackets = Number(msg.numpackets || this.numpackets || '3');
|
||||
var interval = Number(msg.interval || this.interval || '100');
|
||||
if (udpport < 1 || udpport > 65535) {
|
||||
node.warn("WOL: UDP port must be within 1 and 65535; it has been reset to 9.");
|
||||
udpport = 9;
|
||||
}
|
||||
}
|
||||
if (numpackets < 1 || numpackets > 500) {
|
||||
node.warn("WOL: Number of packets must be within 1 and 500; it has been reset to 3.");
|
||||
numpackets = 3;
|
||||
}
|
||||
if (interval < 1 || interval > 3600000) {
|
||||
node.warn("WOL: Interval between packets must be within 1 and 3600000; it has been reset to 100.");
|
||||
interval = 100;
|
||||
}
|
||||
if (mac != null) {
|
||||
if (chk.test(mac)) {
|
||||
try {
|
||||
wol.wake(mac, {address: host, port: udpport}, function(error) {
|
||||
wol.wake(mac, {address: host, port: udpport, num_packets: numpackets, interval: interval}, function(error) {
|
||||
if (error) {
|
||||
node.warn(error);
|
||||
node.status({fill:"red",shape:"ring",text:" "});
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "node-red-node-wol",
|
||||
"version" : "0.1.0",
|
||||
"version" : "0.2.0",
|
||||
"description" : "A Node-RED node to send Wake-On-LAN (WOL) magic packets",
|
||||
"dependencies" : {
|
||||
"wake_on_lan" : "1.0.0"
|
||||
|
Loading…
Reference in New Issue
Block a user