Two small fixes for the Nokia N900

· n900, maemo, qt, python, pyside

The Nokia N900 is a proper little Linux computer that happens to make phone calls. It has a root shell, apt-get, and Qt, so when it annoys me I can usually do something about it. Here are two things I did something about, which I’ve finally put on GitHub.

Autoconnect: Wi-Fi that remembers

The N900 happily remembers WPA Enterprise networks, the kind with a username and password rather than one shared key, as used at universities and offices. What it won’t do is connect to them automatically. Every time, you have to open the menu and pick the network by hand. It’s a known problem, Maemo bug 3399, and a daily irritation when you spend your days on Imperial’s Wi-Fi.

autoconnect is my workaround, written back in June 2010. It’s a small command-line Qt program that you start with the name of a saved network and a scan interval (five minutes by default). Whenever the phone is offline, it scans for networks every so often. If the one you asked for turns up, it opens a connection to it using Qt Mobility’s bearer API, and then it stops scanning until you drop off again.

Most of the code is about coping with the bearer API’s moods, and the comments are fairly candid:

  • isOnline() always says “no” at start-up, so the program just assumes it’s offline and scans anyway.
  • The “you’re online now” signal fires when you connect through the normal Maemo menu, but not when my program opens the connection. So it listens for its own session opening as well.
  • A failed connection sometimes arrives without the matching “gone offline” signal, which left the scan timer stopped. Now it restarts the timer if it finds it isn’t running.
  • Ideally it would just notice networks turning up when other apps scan. Sadly, that signal only fires for scans the program asked for itself, and the passive-scan request that might have fixed it isn’t implemented underneath.

It isn’t elegant, but it works: the phone joins the network on its own, which is all I wanted. And scanning every five minutes hasn’t made any difference to the battery life that I’ve noticed.

MySqueezebox: Napster in my pocket

My other itch was music. mysqueezebox.com is Logitech’s online service behind their Squeezebox players. Log in and it gives your player a set of “apps”, such as Napster, Last.fm, Deezer and internet radio. I’ve got a Squeezebox Classic at home, and I wanted the same thing on the phone.

mysqueezebox is a PySide (Qt for Python) app that talks to the same web API the players use. On first run it asks for your username and password, then asks you to choose which of your players it should pretend to be. After that it:

  1. logs in and fetches the list of apps registered to that player, then shows them as a grid of icons;
  2. lets you browse each app’s menus, which arrive as JSON, and search where the app allows it;
  3. works out the real stream URL for each track or radio station, and plays it through Phonon, Qt’s media framework.

The login is the neatest part. The app never stores or sends your actual password. It keeps a SHA-1 hash of it, and when it logs in it sends a hash of that plus the current time. So even the login URL is different every time.

Each service needs its own glue, because each hides its stream URLs in a slightly different way. Napster and Deezer tracks and radio stations, Last.fm stations, and plain .pls and .asx radio playlists all get their own handling. I also added a hand-written list of BBC radio stations. Last.fm is the one that got away: the app finds the stream, but Phonon refuses to play it, and I never found out why.

It runs on a desktop too, where the N900’s stacked windows become a toolbar of breadcrumbs, which is handy for testing.

Where they stand

autoconnect is there for anyone else stuck with bug 3399. mysqueezebox, sadly, no longer works: Napster has been taken over by Rhapsody, and its streams are no longer accessible, which was most of the point. I’ve put it up anyway, in case anyone wants an example of a PySide app using Phonon on the N900.