Tuesday 29 July 2008

Graphing Current Cost

After hooking up my Current Cost Meter to a database recently I've been logging my power usage so the next step is to look at what I can do with the data. As I mentioned when I introduced my meter lots of other people have been looking into this as well.

I like Dale's idea for creating a daily energy bill so I've decided to aim towards that but include a graph of the days usage and possibly a link to a web page where I can look at more details of that days use.

With the web page idea in mind I decided to look into what I could do graph wise in PHP since that's my web language of choice. After looking through a few options I plumped for the obvious library, that of PHP Image Graph as it's part of PEAR so should be fairly decent, complete, well used and flexible. Here's where I'm at so far:
That's just a small snipped of 1 days power usage when I was cooking dinner. You can see I turned on my steamer (approx 800 watts) at about 5:30pm then went on to turn on the oven which heated up then cut in and out while it was cooking before I turned it and the steamer off just before 6pm.

As you can see, I'm pretty much there with the graphing side of things. The only issue left is to sort out the X axis. While it might appear to be a bit crazy, the current cost meter only samples approximately every 6 seconds. Because of the different number of samples in each hour and with a few rounding errors, the X axis appears not to be linear. Hopefully, I'll solve this by ensuring a consistent number of samples in each time slot.

Overall, PHP Image Graph seems very powerful. You can graph pretty much anything with it in all sorts of formats and have relatively complete control over the way the graph looks. I'm not at all artistic so mine looks very plane! There is, however, a reasonable barrier to entry. Documentation for the API is relatively complete if you know where to start, but documentation in general seems really rather thin on the ground and very sketchy. But, thankfully someone produced a great set of demos for a PHP conference that really show off a lot of the features. The source is available too so it's easier to work out what to do with your own graphing and how to get started. I'll probably blog my source code at some point, it's not very long, but definitely requires some tidying before it's ready for a public outing.

What I want to do next is take the graph and produce some sort of daily "bill" e-mail. That will have a link back to a private area on my web site that would allow closer inspection of certain areas of the graph. This is just the next step in education for how to save electricity by learning how much different combinations of devices use together. For example, is it better to steam fish in a steamer, grill, oven cook, etc. Hopefully, I'll be able to apply those sorts of questions all around the house to work out how to be as green as possible.

Wednesday 23 July 2008

Next Generation Linux

The folk following me on Twitter are probably sick of hearing about identity management, the main stay of my work this year. So I was glad to get out of the office last week to present at an IBM conference in London called "Next Generation Linux". A thank you note I received reminded me I should blog about it, always nice to receive those! Next Generation Linux is an event IBM are running in various worldwide locations this year looking at what comes next for Linux for businesses.

Being a Linux geek working in a software services organisation called Emerging Technology Services and with my contacts I like to think I was the natural choice for the pitch titled "Emerging Linux Technologies". I only had a short amount of time to present a vast field of topics so I narrowed it down to just five topics compelling for business and talked about the following:
  1. Virtualisation
    OK, not strictly an emerging technology as many businesses have already adopted it. But, it was a good opener setting the scene for some of my other topics and allowed the opportunity for me to briefly run through a few virtualisation technologies for Linux.
  2. Cloud Computing
    An exciting name and concept for what is essentially some very well thought out system administration. This technology has always been feasible but it's being made possible now with commodity hardware capable of remote management and some neat software ideas holding it all together. The really novel thing is the way applications can be deployed to run in the cloud environment and the fact we can actually package this up as a solution now. It's the realisation of "On Demand" computing.
  3. Project Big Green
    Green computing is becoming much more of a concern as business starts to run out of room in data centers, power requirements head skywards and running costs steadily increase. Last year IBM announced a re-investment of $1 billion into research towards green computing which gives business the opportunity to cut running costs and jump on the green band wagon at the same time. Green computing is essentially about consolidation of services, allowing spare compute power to be utilised elsewhere, and making sure equipment is environmentally produced and disposed of. It's those three words we hear in all good green campaigns, reduce-reuse-recycle, do it!
  4. Security Enhanced Linux (SELinux)
    One of my specialisms and a topic I could ramble on about for a long time, I'll try to keep it brief. In this short pitch I indicated security is still an issue in 2008 and it can cost you big time if your security is breached. Enter SELinux, an overview of what SELinux is and where it comes from and a comparison with other technologies such as AppArmour is a good start. To get to the crunch of SELinux though, I explain the differences between Discretionary Access Control (DAC) and Mandatory Access Control (MAC) and the ultimate advantages SELinux brings for security.
  5. Real Time Linux
    Real time really is an emerging area with both of IBMs current Linux partners, Red Hat and SUSE, bringing out offerings recently. Real time is built from the hardware up through the OS and in the case of hard real time into the applications too. IBM have certified some particular System X hardware to be real time capable and provide firmware and support for this now. Next comes the Linux piece where some of the firmware functionality removed from hardware must now be implemented in the kernel, there's loads of ways of doing this but to get support for it SUSE and Red Hat take care of that. IBM have also built some enhancements to Java, by introducing a modified garbage collector (Metronome) and providing ahead of time (AOT) compilation while complying with RTSJ, all of which add up to the ability to write real time Java apps - interesting! Now we can offer a full real time system on non-specialised hardware, using a commercially available operating system and a language loads of people can program, backed by IBM through Websphere Real Time. Boy that sounds like an advert, sorry about that, but it is a great idea, very cool!

