Physical WakeOnLan button with Raspberry Pi and Python
This is a fun little demo I threw together in an evening. I'm running Raspbian "wheezy".
Wire up a switch (or switches) to your GPIO port. I have switches connected to GPIO pins 22, 23, and 24.
Install RPIO.
sudo apt-get install python-setuptools sudo easy_install -U RPIO
Install wakeonlan.
sudo apt-get install wakeonlan
Check that you wired your switch up correctly by running ‘rpio-curses' from the terminal. You should see the state of the GPIO pin change when you press the button.
Save the following code to 'gpio-wol.py':
Run gpio-wol.py and try it out. Note: the RPIO library requires root access.
sudo python gpio-wol.py
When you press a button, this is the output you should see:
Sending magic packet to 255.255.255.255:9 with 00:00:00:00:00:00
If you have any trouble, you can open up Wireshark and scan for UDP packets. Since UDP is connectionless, it is broadcast to all machines in the subnet. If you can see the WOL UDP packets and your machine isn't waking up, double-check the MAC address. Also, make sure that the machine is setup to accept WOL packets, which might mean a trip to the BIOS to change some settings.
I would like to point out that you could bind any terminal command to a physical button using this technique by simply changing the gpio_callback() function. How cool is that?