Skip to content

Commit

Permalink
Ethernet experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
a7md0 committed Aug 22, 2023
1 parent bac9a81 commit ecf5e37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/PlatformIO.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ jobs:
run: pip install --upgrade platformio

- name: Build examples
run: pio ci --lib="." --board=${{ matrix.example[0] }}
run: pio ci --lib="." --lib="Ethernet" --board=${{ matrix.example[0] }}
env:
PLATFORMIO_CI_SRC: ${{ matrix.example[1] }}
19 changes: 9 additions & 10 deletions examples/WakeOnLan-ESP32-Ethernet/WakeOnLan-ESP32-Ethernet.ino
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#include <WiFi.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>

#include <WakeOnLan.h>

EthernetUdp UDP;
WakeOnLan WOL(UDP);

const char* ssid = "your-ssid";
const char* password = "your-password";

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

Expand All @@ -24,19 +22,19 @@ void wakeOfficePC() {
// WOL.sendSecureMagicPacket(MACAddress, secureOn, 7); // Change the port number
}

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

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

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

WOL.calculateBroadcastAddress(WiFi.localIP(), WiFi.subnetMask()); // Optional => To calculate the broadcast address, otherwise 255.255.255.255 is used (which is denied in some networks).
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();
Expand All @@ -45,4 +43,5 @@ void setup()

void loop()
{
Ethernet.maintain();
}

0 comments on commit ecf5e37

Please sign in to comment.