In the following post, I’m going to show you how to power on a PC using the Wake on Lan feature and your Arduino.
Almost all the actual network adapters have a feature called Wake on Lan, that is the ability to “wake” the PC with a special command sent through the network.
Requirements
Two main requirements to use this feature:
- if your network adapter is not embedded in the motherboard, you have to connect them with a cable:
- the WOL functionality has to be enabled in the BIOS:
A typical limit in WOL usage is that network adapter isn’t able to wake the PC if it was shut down by power loss. Actually, recent motherboards can enable WOL functionality even after a power loss; you can configure this feature in motherboard’s BIOS:
Magic Packet
The wake command is issued sending on the network a specific packet, called Magic Packet. This packet is receved by all the devices connected to local network because it presents – as destination MAC address – the broadcast address (FF:FF:FF:FF:FF:FF). It includes six bytes valued FF, followed by the target PC’s MAC address repeated 16 times.
Even if it’s not important which high level protocols you choose, it’s a convention to use UDP protocol and destionation port 7 or 9.
Arduino
[highlight color=”yellow”]Note: EtherCard library had a bug in the Magic Packet creation. I solved the problem and my change has been accepted in the official repository: so make sure to download library’s latest version[/highlight]
You can use sendWol() method to send the Magic Packet; that method needs target PC’s MAC address as a parameter:
static byte targetmac[] = {0x00,0x1A,0x4B,0x38,0x0F,0x5C}; ... ether.sendWol(targetmac); |
As usual, you can find a complete example in the GitHub repository related to this tutorial.
Using a network analysis tool like Wireshark, you can inspect the packet sent by Arduino and note that it’s correct:
- in red the destination broadcast MAC address
- in green the choice of IP and UDP protocol
- in light blue the target PC’s MAC address repeated 16 times
Nice work. Next would be interfacing an GPRS shield with the same Arduino so that remote wakeup can be achieved. Of course after PC powers on, we can use it and access files remotely using remote desktop software.
Thanks Arup! It’s a good idea, a GSM shield has just been shipped to my home 😉 Stay tuned for a new blog post about it!
Great Job Luca , will work with wiz5100 ethernet shield?
Thanks Gonzalo,
no, it won’t work because W5100 chip is very different from ENC28J60… as it is the chip chosen for the “official” ethernet shield, you can find a lot of documentation on Playground.
Thank you for this nice piece of code.
It’s a shame it doesn’t work on the W5100 chip.
Have some of you found a way to get it to work on the W5100 chip?
Hi Christian,
it seems WZ5100 does not supporto WOL functionality…
I found an article from Wiznet official blog about W5200 that adds WOL:
http://blog.wiznet.co.kr/w5200-arduino-ethernet-library
thank you very much for correcting the library. I tried to fix it also, it is more useful now! Work fine with ENC2860 connected to Arduino. WOL ok for me. Thank’s again !
Thanks!
when i try to upload i get a ethernet not declared message.. and nu upload to the arduino uno
i have the library in the correct folder?
using IDE 1.0.4
Hi! Did you follow this tutorial about how to install the library?
ciao,
interessante articolo.
io ho una scheda (non shield) con enc 28j60.
volevo fare un wake-on-lan però in modo che ricevendo un magic su porta 9 ad esempio dal router, mi spedisca un magic packet come nell’esempio contenente il MAC del pc che voglio accendere. Quindi su ricezione del pacchetto e non su pressione del tasto ‘w’
Inoltre non ho DHCP quindi dovrei impostare
IP, Subnet mask e Gateway. Come faccio?
Ma un elenco completo (con descrizione) delle primitive dentro a EtherCard dove lo trovo?
Grazie, ciao
Ciao Francesco
non ho capito bene la tua necessità: vuoi comandare il wake-on-lan da remoto? Ad es. pubblicando una pagina web da Arduino che puoi raggiungere via Internet con un pulsante “wake” che fa inviare il magic packet? In questo caso puoi combinare i miei due tutorial (wake on lan e accensione led da pagina web)
Thanks for this. I just had it in my head to make my media PC turn on over WOL along with an IR receiver waiting for a “Power” signal from our remote.
I already have several ENC28J60’s and thanks to you I know that I can use one for just this task (assuming the media PC supports WOL, will check when I get home).
I built this out yesterday and it works like a charm! Again, thanks.
si puo ank fare via usb?
I’m having trouble running this, even after downloading the library it reports errors. Could you help out?
Hi, which errors?
Ciao Luca, ti scrivo perchè ho un problema che non riesco a risolvere e tu sicuramente avrai una soluzione.
Vorrei realizzare un progettino che oltre a pilotare dei relè connessi con Arduino Mega, mi faccia uno scan degli indirizzi IP fissi della mia rete LAN e mi torni come informazione tutti quelli che sono attivi e connessi.
Tutta la parte dei relè e delle informazioni l’ho risolta. Il problema è che quando cerco di utilizzare il PING per vedere cosa è connesso in LAN tutto il resto del programma non funziona più.
E’ come se vi fosse incompatibilià tra l’utilizzo di UDP e l’utilizzo di .
Dopo avere fatto ping ai vari indirizzi fissi, come facci a fare tornare la w5100 in posizione di ascolto?
grazie anticipatamente
Angelo