Perl powered home automation

September 5th, 2012 robin Posted in Home, Ironman, Perl Comments Off on Perl powered home automation

I recently got my first raspberry pi, and have been hacking… 🙂

If you haven’t heard of “The Pi”, it’s a credit card sized computer with a 700MHz ARM processor, 256MB RAM, USB, HDMI, Network, … and a load of GPIO output pins.  Happily, someone has already written a perl interface to the GPIO pins, and so now for the first time I can quickly and easily do hardware hacking with perl.

There are already a few operating systems ported to the Pi, but the most popular is Raspbian – a Debian variant customised for the Pi.  With a bit of hardware hacking (optocouplers to isolate a 12V circuit from the 3.3V one, and a 3V to 12V voltage converter), I was able to make an interface between the Pi, and a household plug socket remote control (about 9.90EUR at most hardware stores).

Here’s the result:

Perl interface to Google Directions API

February 1st, 2012 robin Posted in google, Ironman, Perl, Travel Comments Off on Perl interface to Google Directions API

Google has a pretty neat service for getting driving/cycling/walking directions between places, and now there’s a perl interface to it: Google::Directions (and on GitHub)

It’s Moosey and it’s juicy… I hope it helps you get from A to B with Perl a bit faster! 🙂

If anybody is top-fit with Moose::Util::TypeConstraints, I have some issues in this module which I don’t understand and would really appreciate some tips with. 🙂

And here’s some sample code:

#!/usr/bin/env perl
use strict;
use warnings;
use Google::Directions::Client;
use Getopt::Long;
my %params;
GetOptions( \%params,
my $goog = Google::Directions::Client->new();
my $response = $goog->directions( %params );
my $first_leg = $response->routes->[0]->legs->[0];
printf( "That journey will take you %0.1f minutes and %0.1fkm\n",
 ( $first_leg->duration / 60 ),
 ( $first_leg->distance / 1000 ),
# $> ./ --origin "Munich, Germany" --destination "Hamburg, Germany"
# That journey will take you 443.8 minutes and 778.5km

Interface to EFA (Elektronische Fahrplan Auskunft)

January 23rd, 2012 robin Posted in Ironman, Perl, Travel Comments Off on Interface to EFA (Elektronische Fahrplan Auskunft)

I’m publishing this module now, even though it’s not complete because I foresee not getting round to developing it much in the near future, and maybe others can benefit from it in its current state, or continue development.

What is EFA?

EFA is a product from Mentz Datenverarbeitung in Munich which is used my many municipal travel providers such as the MVV in Munich to provide travel data for their patrons.

Unfortunately there is no documentation to the interface available, so my implementation is mostly reverse-engineered to their RESTful API.  A lot of ground work which helped me get ahead was done by Andreas and friends in Java with the public-transport-enabler (see AbstractEfaProvider in there for more details) which incidentally is the code behind the hugely popular android App Öffi.

What can I WWW::EFA for?

Querying travel times between locations, and stops within a municipal transport network.

Which municipalities will it work for?

There are loads of transport authorities which use EFA (London, Munich, Basel, San Francisco, …).  I have only tested it with the MVV…

Where are all the unit tests and examples?

Sorry… it’s a work in progress… I’d be really grateful for any contributions you want to make to make it more complete!!

What other similar perl modules are there?

Code example

use WWW::EFA::Provider::MVV;
use WWW::EFA::Coordinates;
use WWW::EFA::Location;
use Class::Date qw/now/;
my %efa_params;
my $efa = WWW::EFA::Provider::MVV->new( %efa_params );
my $search_to_location = WWW::EFA::Location->new(
 coordinates => WWW::EFA::Coordinates->new(  lat => 48.171606, lon => 11.498899 ),
my $search_from_location = WWW::EFA::Location->new(
 coordinates => WWW::EFA::Coordinates->new( lat => 48.140267, lon => 11.557302 ),
my( $from_location ) = $efa->coord_request(
 location => $search_from_location,
 max_results => 5,
 max_distance => 100,
my( $to_location ) = $efa->coord_request(
 location => $search_to_location,
 max_results => 5,
 max_distance => 100,
printf "##### Getting trips between\n%s\n%s\n",
 $from_location->string, $to_location->string;
my $trips = $efa->trips(
 from => $from_location,
 to => $to_location,
 date => now(),
print $trips->string;