/
WakeOnLan.cpp
54 lines (34 loc) · 1.24 KB
/
WakeOnLan.cpp
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
53
54
/*
WakeOnLan by Ryan Esteves
Send WOL magic packets
To Use:
(Arduino 1.0+)
1. Initialize WakeOnLan with your EthernetUDP object.
2. Send magic packet using the method 'send(byte* mac, byte port);'
3. Repeat step 2 for as many packets as you would like to send.
(Arduino 0023-)
1. Initiate Udp
2. Send magic packet using the static method 'send(byte* mac, byte port);'
3. Repeat step 3 for as many packets as you would like to send.
*/
#include "WakeOnLan.h"
byte WakeOnLan::_ip[4] = {255,255,255,255};
#if defined(ARDUINO) && ARDUINO >= 100
void WakeOnLan::send(byte* mac, byte port, EthernetUDP udp) {
byte preamble[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
byte i;
udp.beginPacket(_ip, port);
udp.write(preamble, sizeof preamble);
for (i = 0; i < 16; i++)
udp.write(mac, sizeof mac);
udp.endPacket();
#else // ARDUINO not defined or ARDUINO < 100
void WakeOnLan::send(byte* mac, byte port) {
byte magic_packet[102] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
for (byte i = 6; i < 102; i++)
{
magic_packet[i] = mac[i%6];
}
Udp.sendPacket(magic_packet, 102, _ip, port);
#endif // #if defined(ARDUINO) && ARDUINO >= 100
}