Archive for the ‘code’ Category

UK traffic news for Android

Thursday, May 6th, 2010

Update: (April 2011) The app is no longer available


I’ve been travelling a lot for work recently. Most of it has been by car, and on a few occasions, I’ve run into traffic problems that have made me late.

This got me thinking about what I could do to make things easier.

There are websites with traffic info – such as the Highways Agency or motoring organisations like the AA and RAC. They show travel information for a particular region, or the UK as a whole.

But that’s not really enough.

For one thing, I have to remember to check. I’m not a morning person – particularly when I need to get up at 5am so I can drive for hours. Any approach that relies on me remembering to do something isn’t off to a great start.

And it’s too manual. They show me all of the traffic problems, and it’s up to me to manually work out which of them might affect my route. There is too much noise, with too many traffic reports for places that are nowhere near me, or where I want to go. It’s up to me to filter that out.

At any rate, I don’t want to boot up a computer at 5am, so an AJAX-heavy website that doesn’t work on mobiles isn’t an ideal fit anyway.

My ideal approach would be:

mobile
My mobile phone is already my alarm clock. It’s the only screen I look at when I get up in the morning, so this is the ideal place to get traffic info.

automatic
My mobile knows when I’m going to go somewhere, and where I’m planning to go. It shouldn’t need me to manually check every day – it should check for me automatically, and alert me if it finds any problems.

relevant
Showing me every traffic problem is too much. My mobile knows where I am, and where I’m going. I only want to see problems that are on (or perhaps very near) my route. Anything else should be filtered out, leaving me with just the updates relevant to me.

I went looking for a mobile app that does this, but didn’t have any luck. There are a couple of Android apps with UK traffic information (one from the RAC, the other by the brilliant Simon Judge).

They at least get the traffic info into a mobile-friendly format. But they still show you every traffic problem, and only when you remember to check. I couldn’t find anything that meets all three of my needs.

So I’ve written one.

It’s basic looking… and perhaps a little rough around the edges. But it’s a start.

You enter in routes – which is a start and an end location. This can be a town or city name, a full address, or a postcode.

From there, you can either check the traffic now, or schedule the app to check at a later date and time. For regular journeys, you can describe a repeating pattern – so for example, I can tell it to check my route to work every weekday morning at 7am, and my route home every weekday evening at 4.45pm.

The app works out the route, and compares it with known traffic problems.

This can be done in the background, so it doesn’t matter if your phone is switched off when it’s time to check, or if you’re using another app.

If it finds any matches, it puts a warning in the notifications bar. Tapping on this can take you to a list of the problem descriptions, or an interactive map with both the route and the traffic problems marked on it.

It’s pretty neat, even if I say so myself. 🙂

And it’s something that I can see myself using.

So why am I not making it available for others now? I’ll leave that for another post…

Following twitter hashtags on TV

Tuesday, April 6th, 2010

DSC06104As a lot of other people, I’m watching the debate of the Digital Economy Bill on BBC Parliament tonight. I’m also trying to follow along with some of the #debill back-channel on twitter.

With such a heated and interesting commentary on twitter, it reminded me of Roo’s “Second screen” idea of having tweets with a specific hashtag next to the TV during live TV events, when following the twitter backchannel during ‘The Apprentice’.

Unfortunately, I don’t have a spare laptop kicking around to show tweets on. But I do have a hackable TV. 🙂

With that in mind, in just a few minutes I hacked together the following script to flash up tweets with the #debill tag on the TV:

# run me using:
#       python twittertv.py debill 1

import twython
import subprocess
import sys
from time import sleep

twitterKeyword = sys.argv[1]
twitterSearchRateLimitMins = int(sys.argv[2])

twitter = twython.core.setup()

showOnTVCommand = ['svdrpsend', 'mesg', 'messagetodisplay']

lasttweetid = 1

while True:
    search_results = twitter.searchTwitter(twitterKeyword, since_id=lasttweetid, show_user=True)

    numtweets = len(search_results["results"])
    for tweetnum in reversed(range(0, numtweets)):
        lasttweetid = search_results["results"][tweetnum]["id"]

        user = search_results["results"][tweetnum]["from_user"]
        tweet = search_results["results"][tweetnum]["text"]
        showOnTVCommand[2] = user + " : " + tweet

        subprocess.Popen(showOnTVCommand)
        sleep(20)

    sleep(twitterSearchRateLimitMins * 60)

DSC06127

It’s a quick-and-dirty hack, but I wanted to get something that would work before the debate was finished. 🙂

And it seems to do the trick.

Why I haven’t written TwitToday for Android

Thursday, February 25th, 2010

(or “looking at the limitations of the Android home screen widgets framework”)

Twitter client for Windows MobileA couple of years ago, I wrote a Windows Mobile app called TwitToday : a Twitter widget for the “Today screen” (the default screen when the phone is on, with all apps closed or minimised).

The rationale was that it was useful to have a way to post a tweet quickly when you don’t want to have to wait for a full-blown client to start.

Or if you don’t want to incur the battery or memory cost of leaving a client running all the time.


A widget that doesn't work on AndroidAndroid has a “Home screen”, which is similar to the Today screen on Windows Mobile. And it has support for widgets. This led several people to ask me why I never ported TwitToday to Android.

The short answer is that I did try, but the current state of the widgets framework made it impossible.

