Raspberry Pi as a WOL server

My electricity supplier in the UK recently sent me a electricity consumption meter which tracks energy use in real time and displays in on a small LCD panel. This has proved to be a real eye opener for me and has helped me to see how much power is used by a variety of devices in the house. I’ve found myself checking the meter at regular intervals and I’m getting good at working out which things are powered on just by checking the meter!

Electricity Consumption Meter
Electricity Consumption Meter

I’m one of those geeky types that likes to leave my home PC on all the time. This means that when I’m away from home, I can connect to the PC remotely and pick up files or refer to old email archives that I don’t keep on my laptop. I haven’t given this much thought until now but I checked the power consumption of my PC and saw that it draws 250W – 300W whenever it’s powered on. I did some rough calculations to see what this was costing me and I was surprised.

Daily power use for my PC = 0.275 KW x 24 = 6.6 KWh
Annual power use for my PC = 6.6 KWh x 365 = 2409 KWh
Average cost in the UK for 1 KWh = £0.14

Annual cost for running my PC all the time = £0.14 x 2409 KWh = £337.26

This made me think about turning my PC off more (as my wife has been suggesting for years) 😉  But I don’t want to lose the ability to turn it on remotely and get access to files….. hence my use of WOL (Wake on Lan).

I recently bought a Raspberry Pi and I’ve been tinkering with it for a while, I’ve used it for time lapse photography and general experimentation. I’ve also put one in the Trust IV office in Manchester which operates a webcam. I thought that I could use the low-powered Raspberry Pi to wake up my high-powered PC when I need it and I’d enable power management on the PC to put the PC to sleep when it isn’t in use.

Here’s how I did it.

  • Installed a base build of Raspbian on my Pi
  • Installed “wakeonlan” on the Pi, using the command [sudo apt-get install wakeonlan]
  • Installed Apache on the Pi, using the command [sudo apt-get install apache2]
  • Installed PHP5 on the Pi using the command [sudo apt-get install php5]
  • Wrote a small PHP script that sends the wakeonlan command to my PC.
  • Changed the default port for the webserver
  • Enabled port forwarding on my router to forward HTTP requests from outside to the Pi.
RPi screenshot
RPi screenshot

The PHP script (above) is pretty straightforward and uses the “exec” command to simply execute the wakeonlan command. I may improve this to give myself some visual feedback to show that the magic packet has been sent to the PC. For now I’m just happy that I can reduce my energy consumption and still access my PC remotely whenever I want to.

Assuming that  this gives me a 50% energy saving, this should reduce the electricity bill by more than £150 per annum.

Author: Richard Bishop


7 thoughts on “Raspberry Pi as a WOL server”

  1. Hi, mate! How’s going?

    So, did you give some kind of permission to the program wakeonlan, or to Apache/lighttpd, to make the whole thing work, because I’ve trying to do the same, although without success. The funny thing is that via Unix-command line everything works fine, whereas when it comes to Apache nothing seems be happening.


    1. Hi Pedro,
      I just used a default Apache installation, enabled PHP (which I tested with a simple PHP test script).

      The php file has these permissions.
      -rw-r–r– 1 root root 48 Apr 24 19:32 rb.php

      Good luck,

  2. Hi buddy, I was wondering if you could please help me? I’ve got a Pi coming soon off eBay, the plan is to vnc to it from work so I can wake up my NAS drive if needed. Can I do this without any php stuff? Ideally I just want a shortcut on the pi desktop that I can run to wake up my NAS. I am a total pi noob so any help would be much appreciated! Cheers mate. Rich

    1. Hi Rich,

      Yes this should be possible, the only problem is security. I used the wakeonlan application on my Pi. You could easily create a shortcut to this or another WakeOnLan application on your Pi’s desktop but you’d need to consider how you’d secure this.

      VNC usually uses port 5900 so you’d need to leave this open on your company firewall and your firewall at home. This may be something that your IT security team frown upon. You could secure this by ensuring that the company firewall only accepts connections from your home address (assuming that you have a static IP from your broadband provider). Similarly, you may be able to configure your router to only accept connections from your company’s IP address. (I’ve worked with clients before where they’ve secured their network in this way and it’s worked well).

      Good luck with your Pi,
      All the best

      1. Thanks for the reply 🙂 security should be no issue for me – The plan is to only allow my company’s IP address to access port 5900 on my own router. This will be no problem as I’M the IT team in my company 🙂 the port forwarding stuff is the easy part, my main problem that I think I might run into is creating the actual shortcut on the Pi desktop. I’ll know more when my Pi turns up hopefully tomorrow. Cheers again mate. Rich

  3. Hi Richard,

    Cool project. I have a RPi that provides DNS on my home network (http://www.ducky-pond.com/posts/2013/Oct/how-to-setup-a-dns-server-with-powerdns-on-raspberry-pi/), and a separate Windows machine running Apache, PHP, and WordPress to serve a website.

    This is just a hobby thing and not a real website, so I don’t want to leave the web server on all the time. But it would be nice if visits to my website would trigger the RPi to wake up my server. There would obviously be a delay in loading the page for a visit that woke up the PC, but better late than never. Also, I could just jump on my webpage any time I wanted remote access to my PC.

    I tried getting remote WoL working with this approach, but having a web server running on the Pi started messing with things – visits to my website would sometimes be redirected properly to my server, and other visits would end up seeing the default It Works! page Apache was serving on the Pi.

    I would like to have the ability to:

    1 – Detect a visit to my website on the Pi. Is there a way for the Pi to programmatically recognize that it has resolved an internal DNS request to my web server?

    2 – Send a WoL packet to my web server. I should just be able to do this by installing wakeonlan and PHP, and leaving Apache off.

    Anyway, like I said cool work, and I’d love to hear any thoughts you may have on step 1 up there. Thanks!

    1. Hi Cory,

      I’m not sure how you could trigger an action when a particular DNS query was executed. Maybe you’d schedule a task to run every minute using CRON that runs a TAIL query against the DNS log and GREPs it to see whether the IP address of your webserver was returned. You could then use an IF statement to run the WOL script if a query for the webserver had been performed.

      I really liked this article that I read recently about how Einstein solved problems by the way.

      It recommends taking a step back before trying to find a solution. I could benefit from thinking more like Einstein. Maybe you could skip step 1 (programatically checking to see if a DNS request has been received) and just install the WOL/Apache and PHP. Are you avoiding this because of concerns re: Apache performance or security?

      Good luck…

Comments are closed.