This is all very much in brief, if you want to know more then get in touch or leave a comment.

Tuesday 22 July 2008

Current Cost Monitor

A couple of guys at work have managed to lay their hands on a funky new device called a Current Cost meter. It's pretty simple to understand, it measures your household electricity usage and displays it on the screen (left). To do this it comes in two parts, you hook a plastic loop around the live feed going into your fuse box (mine is in the garage) which is connected to some electrical wizardry I don't understand to measure the current without interfering with the wire, and a wireless transmitter device to send the data to the unit you just plug in somewhere in your house.

I jumped at the chance to get one of these things and was one of the first batch to get them at work and a little community of current cost users has built up pretty quickly. That said, pretty much everyone else has beaten me to blogging about it with some very cool results. So here's the list (that I know of) right now, in no particular order we have...As an aside, Dale's just joined my department at work (horay), and Roo is leaving IBM (boo and much sobbing).

There's lots of other people looking into these things too, but those are just the blogs I know about. This type of device isn't exactly new, but what makes this one exciting is the data port and connectivity to a computer. With such a community there's been some cool work done such as graph power usage and send yourself a daily electricity bill. The device itself can't really save you money and definitely doesn't save energy (you have to plug it in) but what it does do a great job of is educating you about exactly what all your household devices like to eat for breakfast.

I'm just starting out at home having had the screen in the kitchen for a couple of months already with looking at what I can do with it while connected to a computer. I'm now logging all the data to a database so I guess one of the first things I'll be doing is graphing my own data. From that I hope to learn even more about what my house does with its power. For now though, the only graph I have (above) is that produced by sending my data via a Nanobroker to Andy Standford-Clark's server. This should hopefully be another fruitful little project for my new (and now you know why it's low power) home server.

Thursday 17 July 2008

Installing Ubuntu On A TinyTuxbox

With my new toy now in hand the time soon came to get it installed with Linux. At first glance it might appear to be tricky to install given the lack of CD or Floppy drives. However, it boots from just about anything you attach to it whether that's USB, Compact Flash or Network Boot. Setting up a one-time PXE server seemed a little over the top so I was planning to boot from a USB stick until I found someone at work with a USB CDROM.

Ubuntu IconUsually I like to run Fedora at home, it's the thing I'm most comfortable with having spent my career tinkering with Red Hat and SUSE based distributions so one of the things I wanted to do with this box was install the much hyped Ubuntu distribution. This wasn't to see what all the fuss is about (I'm familiar with Ubuntu having tried it a couple of times before but always gone back to Fedora) but really just so I can get to know it even better. This machine is going to be part desktop and part server so Ubuntu kind of makes sense too.

I installed the hard disk into the box myself and once I got over some initial hardware niggles (that I caused I should add) the installation was simple. Boot from USB CDROM with the Hardy Heron CD in it and the rest is history. It's amazing how such a small box can run a full whack desktop operating system and do all that on just 8 watts.

In these early days, I have three things in mind for the box. The primary use will be to serve my music collection to my stereo; next is to connect my current cost meter to allow some more in-depth analysis of our power usage at home; then there's simply using it as a desktop for the simpler day-to-day computer usage i.e. browsing the web.

Setting up the music streaming was pretty easy after transferring my collection to the hard disk. I added the apt sources for the SqueezeCenter software that operates with my SqueezeBox Duet, did an apt-get update and an apt-get install squeezecenter and job done. The TinyTuxbox can much better cope with running the MySQL server this is based on along with the web front end and the music collection scanning services associated with the software than the SLUG I tried previously. All in all, couldn't have been much easier.

I've not tried hooking up my current cost meter yet, ironically I've run out of power sockets near the computer with only a six-way adapter and plugs for the PC, TinyTuxbox, Printer, Monitor, ADSL Modem Router, and speakers although it shouldn't be a hard problem to rectify.