I tried to write a TwitToday widget back when the Android widgets framework was first introduced in Android 1.5.

It all started quite well:

  1. I wrote the Android Service that would carry out the background task of posting a tweet. No problems there – it worked fine.
  2. I wrote the widget XML to define the GUI. This is what you can see running in the screenshot. And it works… sort of. It has a text box that you can type up to 140 characters into. And if you press the button, it causes a chunk of code to get invoked.

The problem came when I tried to link the two together: to get the Service that posts tweets to obtain the String from the text box in my widget.

This isn’t possible. Android’s widget framework as it currently stands is geared around displaying information to the user, not collecting user input.

(more…)

Using my mobile as a TV remote control for vdr

Monday, February 22nd, 2010

remote controlsI can never find the TV remote.

Whether it’s slipped somewhere in or under the sofa, or been hidden by the kids, I’m often at a loss to find it.

A mobile phone, on the other hand, is rarely too far from my hand 🙂

So I’ve hacked together a quick app to put a TV remote control interface on my phone. It’s definitely a quick-and-dirty chunk of code, but it does now mean that I can work my TV from my mobile if I can’t find the real remote.

On the off-chance that this is useful to other vdr users, I wanted to share how I did it.

(more…)

last.fm for television

Wednesday, January 6th, 2010

One of the social network sites I’ve been using the longest is last.fm.

(If you know what last.fm is, bear with me teaching you to suck eggs for a few paragraphs… it gets more interesting – honest!)

The idea of last.fm is that a background service captures (or “scrobbles“) the music that I listen to on my computer at home, on the mp3 player that I use in the car, and on my laptop in the office.

This means that I now have a large record detailing the music I’ve listened to over the last three years.

I do this for a few reasons, including:

  • The data is made available to me through a rich API, which means I’m free to play with it, as well as take advantage of the creations of others, such as the wonderful visualisations generated by lastgraph
  • I can see what my friends listen to, which is interesting, as well as being a good way to come across new music
  • last.fm use this detailed history of my music-listening tastes to make automated recommendations of other music that I might like

This is all a long-winded way of saying that I like last.fm. I find it useful and interesting, and want the same for all the media that I consume – not just music.

I went looking for an equivalent for the books that I read in August 2008, and started using goodreads.

But what about the television that I watch? Could I create a last.fm-style scrobbler to capture what I watch on television? And then try and come up with a few examples of how I could share and visualise the data?

This question is where I started at Christmas… and after a few evenings of hacking some Python together, I’ve come up with:

last.fm for television

Please go take a look. (needs Flash – sorry)

(more…)

How much did I spend on electricity to do that?

Friday, November 27th, 2009

Selecting a chunk of a graphTime for number 73 in my never-ending list of ever-so-slightly-different things to try with a graph of home energy usage data

🙂

This time… working out the electricity used (and the cost) of doing… well, something in particular.

We already have live graphs (Switch something on and watch the graph shoot up. Switch it off and watch the line drop.)

And we’ve already got graphs with hourly, daily, or monthly totals.

But if I boil a kettle, how do I know how much that cost?

The live graph shows you the shape of the usage curve for a particular appliance.

What I wanted was to be able to start the live graph running, switch something on, then after it’s finished, go back to the live graph, see the bump in the graph for when I did that, and measure the area under it – giving me my total energy usage for that time.

A quick bit of Python-tinkering later, and here we go

Click-and-drag to highlight a span of the graph, and the Python script calculates the area (more-or-less) under that part of the curve, using this to calculate how much energy I used during this time.

(more…)

Augmented reality for Hursley

Friday, November 6th, 2009

screenshot : click for better resolution imageOne of the themes at openMIC this week was augmented reality, and a topic that came up a couple of times was Layar.

Layar is a mobile app for Android and iPhone that lets you display location-based information overlaid on a real-time camera view.

For example, the screen normally shows a viewfinder-like view from your mobile’s camera.

Search for “coffee” and a bunch of markers appear on the view, showing you where the nearest coffee shops are.

As you move the phone around, the markers follow the approximate location of the places they are showing you.

That’s assuming you want to search ‘Google Local’, but that’s not the only option. Location data is provided through “layars”, and there are layars available for location-tagged Wikipedia articles, Flickr photos, brightkite users, and more.

The interesting thing talked about at openMIC was the Layar API which lets anyone create a new Layar with their own information.

So I decided to spend a quiet Friday afternoon in the office creating a Layar for around Hursley. 🙂

This means a phone with the Layar browser installed can browse and search for points of interest around the site.

It was really very easy, so I’ll quickly outline the steps involved.

(more…)

Tracking my location on TV

Wednesday, October 21st, 2009

Location tracking on TV

This is what you see if you press the “Find Dale” button on my TV remote control.

(Well, actually the “Teletext” button… cos I wasn’t using it, and there isn’t another button that makes any more sense!)

The on-screen-display adds a message at the bottom of the screen for a few seconds, saying my last recorded location and when I was there.

People following me on twitter may have noticed me talking about setting up a new home media server: a small Linux server that has become our Freeview box, PVR, home photo album, and music server.

And now it’s set up, it is surprisingly easy to do amazingly useful, and not-at-all annoying things like this! 😉

In my defence, I stopped just short of making the script poll for my location and display an on-screen message whenever my location changes. Which would’ve been very cool, but probably drive my family nuts. So I compromised with a script that runs when you press a button on the remote.

(more…)