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.

Office window time-lapse

As followers of this blog will know, I’ve been experimenting with a Raspberry Pi (RPi) and one of the uses that I found for it is as a webcam server. I have plans to put a permanent webcam in the TrustIV office window in Manchester and I’ll be using a RPi to do this.

My installation is pretty straightforward:

  • Raspberry Pi
  • Logitech C270 webcam
  • Shared windows folder for storage of images

I installed the standard Raspbian operating system and connected the Pi to the Office network. Once I identified it by IP address, I connected to it via SSH. I left the RPi in “headless mode” without a keyboard, monitor or mouse attached.

I installed fswebcam software. Fswebcam is a simple webcam app. It captures images from a V4L1/V4L2 compatible device or file, averages them to reduce noise and outputs the image to PNG or JPEG formats. The resulting image can then be saved to a file, like the image below.

Webcam time-lapse

Click on the image above to see the timelapse, alternatively read on for the geeky bit…

I mounted an external shared windows folder (called nas) using these commands:

cd /mnt
sudo mkdir nas
sudo mount -t cifs -o username=<username>,password=<password> //PC/nas /mnt/nas
(instructions from the Raspberry Pi adventures blog.

Then I wrote a short script called webcam.sh  that created a folder on the NAS and saved images to that share at five-second intervals

mkdir /mnt/nas/$(date +”%Y%m%d”)
sudo fswebcam -r 640×480 -S 15 –jpeg 95 –save /mnt/nas/$(date +”%Y%m%d”)/webcam.jpg

while true
     sudo mv /mnt/nas/$(date +”%Y%m%d”)/webcam.jpg /mnt/nas/$(date
+”%Y%m%d”)/webcam_$(date +”%m%d%Y%H%M%S”).jpg
     sudo fswebcam -r 640×480 -S 15 –jpeg 95 –save /mnt/nas/20130121/webcam.jpg

run using
sudo ./webcam.sh

To “stitch” the video together, I used Windows Live Movie Maker to convert the folder of images to a time-lapse video. Images were replaced every 0.05 seconds, meaning that the “action” was sped up 160x faster than real life.

If you read this far, well done. The video is now on the TrustIV blog page, click the image below to see the timelapse footage, and keep checking back there for the webcam. (When I finally get round to installing it) 🙂

Webcam time-lapse