Last of all, one of the additional benefits of this low-power box is every day usage. It can easily run a web browser so instead of starting up a large PC just for this, we can switch to the TinyTuxbox desktop and browse there. This should add to our power saving, even though it's likely the TinyTuxbox will be run all the time soon to serve the current cost data. That reminds me, I really should discuss batch-uploading of current cost data so I can save even the 8 watts the TinyTuxbox uses most of the time too.

Sunday 13 July 2008

Introducing the TinyTuxbox

My second choice of home media server arrived on my doorstep last week after my unwillingness to maintain the painfully slow and awkward slug. This time around I've plumped for a TinyTuxbox Series 8 which seems to be a UK resold version of the e-Box 4300. It fits the extra requirements I made after parting with the SLUG, that is it's an x86 based machine and has lots more memory. I'm not the only one at work with one of these types of boxes either, James Taylor has the Netvoyager re-badged version of the previous box to my one, the e-Box 2300.

It is, in fact, a fully functional x86 PC but just a really small one, even smaller than the pretty tiny Fit-PC which I was also seriously considering and probably would have gone for were it not for the excellent pre-sales support of one of the TinyTuxbox staff over e-mail. That said, the excellent pre-sales was balanced with painfully slow delivery. It took 28 days to get it to my door which for a delivery cost of nearly £20 I consider poor. I've been left with a upward feeling though, post-sales support has been promising too as I initially had some problems installing the box, which it turned out were my fault and I solved quickly enough anyway. I'm not going to talk software here though, that's a story for another day. So how does my TinyTuxbox look and spec up....?

The workhorse of the TinyTuxbox is the 500MHz Via Eden ULV processor which provides a 32-bit x86 processor along with a built-in graphics processor with hardware MPEG decoding. The processor is an impressive bit of kit, it runs all that from just 1 watt of power, see the link for the full specs! Away from the processor we have 512MB RAM (some of which is shared for the video output), on-board Ethernet, 3 USB ports, VGA output, a PS/2 connector (supplied with PS/2 Y-Splitter cable to connect both keyboard and mouse), a compact flash slot, sound in and out, power button, and hard disk and power LEDs. The box is also fitted with an IDE connector and can house a 2½" laptop type hard disk in it. I ordered it without the hard disk and fitted my own as the supplied ones were not good value for money probably due to the services incurred from the fitting itself.

The TinyTuxbox site advertises the unit as consuming a maximum of 8 watts and I'm pleased to report that was absolutely accurate. According to my current cost meter, it uses 8 watts with the hard disk spinning so once I get it to spin down on idle it should use very little juice. Click the various images for a link to my Flickr page and some more notes.

Friday 11 July 2008

Introducing Home Easy

One of the things I've been giving consideration to while choosing my media server is home automation. I don't want to go crazy about it and have everything in the house hooked up to a computer so curtains open when alarm clocks go off, or alarm clocks go off earlier if it's freezing outside (to give more time to scrape ice), etc. I'm more interested in a few subtle things to help be more green at home, and possibly to help with security, anything I can get that adds convenience is a bonus but not necessary for me.

The first simple step I've taken along this road is to get some stand-by power savers that are getting ever more popular these days. The one I went for was the introductory pack from the Home Easy range which are manufactured by Byron and retailed exclusively through B&Q.

The pack gives you three radio controlled sockets into which you can plug your devices at home, and a remote control to turn on/off the sockets. So, by plugging in my TV, DVD, Wii, and other devices to one of these via their 4-way extension lead I can turn off a whole bunch of stand-by with the click of a remote control button anywhere in the house.

The Home Easy range is relatively complete for a UK home automation solution not based on X10. The kit is reasonably priced too with the 3 sockets and remote costing £20, unlike X10 end points. One of the reasons for choosing Home Easy over another popular standy-by saver is that the range is more complete, but also the protocol is well known so third parties are starting to produce devices compatible with Home Easy too. For example, rfxcom have certified their transceiver to work with Home Easy so it's now possible to computer control Home Easy devices - nice!

The next tentative steps I'll be looking to take on this road are having a home on/off switch. It's annoying having a single remote control, it's small, you have to find it, and it might be upstairs/downstairs and probably not where you are. I want to take advantage of the home easy grouping facility to have a switch that basically turns my house on or off. We should be able to leave the house (or go to bed) and turn all the stuff we're not using off, and turn back on again when we get home (or wake up).

