Tag Archive for Technical

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
     do
     sleep5
     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
done

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

 

 

Google Cloud Print – Is this Google’s best kept secret?

Printing to your iPhone or iPad
Yesterday I was in the TrustIV office and I registered to attend a Microsoft Partner event in Manchester. At the end of the process I was advised to print a copy of the ticket to take with me so that I could be given access on the day of the event.

I had registered using Google Chrome browser but because I rebuilt my laptop last week I didn’t have a default printer. Perhaps this is what drew my attention to a printer that I didn’t remember configuring.

Chrome screenshot

As well as this, I noticed a link to my iPad. I have installed Google Chrome on each of these devices but until now I hadn’t noticed that this gave printer support.

I printed my ticket to the iPhone and within a few seconds I was a pop-up on my iPhone to say that a document was ready to view. Clicking on the link opened Google Chrome where I could view a copy of my document…… or so I thought.

iPhone screenshot - document ready

 

When Chrome opened I saw a warning message saying that I had to sign in and enable the print-to-phone feature to see my documents.

iPhone screenshot - Print-to-phone jobs are available: please sign in and enable this feature to get data

 

I wasn’t sure how to do this initially but then I found that if I opened  “Settings” -> Basics, then clicked on my Google account name, I was able to enable the “Chrome to Mobile” setting which meant that I could view my printed documents.

 

So far so good, but a little experimentation showed me even more features.

Printing from your iPhone/iPad
By modifying settings in Chrome it is possible to allow iPhones or iPads to print to your PC or laptop printer. [Other devices are available – Ed]

  • Open Chrome settings (using your mouse to click the “three horizontal lines” icon or typing chrome://settings/ in the address bar.
  • Click “Show advanced settings…”
  • Scroll down to “Google Cloud Print”
  • Click “Manage Print Settings”

This opens a page where you can grant different Google accounts access to your laptop or PC printers. Once you do this it is possible to print directly to your shared printers from within your iPhone applications.

This is such a useful feature, I can’t believe that I hadn’t heard of it until now.

Vivit interview at HP Discover, Frankfurt

On Thursday 6th December at HP Discover in Frankfurt, Jason Kennedy, Martijn Stuiver and I were asked to discuss how Vivit is changing from a primarily US-centric, practitioner-focused user community to one which helps support our members as the IT world changes around them.

The interview covers the changing demographics of the Vivit user community, how we plan to alter our content to suit our membership, our development of new social media channels, the growth of our membership as well as the development of new special interest groups such as “Cloud Builders” and “Security” alongside our existing special interest groups.

Vivit interview at HP Discover, Frankfurt

Vivit interview at HP Discover, Frankfurt

For more information and to join the Vivit community (it’s free by the way), go to
http://www.vivit-worldwide.org

Bristol Pound – a great concept but a flawed web launch

I was drawn to the Bristol Pound project by a tweet that I spotted at lunchtime today.

The concept is simple:

  • Launch a local currency to help support the local economy in Bristol.
  • Encourage people to support local businesses.
  • Boost local spending power and lock money into the Bristol economy.

This all sounds great, but I just went to their website at  http://bristolpound.org  and the page took more than 3 minutes to download. Now I’m not blessed with the world’s fastest Internet connection in the office, but that’s a lot longer than most people are prepared to wait.

I was reminded of a couple of StrangeLoop infographics:

The first one describes web user’s boredom thresholds and shows that people abandon slow sites quickly, many never return and even worse, they tell their friends about their bad experience. This can be very damaging for a brand that puts so much effort into their day 1 launch.

 

User boredom thresholds - infographic

 

The second infographic documents the increasing size of pages over time. I know that we all use high speed internet connections nowadays, but if a lot of people start to hit your site, you’re going to run out of bandwidth to serve the requests pretty quickly.

 

I think that the Bristol Pound website is suffering from “page bloat” and here’s why…

Using a Firefox browser with an empty cache and Firebug, I connected to http://bristolpound.org and saw that it took almost 3 minutes for the page to download completely. The page looks great and is graphically rich, but it doesn’t perform well for those first-time visitors hitting the site today.

The image below which is taken from the HAR (HTTP archive) file that I created shows a single image taking 2.33 (139 seconds) minutes to download. The large/slow image is called FINAL_Launch_POSTER_copy.jpg , and it is advertising tonight’s launch party for the Bristol Pound.

 

 

The main problem with this image is that somebody has uploaded the full size image to the website and rescaled it using HTML. The original image size is 3,508 x 4,966 pixels which is huge, but it is displayed at only 338 x 495 pixels. Serving a scaled-down image could save 1.8MB of bandwidth for each page request (a 99% size reduction). This would reduce the download time for this component from about 139 seconds to less than 2 seconds. This alone would significantly improve user’s first impressions of the site.

This screenshot shows the “offending image” highlighted in red.

 

There are other improvements that could be made, but to improve performance for now, I’d simply resize the image in an image editor (MSPAINT would do) and then keep my fingers crossed…..