Archives 2007

Bletchley Park

Had a trip down to see Martyn and Em the other week and ended up having a day trip out to Bletchley Park, home of the code breakers during World War II. This is the place where the Enigma code was decoded, and the worlds first programmable computer was produced, Colossus, which has been lovingly rebuilt from eight war time photos and some illegally kept partial circuit diagrams. (It was in England, not America, that the first computer was built. Don’t let anyone tell you otherwise!) Well worth a trip to see, especially if you are in to computers or anything from the WWII era. There are collections of Churchill memorabilia (one couple’s personal collection, put on show for everyone), cinematography, and other similar things. Also, the stately house is open for wanderings which may interest people too

Also, getting started at Bletchley Park, is the National Museum of Computing. It isn’t quite ready for the public yet, but Martyn, being of geek persuasion, wanted to volunteer which meant we got a private guided tour around what was happening behind the scenes. The plans that they have for the place look rather impressive, including a room dedicated to british computing. It looks like there may well be quite a bit of hands on exhibits too, including all the home computers running classic games for you to play. I’m going to make a list of all my old computers (including a very old Compaq luggable) to see if I can make any donations. Not holding my breath, but if I can get rid of a couple of items to a good home that will make me happy!

So, if you are ever in the area and want a good day out it is well worth the trip. You can go back at any point within a year of your first visit for free too which I think we probably will do when the computer museum opens.

Astro Empires / Tribal Wars – Great new way of wasting time!

Recently I’ve been playing a game that Lionel put me on to called Tribal Wars which is very good fun. Basically its a web based strategy game where you build up your village, recruit some thugs, and plunder other villages around you, eventually taking over other villages and growing your empire. To help all this you can also if you wish join a guild and enlist the help/protection of hundreds of other players. The best part of all is the fact that it is set up to play over a very long time. Building and recruiting is done over a span of hours, along with resource build up. This means that you can set something up in the morning, go to work and leave it to run its course.

After playing that for a month or two, I’ve had a look for a different one to play with a more sci-fi theme and have no found one called Astro Empires. The basics are very similar to Tribal Wars except on a larger scale. In this you set up your base and build up your structures whilst researching new technologies. Once you get to a certain level you then start sending out your scouts and outpost ships to colonise new planets. Again you have the choice of joining guilds to help you which comes in very handy if someone decides to attack you! Astro Empires is actually a lot more flexible than Tribal Wars, with a lot more scope for designing your base, the ability to set up trade routes, and also hire commanders with certain skills to help you run your bases.

Both games are free, with the choice of paying for an account upgrade (both offer free trials of upgrades) to give you various benefits such as larger construction queues and an advanced interface. Definately worth a try, click the banner below to play Astro Empires!


Play in the Park

Thankfully, on friday, we actually managed to remember that we had tickets to see a ‘play in the park’ at Williamson’s Park. Earlier in the year we’d managed to forget that we had tickets, only remembering a couple of days later!

We’d been planning on going to a play for a number of years, but this is the first time we’ve actually managed to be ‘cultured’ and go and see one. Unfortunately we didn’t fancy the Duke’s one this year, so we decided to watch a traditional Shakespeare one, a Midsummer Nights Dream by the Chapterhouse Theatre Company.

We wandered up to the park about half an hour before it started to pick up our tickets and get some good seats. I’m glad we did seeing as it got rather busy, infact I think the dell (main ampitheatre in the park) was packed by the time the show started. One of the theatre company came out and introduced the show, also telling us that in the event of rain, we’d get wet, which was nice of him! The whole play was performed by the same eight actors, who definately got a lot of practice at quick changes. It was all rather well done and you soon learnt to associate with the costumes rather than the faces of the actors.

It did attempt to rain on a couple of occasions, which was met by a lot of rustling of coats, macs and umbrellas. In fact, there were some pretty thoughtless people in the middle of the audience who seemed to think that people could see through their ‘brollies! The rain didn’t amount to much and we only got a little damp, but noone seemed to care.

All in all, it was a play not to be missed and we’ll definately be going back to watch some more when they start again next year. If you get a chance to go to one, you’d be a fool to miss it! Hopefully the Duke’s will put on a play that we both want to see as theirs are set in various locations around the park which should make it even more interesting!

Caller ID from Asterisk to all phones, MythTV’s and SqueezeBoxes

Well, I had some spare time and finally got round to getting CallerID sorted on my phones. I’ve had it enabled on the line for a while now, and even had it doing database lookups to display a name on the phone handsets as well as the number, tho’ that broke when I upgraded Asterisk. I have, however, sorted out that problem and expanded everything a little.

Now, when the phone rings, the number is looked up in a database of known numbers, then sent out to all the phone handsets as well as any active MythTV frontend or Squeezebox on the network! If we are watching the TV a box pops up with the time, date, number, and if found, name of the incoming call. Likewise if we are in the library where we can’t actually hear the phone, then the Squeezebox display will change to the name and number and we can decide wether to answer it or not!