Just this one purchase can save me anywhere between 20 and 50 watts in stand-by power. At 10 pence per kilowatt hour (typical rate) I'll get my £20 back with just 6 months usage. So it's green and saves you some dosh too, bonus!

Friday 27 June 2008

Squeezebox Duet: What's in the box?

I've had my Squeezebox Duet at home for quite some time now, since I was experimenting with using a slug as a home media server. I've been waiting for my replacement for the slug for some time now and it's still not arrived so the home media server project has stalled somewhat at the moment. However, I do still have the Squeezebox set up and even though I'm not really using it right now here's what you get in the box when you buy one...

The packaging feels very nice indeed, as it should along with the rest of the stuff in the box given the price if I'm honest. Once you slide the box out of it's card sleeve you're faced with a rather sleek minimal looking flip top black box:


The next thing is to flip that lid up and you see a very neatly laid out set of Squeezebox gear which I've positioned after a little unpacking:


So in the box we have a whole array of different stuff. There is, of course, the squeezebox remote and the receiver boxes, these are powered via some reasonably small AC-DC transformers which have changeable plugs. Plugs are supplied for European, US and UK sockets so you don't have to worry about getting a localised unit for your area which is a neat trick. The remote control has a charging stand so you can return it to its cradle when you're finished using it and it will stay charged all the time. You also get a set of reasonable length RCA leads to connect the receiver to your amplifier. Last, you get a fairly minimal manual which I've hardly used as all the best documentation is on-line:


Setting up really is very trivial, it's just a case of connecting all the wires, so power to the receiver and the remote charging stand, and a connection from the receiver to the amplifier. Once you've done this, just permit access by the two wireless devices (the receiver and the remote are both wi-fi) to your access point. Both devices DHCP and you're up and running with a squeezebox duet, nice and simple. This does, however, only get you Internet provided services if you want to get the full benefit of streaming your own music collection you need the Squeeze Centre software too, and hence I'm still waiting for my media server to be delivered before I get full functionality from my Squeezebox.

Wednesday 18 June 2008

New Thinkpad T61p

Gutted! A couple of weeks ago now I had a bad Friday, the train home from London where I'd been working with a customer all day was stupidly late and I had to change twice instead of going directly home. Then I get home and fire up my laptop to send the e-mail's I'd written during the day and the darned thing didn't work, argh! Seems in spite of working all day, my T41p had died on the trip home. After reporting the problem at work the following Monday it was decided the T41p needed a new motherboard and this wasn't economical to fix, so I was issued with a shiny new T61p a few days later.


I've been pleasantly surprised by my new laptop, I wasn't expecting great things since IBM sold the Thinkpad business to Lenovo but this thing is actually quite nice. I'll spare listing the full gory details to the technical specifications page. However, it has some nice additions over my previous laptop, namely built-in firewire (not that I'm likely to use it), built-in SD card reader (used that already), an extra USB port (always handy), a DVD writer, a hardware wireless off switch (presumably for use in planes), an enormous hard disk (compared to the T41p anyway), and a lovely 15.4" widescreen capable of 1920x1200 backed by a 256MB NVidia graphics card.

Unfortunately, it came pre-installed with Vista so that (along with the stupid Vista sticker next to the keyboard) were the first things to go. I've installed Redhat Enterprise Workstation 5.2 on it which may sound like an odd choice, but IBM have a layer of software designed to sit on top of Redhat to enable us to install things like Lotus Notes, Sametime, etc. This is known as the Open Client internally and works really nicely. Clearly, there are later and greater distributions I could use but on this issue I like to support IBM and the internal community of Linux desktop users so I choose to go with the officially provided solution.

I've been up and running for a week now with no problems so far, I've been able to do all the things I could do with my old laptop and all the things I need to be able to do in order to do my job. Of course, I make some modifications to the way things work to suit my tastes (such as running KDE instead of Gnome) but all these work well too which is a great reflection on the modular nature of all things involved with Linux. I hope I continue to be surprised and pleased with the machine, and I'm definitely surprised at the ease of transition between the two machines for me.

Thursday 12 June 2008

Google Treasure Hunt Question 4

Question 4 has been out for a while now and it's taken me a while to blog the solution for a couple of reasons, I've not had much time to work out the solution recently, and this question seems a lot more difficult than the other three (for me at least).

Here's my question this time around:
Find the smallest number that can be expressed as
the sum of 25 consecutive prime numbers,
the sum of 99 consecutive prime numbers,
the sum of 189 consecutive prime numbers,
the sum of 467 consecutive prime numbers,
the sum of 535 consecutive prime numbers,
and is itself a prime number.

