Getting started developing for Maemo in Python

After a few months of owning a N900 finally came the itch to write an app for it -- using of course Python! The Maemo documentation is excellent, I'm only putting my notes down here for future reference.

First off, making sure to know which version of Maemo is on the phone: Settings -> About: Maemo 5.

Setting up

The documentation at is truly excellent. Of interest to us to begin with is installing the SDK. The wiki has been kept up to date with tips and links to solutions of potential problems at the stage where you might encounter them, making any issue a non-event.

Note: It turns out that the SDK is optional to develop with Python. If you would prefer not to set this all up, you can simply move your Python files to the phone or write the code there directly. Personally I found having a full SDK on the laptop to be really handy to try things out quickly, and to tweak and understand what the final result will look like.

Getting started, every time

The SDK docs lists the various commands that may work for your distro and system specifics, which is awesome but can be a bit dense to read through and find again later on. Here's what I do on Debian unstable:

Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac &


export DISPLAY=:2 start

Important: Don't forget to run ` stop` at the end, or say, if you messed your Xephyr command and need to restart it -- you will need to stop this script before attempting to start the emulator environment again. Otherwise there will be D-Bus conflicts and things won't work.

Hello, world

After setting up the SDK, the documentation recommends you go learn about packaging next -- I kept that one for later, it's more interesting to build something first!

By following the documentation you can find the Hello world for Python, which does work on the phone with no hassle and without stopping by the SDK: Developer Guide -> Programming Environments -> PyMaemo quick start.

If you'd like to work in scratchbox (quicker turnaround!), you can go back to the Maemo SDK on your machine and follow again the instructions to set up a Python development environment.

Hello world, again

The same Python-related packages need to be installed into the dev environment, within scratchbox.

nano /etc/apt/sources.list
deb fremantle free non-free
apt-get update
apt-get install maemo-python-env (and qemacs :o))

Note that on the phone, you would install maemo-python-device-env (cf. Quick Start Guide), while when working in scratchbox  you should install maemo-python-env instead (cf.  Python support)

qemacs -nw

Make sure you're calling `python2.5` explicitly or the program will fail with "ImportError: No module named gtk". While working with Hildon I use this command instead, which you'll learn when doing the UI Tutorial. python2.5

Because of the various warnings messing up my scratchbox screen, I ended up using emacs from outside of scratchbox. The files you're working with are located at /scratchbox/users/<username>/home/<username>.

Once you can run the Hello world program, the next step is to go through the handy UI tutorial, which teaches a lot about Hildon and GTK.

I would also recommend installing the devhelp packages for:

  • PyGTK (python-gtk2-doc),
  • the PyGTK tutorial (python-gtk2-tutorial), and
  • the hildon API (libhildon-1-doc) (also available online). The API reference is in C but after doing the tutorial it's easy enough to guess the Python names. Note that although it's still handy, the Debian package does not appear to be the very latest version, e.g. HildonSizeType isn't documented.

I'm really happy with that setup, and it's lovely to get a nice looking UI working so quickly and easily. This is reconciling me with GUI programming -- it looks nice and because of the small screen, there isn't a ton of repetitive boilerplate to write. I can't wait to be far along enough in that project, that I have an excuse to learn again about Debian packaging! :-)

Screenshot of development environment

Leave a comment

Tethering on the N900

As FOSDEM (woohoo \o/) draws closer and the likelihood of spending a lot of time in the airport doesn't change, I thought it was time to find out how to use my N900 as a modem or for "tethering" as I'm told the proper word is.

Some background:

  • my laptop runs Debian Squeeze (unstable) -- the stable release is coming out this week-end by the way!
  • my phone carrier is Meteor (Ireland) and I use their 3G/GPRS connection for data.

Tethering via the USB cable

The official Maemo webpage makes it all sound real simple but it didn't quite work this way for me. The wizard did not appear either on Debian or when I tried on Ubuntu 10.10. Although the phone did show up in Network Manager -> Wired networks, it only displayed as Disconnected and I couldn't find any option to set up a new 3G network.

After many failed attempts, this is the approach that worked for me. It requires wvdial. One annoyance: it works once, then I need to unplug and re-plug the phone.

Here's the wvdial information for Meteor Ireland:

Username: my
Password: meteor

Tethering via Bluetooth

Emboldened by my success I decided to follow the link to the Debian wiki on how to set up the same using Bluetooth. I was very disappointed to see they recommend using a KDE app even under Gnome, and when I looked at the number of dependencies it would bring I thought I'd take my chance the Gnome way.

...I'll skip on the embarrassing moments where I was thinking Gnome 3 wasn't set up yet to handle Bluetooth then found out the Bluetooth service was actually turned off... *cough* I used the Bluetooth applet to pair with the phone and followed the rest of the instructions on the wiki page, until the rfcomm command brought up the following error.

Can't connect RFCOMM socket: Connection refused

Using "sdptool browse <N900_MAC_ADDRESS>" revealed that I did not have the "Dial up networking service" running on the phone. You actually need to install an extra app, available in the repos first (application name is: Bluetooth Dial-Up Networking). I then followed these instructions on the Maemo wiki to set up rfcomm.conf, until "Restart the bluetooth stack" in the first section, and ta-dah! With "wvdial bluetooth" I can now start the connection via Bluetooth.

To be honest I'm sure this is a battery drain nightmare and I can't imagine tethering without the cable but heh! I learnt about several new tools and if I ever need it, it's there :-)

Final wvdial.conf, in all its mighty glory

[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Baud = 460800
New PPPD = yes
ISDN = 0
New PPPD = yes
Phone = *99***1#
Username = "my"
Password = "meteor"
Init6= AT+CGDCONT=1,"IP",""

[Dialer usb]
Modem Type = USB Modem
Modem = /dev/ttyACM0

[Dialer bluetooth]
Modem = /dev/rfcomm0
Leave a comment | 5 so far

Spring cleaning

I'm after "spring" cleaning a little the website. A bit of CSS here, updating some Django code there, adding a couple of icons and creating new pages. It's a bit sad how short the "Speaking & Writing" page ended up being! A clear path for improvement in 2011.

In other news I got myself a N900 \o/ I can now handle email while stuck on the bus, yay. I would have posted a picture, but I applied the protector film so poorly that I can't take a picture without weird reflections. Ah well. Here's a picture from Nokia themselves, who are much better photographers than I am :-)

Hot linking a picture of the N900

Leave a comment | 2 so far