-
Notifications
You must be signed in to change notification settings - Fork 13
/
wake_on_lan.lua
52 lines (41 loc) · 1.21 KB
/
wake_on_lan.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
--[[
%% properties
%% globals
--]]
-- convert MAC adress, every 2 Chars (7-bit ASCII), to one Byte Char (8-bits)
function convertMacAddress(address)
local s = string.gsub(address, ":", "");
local x = ""; -- will contain converted MAC
for i=1, 12, 2 do
x = x .. string.char(tonumber(string.sub(s, i, i+1), 16));
end
return x;
end
fibaro:log("Start process");
-- MAC adress
local _macAddress = convertMacAddress("xx:xx:xx:xx:xx:xx");
-- Create Magic Packet 6 x FF
local _magicPacket = string.char(0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
-- Broadcast Address
local _broadcastAddress = "255.255.255.255";
-- Default port used
local _wakeOnLanPort = 9;
fibaro:sleep(750);
for i = 1, 16 do
_magicPacket = _magicPacket .. _macAddress;
end
fibaro:log("Magic packet successfully created");
fibaro:sleep(1000);
socket = Net.FUdpSocket();
socket:setBroadcast(true);
local bytes, errorCode = socket:write(_magicPacket, _broadcastAddress, _wakeOnLanPort);
--check for error
if errorCode == 0 then
fibaro:log("Successfully sent");
else
fibaro:log("Transfer failed");
end
-- clean up memory
socket = nil;
fibaro:sleep(1000);
fibaro:log("Please wait for the server startup.");