For example, 41 is the smallest prime number that can be expressed as
the sum of 3 consecutive primes (11 + 13 + 17 = 41) and
the sum of 6 consecutive primes (2 + 3 + 5 + 7 + 11 + 13 = 41).


First of all I thought I'd write a routine (once again in Perl) to generate prime numbers. I know I'm not entering a competition to find the worlds largest primes so chose to write an optimised solution rather than a super efficient one. The difference here is computational complexity v coding complexity. I chose the simpler code but less efficient solution rather than the more complicated code but efficient solutions offered by algorithms such as the Sieve of Eratosthenes.

sub primes {
my $max = shift || 10;
my @primes = ( 2, 3, 5, 7 );
return @primes if ($max <= 9);
my $loop = 9;
while (scalar(@primes) < $max) {
my $is_prime = 1;
for (my $div = 3; $div < ($loop-1)/2; $div++) {
$is_prime = 0 if ($loop % $div == 0);
}
push (@primes,$loop) if ($is_prime);
$loop += 2;
}
return @primes;
}


Now I had a way of populating an array with prime numbers I thought about the solution a bit more carefully and decided it wasn't likely to be simple to calculate, however long the code I managed to write was. So, I decided to search around for lists of prime numbers and decided to use a list of the first million primes. I could, on reflection, just used my routine to generate 1 million primes and written them to a file instead of generating each time.

The solution I came up with is shown below. It starts by populating an array with the first million primes from the downloaded file. Then the sums of the required continuous number of primes are generated and stored in another array. At this early stage, the solution is now contained in this array (with the assumption the solution exists within the first one million primes of course) so it's just a case of searching the array to find it. In order to find the number, I numerically sort the list. Now it's a simple case of finding the first (and therefore lowest) prime in the new list that is repeated 5 times.

use strict;
use FileHandle;

sub sum_primes {
my $amount = shift;
my $start = 0;
my @sums;

while ($amount < scalar(@_)) {
my $sum = 0;
for (my $i = $start; $i < $amount; $i++) {
$sum += $_[$i];
}
push(@sums,$sum);
$start++;
$amount++;
}
return @sums;
}

sub read_primes {
my $filename = shift;
my $fh = new FileHandle;
$fh->open($filename) || die "$filename: $!\n";
my @primes;
push(@primes,split) while (<$fh>);
$fh->close();
return @primes;
}

sub is_prime {
my $num = shift;
foreach my $prime (@_) {
return 1 if ($num == $prime);
}
return 0;
}

my @primes = read_primes("1000000.txt");
my @sum_list;
push(@sum_list, sum_primes(25,@primes));
push(@sum_list, sum_primes(99,@primes));
push(@sum_list, sum_primes(189,@primes));
push(@sum_list, sum_primes(467,@primes));
push(@sum_list, sum_primes(535,@primes));
@sum_list = sort(@sum_list);
my $prev = 0;
my $same = 0;
foreach my $num (@sum_list) {
if ($num == $prev) {
$same++;
if ($same == 4) {
print "Found $num, checking... ";
if (is_prime($num,@primes)) {
print "PRIME! :-)\n";;
last;
} else {
print "not prime :-(\n";
$same = 0;
}
}
} else {
$same = 0;
}
$prev = $num;
}


This code takes a few minutes to run. I'm sure it's not the smartest solution to the problem, there must be some maths I can use to calculate a solution. Instead, this approach turns the problem into a search solution but it works pretty well and identified the correct answer of 6990493 for my question.

Tuesday 3 June 2008

Showing Off Linux

Thanks to Ian Hughes for the picture on his flickr. Yesterday, at work, the Hursley Linux Special Interest Group ran a little trade show type event for a couple of hours after lunch. The idea was to provide a bit of away from your desk time for folks around the lab to see what we Linux geeks have been getting up to. Various people interested in using Linux inside and outside work came along to demo their gadgets.

The picture shows me showing off my old Linux audio centre. But, also at the event were the main organiser of the day Jon Levell (showing Fedora 9 and an eeepc), and Nick O'Leary (showing his N800 and various arduino gadgets), Gareth Jones (showing his accelerometer based USB rocket launcher and bluetooth tweetjects), Andy Stanford-Clark (showing his NSLU2 driven house, and an OLPC), Laura Cowen (showing an OLPC), Steve Godwin (showing MythTV), and Chris law (showing Amora).

I thought it was quite a nice little selection of Linux related stuff to look through for the masses of people turning up, plenty of other things we could have shown too of course. The afternoon seemed very much a success, generating some real interest in the various demo items and lots of interesting questions too. Thanks to everyone for taking part!