All this is done using a feature in Asterisk call AGI, or Asterisk Gateway Interface. This is very similar to CGI scripts found on web pages. AGI scripts are run from the Asterisk dialplan to do various things. In this case the AGI perl script is run and the incoming call number is passed to it. This number is looked up in a database to see if its a known number. Wether it is known or not, the script sets the full CID info in Asterisk.

It then procedes to use a utility call cidbcast that is in the contrib directory of MythTV. This cidbcast sends out a UDP broadcast over the network to any listening machine, in this case the MythTV backend server which has the mythudprelay program running, another one from the MythTV contrib directory. This picks up the broadcast and sends the message to all MythTV frontends using mythtvosd.

Lastly the AGI script connects to the SlimServer which controls all the Squeezeboxes. Talking over the CLI port (9090) on the server it gets a list of all current players and proceeds to send a simple two line display message consisting of the number and name. The majority of this part of the script is a simple cut and paste of the relevant parts of the Squeezebox plugin written by Max Spicer.

All in all this is a fairly simple thing to implement, but is very useful for those as lazy as me!

Script

#!/usr/bin/perl

use DBI;
use IO::Socket;

# MySQL settings for asterisk
my $dbhost = 'localhost';
my $dbuser = 'asterisk';
my $dbpass = 'asterisk';
my $dbname = 'asterisk';

# Slimserver Settings
my $serverAddress = 'mythbe-1';
my $serverPort = 9090;
my $maxVolume = 75;
my $displayTime = 30;
my $debug = 0;

# Mythtv Setting
my $mythxmlfile = '/usr/lib/asterisk/cidbcast.xml';



################
# Get name from mysql for the incoming number
#
$|=1;

#Get the initial data
     my %input;
     while() {
         chomp;
         last unless length($_);
         if (/^agi_(\w+)\:\s+(.*)$/) {
         $input{$1} = $2;
     }
}

my $dbh = DBI->connect ("dbi:mysql:host=$dbhost:database=$dbname","$dbuser","$dbpass") or die "Can't connect to database: $DBI::errstr\n";
my $sth = $dbh->prepare( "SELECT cid FROM known_numbers WHERE source='$input{callerid}'" );
$sth->execute();
@row = $sth->fetchrow_array();
$cidname = @row[0];
print "SET CALLERID \"@row\"<$input{callerid}>";

###############
# Broadcast info to MythTV
my $command;
$command = "cidbcast --once --file=$mythxmlfile 6947 $input{callerid} \"$cidname\" line";
system("$command &> /dev/null");

################
# Send out to squeezeboxes
# Code ripped from Squeezebox CID plugin by Max Spicer
# http://www.thespicers.net/cid.html
#

my $socket = IO::Socket::INET->new (PeerAddr => $serverAddress,
                                    PeerPort => $serverPort,
                                    Proto    => 'tcp',
                                    Type     => SOCK_STREAM)
or die 'Couldn\'t connect to server';

# Get the number of players
my $playerCount = sendAndReceive('player count ?');
$debug && print "$playerCount players found\n";

# Display message on each player and adjust volume if necessary
for (my $i = 0; $i < $playerCount; $i++) { my $playerId = sendAndReceive("player id $i ?"); # Put the players display at max brightness if it's currently 0 my $powerState = sendAndReceive("$playerId power ?"); my $brightnessPref = $powerState ? 'powerOnBrightness' : 'powerOffBrightness'; my $brightness = sendAndReceive("$playerId playerpref $brightnessPref ?"); $debug && print "brightness: $brightness\n"; if ($brightness == 0) { sendAndReceive("$playerId playerpref $brightnessPref 4"); } $cidname =~ s/\s/%20/g; $debug && print("Sending: $playerId display Incoming%20call:%20$input{callerid} $cidname $displayTime\n"); sendAndReceive("$playerId display Incoming%20call:%20$input{callerid} $cidname $displayTime"); # Drop the volume if necessary my $playerMode = sendAndReceive("$playerId mode ?"); $debug && print "playerMode: $playerMode\n"; if ($playerMode eq "play" && sendAndReceive("$playerId mixer volume ?") > $maxVolume) {
    $debug && print "Decreasing volume\n";
    sendAndReceive("$playerId mixer volume $maxVolume");
  }
}
$debug && print "\n";
exit 1;

# Send given cmd to $socket and return answer with original command removed from
# front if present.  Routine nicked from code by Felix Mueller. :-)
sub sendAndReceive {
  my $cmd = shift;
  return if( $cmd eq "");

  print $socket "$cmd\n";
  $debug > 1 && print "Sent $cmd to server\n";
  my $answer = <$socket>;
  $debug > 1 && print "Server replied: $answer\n";
  $answer =~ s/$cmd //i;
  $answer =~ s/\n//;

  return $answer;
}

Database table structure

mysql> describe known_numbers;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| source | varchar(13) |      | PRI |         |       |
| cid    | varchar(26) |      |     |         |       |
+--------+-------------+------+-----+---------+-------+