Arduino Wakes My PC
This Arduino progject using arduino Uno + ethernet shield(W5100). It’s Application. used W5100 chip WOL(Wake on lan).
I needed a way to bring it on whenever I wanted. So I tought I could use an Arduino with an Ethernet shield to send the Wake On Lan packets.
The UdpRaw allowed me to send raw packets, so all I needed was to implement the “magic packet” – it consists of 6 times 0xFF followed by 16 times the target MAC address.
So, first, I store that MAC address in a byte array. Take “00:00:00:36:45:C1″ as my example target MAC:
byte wolMac[] = { 0x00,0x00,0x00,0x36,0x45,0xC1 };
Now, all I need is to copy that 16 times, after 6 * 0xFF (102 bytes total). This is how I did it:
byte all[102]; int i,c1,j=0; for(i = 0; i < 6; i++,j++){ all[j] = 0xFF; } for(i = 0; i < 16; i++){ for( c1 = 0; c1 < 6; c1++,j++) all[j] = wolMac[c1]; }
After running this code, the “all” array will have the complete magic packet, ready to send:
UdpRaw.sendPacket(all,102,targetIp,targetPort);
So to test it, I thought of a simple program that sends the packet when a pushbutton is pressed. To do this, I used an interrupt at pin 2. Basically, the Arduino keeps listening to that pin and whenever it raises from LOW to HIGH, it will execute a certain function.
After this, I plan to make the Arduino to listen to a port from the Internet and whenever it receives a certain packet sequence, it wakes the computer. This way I’ll be able to power up the computer from anywhere in the world!
Here is the whole Arduino code:
/* * Arduino WakeMyPc * Ricardo Dias * http://ricardo-dias.com/ * * This sketch sends the "magic packet" to wake up * a PC on Local Area Network when a push-button * is pressed. */ #include <Ethernet.h> #include <UdpRaw.h> // ARDUINO CONFIG byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Arduino MAC byte ip[] = { 192, 168, 1, 112 }; // Arduino IP byte gw[] = { 192, 168, 1, 254 }; // Gateway IP address int localPort = 8888; //local port to listen on // THE TARGET byte targetIp[] = { 192, 168, 1, 255 }; int targetPort = 5456; byte wolMac[] = { 0x00,0x00,0x00,0x36,0x45,0xC1 }; // The target PC Mac Address void setup() { Ethernet.begin(mac,ip,gw); UdpRaw.begin(localPort); // Will run the sendPkt() function when a button wired to // pin 2 is pressed attachInterrupt(0, sendPkt, RISING); } void loop() { delay(1); } void sendPkt(){ // The 'magic packet' consists of 6 times 0xFF followed by 16 times // the hardware address (MAC). byte all[102]; int i,c1,j=0; for(i = 0; i < 6; i++,j++){ all[j] = 0xFF; } for(i = 0; i < 16; i++){ for( c1 = 0; c1 < 6; c1++,j++) all[j] = wolMac[c1]; } UdpRaw.sendPacket(all,102,targetIp,targetPort); }
original link – http://ricardo-dias.com/2010/11/20/arduino-wakes-my-pc/
COMMENTS