1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Added UDP port option to node-red-node-wol (#606)

* Added udp port option

* Added UDP port validation and msg.udpport support
This commit is contained in:
SillaRizzoli 2019-11-25 15:17:36 +01:00 committed by Dave Conway-Jones
parent e814c676d2
commit dfddf0645a
3 changed files with 16 additions and 3 deletions

View File

@ -8,19 +8,25 @@
<label for="node-input-host"><i class="fa fa-globe"></i> Target Address</label>
<input type="text" id="node-input-host" placeholder="e.g. 192.168.1.255 or 10.255.255.255">
</div>
<div class="form-row">
<label for="node-input-udpport"><i class="fa fa-globe"></i> Target UDP Port</label>
<input type="number" id="node-input-udpport" placeholder="9">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-tips">Tip: leave blank if you want to use <code>msg.mac</code> or <code>msg.host</code> to dynamically set target mac address.</div>
<div class="form-tips">Tip: leave blank if you want to use <code>msg.mac</code>, <code>msg.host</code> or <code>msg.udpport</code> to dynamically set target information.</div>
</script>
<script type="text/x-red" data-help-name="wake on lan">
<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>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>
</script>
<script type="text/javascript">
@ -30,6 +36,7 @@
defaults: {
mac: {value:""},
host: {value:""},
udpport: {value:9, validate:RED.validators.number()},
name: {value:""}
},
inputs:1,

View File

@ -8,15 +8,21 @@ module.exports = function(RED) {
RED.nodes.createNode(this,n);
this.mac = n.mac.trim();
this.host = n.host;
this.udpport = n.udpport;
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');
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 (mac != null) {
if (chk.test(mac)) {
try {
wol.wake(mac, {address: host}, function(error) {
wol.wake(mac, {address: host, port: udpport}, function(error) {
if (error) {
node.warn(error);
node.status({fill:"red",shape:"ring",text:" "});

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-wol",
"version" : "0.0.12",
"version" : "0.0.13",
"description" : "A Node-RED node to send Wake-On-LAN (WOL) magic packets",
"dependencies" : {
"wake_on_lan" : "1.0.0"