Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethernet support #8

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions .github/workflows/PlatformIO.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
name: PlatformIO CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
example: [[esp32dev, examples/WakeOnLan-ESP32/WakeOnLan-ESP32.ino], [nodemcuv2, examples/WakeOnLan-ESP8266/WakeOnLan-ESP8266.ino]]

steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install PlatformIO Core
run: pip install --upgrade platformio

- name: Build examples
run: pio ci --lib="." --board=${{ matrix.example[0] }}
env:
PLATFORMIO_CI_SRC: ${{ matrix.example[1] }}
name: Build CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
example: [[esp32dev, examples/WakeOnLan-ESP32/WakeOnLan-ESP32.ino], [nodemcuv2, examples/WakeOnLan-ESP8266/WakeOnLan-ESP8266.ino]]
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install PlatformIO Core
run: pip install --upgrade platformio
- name: Build examples
run: pio ci --lib="." --board=${{ matrix.example[0] }}
env:
PLATFORMIO_CI_SRC: ${{ matrix.example[1] }}
52 changes: 40 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ To install the library in the PlatformIO IDE, use the library name like so:
WiFiUDP UDP;
```

#### (or) Include and initialize EthernetUdp
```cpp
#include <EthernetUdp.h>
EthernetUdp UDP;
```

#### Include and initialize WakeOnLan class
```cpp
#include <WakeOnLan.h>
Expand All @@ -24,13 +30,19 @@ WakeOnLan WOL(UDP); // Pass WiFiUDP class

#### Add this line in void setup() (optional)

`WOL.setRepeat(3, 100); // Repeat the packet three times with 100ms delay between`
```cpp
WOL.setRepeat(3, 100); // Repeat the packet three times with 100ms delay between
```

#### After connecting to WiFi successfully, Calculate and set the broadcast address (optional)
`WOL.calculateBroadcastAddress(WiFi.localIP(), WiFi.subnetMask());`
```cpp
WOL.calculateBroadcastAddress(WiFi.localIP(), WiFi.subnetMask());
```

#### Manually set the broadcast address (optional)
`WOL.setBroadcastAddress("192.168.1.255");`
#### Manually set the broadcast address (optional; default to 255.255.255.255)
```cpp
WOL.setBroadcastAddress("192.168.1.255");
```

## **Usage**

Expand All @@ -42,10 +54,14 @@ const char *MACAddress = "01:23:45:67:89:AB";
```

##### Send WOL UDP packet (Using the default port - 9)
`WOL.sendMagicPacket(MACAddress);`
```cpp
WOL.sendMagicPacket(MACAddress);
```

##### Send WOL UDP packet (Use port 7)
`WOL.sendMagicPacket(MACAddress, 7);`
```cpp
WOL.sendMagicPacket(MACAddress, 7);
```


#### Set MAC address and SecureOn variables
Expand All @@ -55,10 +71,14 @@ const char *secureOn = "FE:DC:BA:98:76:54";
```

##### Send WOL UDP packet with password (Using the default port - 9)
`WOL.sendSecureMagicPacket(MACAddress, secureOn);`
```cpp
WOL.sendSecureMagicPacket(MACAddress, secureOn);
```

##### Send WOL UDP packet with password (Use port 7)
`WOL.sendSecureMagicPacket(MACAddress, secureOn, 7);`
```cpp
WOL.sendSecureMagicPacket(MACAddress, secureOn, 7);
```

### **Send WOL from byte array MAC Address**

Expand All @@ -68,10 +88,14 @@ uint8_t MAC[6] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB}; // 01:23:45:67:89:AB
```

##### Send WOL UDP packet (Using the default port - 9)
`WOL.sendMagicPacket(MAC, sizeof(MAC));`
```cpp
WOL.sendMagicPacket(MAC, sizeof(MAC));
```

##### Send WOL UDP packet (Use port 7)
`WOL.sendMagicPacket(MAC, sizeof(MAC), 7);`
```cpp
WOL.sendMagicPacket(MAC, sizeof(MAC), 7);
```


#### Set MAC address and SecureOn in variable
Expand All @@ -81,10 +105,14 @@ uint8_t SECURE_ON[6] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54}; // FE:DC:BA:98:76:5
```

##### Send WOL UDP packet with password (By default port 9)
`WOL.sendSecureMagicPacket(MAC, sizeof(MAC), SECURE_ON, sizeof(SECURE_ON));`
```cpp
WOL.sendSecureMagicPacket(MAC, sizeof(MAC), SECURE_ON, sizeof(SECURE_ON));
```

##### Send WOL UDP packet with password (Use port 7)
`WOL.sendSecureMagicPacket(MAC, sizeof(MAC), SECURE_ON, sizeof(SECURE_ON), 7);`
```cpp
WOL.sendSecureMagicPacket(MAC, sizeof(MAC), SECURE_ON, sizeof(SECURE_ON), 7);
```


### **Generate magic packet**
Expand Down
47 changes: 47 additions & 0 deletions examples/WakeOnLan-ESP32-Ethernet/WakeOnLan-ESP32-Ethernet.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>

#include <WakeOnLan.h>

EthernetUdp UDP;
WakeOnLan WOL(UDP);

void wakeMyPC() {
const char *MACAddress = "01:23:45:67:89:AB";

WOL.sendMagicPacket(MACAddress); // Send Wake On Lan packet with the above MAC address. Default to port 9.
// WOL.sendMagicPacket(MACAddress, 7); // Change the port number
}

void wakeOfficePC() {
const char *MACAddress = "01:23:45:67:89:AB";
const char *secureOn = "FE:DC:BA:98:76:54";

WOL.sendSecureMagicPacket(MACAddress, secureOn); // Send Wake On Lan packet with the above MAC address and SecureOn feature. Default to port 9.
// WOL.sendSecureMagicPacket(MACAddress, secureOn, 7); // Change the port number
}

void setup() {
WOL.setRepeat(3, 100); // Optional, repeat the packet three times with 100ms between. WARNING delay() is used between send packet function.

// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
Ethernet.begin(mac);

while (Ethernet.linkStatus() != LinkON) {
delay(500);
Serial.print(".");
}

WOL.calculateBroadcastAddress(Ethernet.localIP(), Ethernet.subnetMask()); // Optional => To calculate the broadcast address, otherwise 255.255.255.255 is used (which is denied in some networks).

wakeMyPC();
wakeOfficePC();
}


void loop()
{
Ethernet.maintain();
}
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"maintainer": true
}
],
"version": "1.1.7",
"version": "1.2.8",
"frameworks": "arduino",
"platforms": "espressif32, espressif8266"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=WakeOnLan
version=1.1.7
version=1.2.8
author=a7md0 <[email protected]>
maintainer=a7md0 <[email protected]>
sentence=Generate and send Wake On Lan (WOL) packet over UDP protocol.
Expand Down
Loading