Some time ago I wrote about how to control your PC using your Nokia S60 mobile phone (see it here). It consisted in an application written in Python which stablished a connection between the phone an the computer and according to user inputs in the phone it performed one or another action in the computer.
I was really interested in programming my mobile phone to develop some applications I have in mind and as I also wanted to learn some Python this past weeks I’ve spent some spare time doing my first applications. I’m going to explain how can you program your S60 phone with Python under Linux and in following posts I’ll try to write some tutorials about how to develop some applications.
In order to program your S60 phone with Python, first of all you should get the interpreter and install it into your phone. You can find it in sourceforge (current version is 1.4.5) and where you should download the one according to your phone. As mine is a Nokia N70 I’m using PythonForS60_1_4_5_SDK_2ndEdFP3. Download both the interpreter and the script shell and install them into your phone. I also recommend to download the latest API documentation.
At this point you should be able to execute Python scripts in your phone, by the way, some examples are provided with the interpreter try to run them in order to check that the installation was succesfully done.
Lets go now with the funny part, programming our own applications under Linux. The following options are available:
Programming the application directly on the phone (which I consider very cumbersome so lets discard it).
Programming the application on your computer and transfering and running it in the phone (which is not a bad option but, in my opinion, it is not really the best option).
In order to do this in a more easy way you could use the PUTools utility which will help you transferring the files, interacting with the phone, taking snapshots… in an easier way through a terminal running in your computer.
In the PUTools page, the instructions are writter for Windows users, but it’s not hard to adapt them for Linux users, basically what you have to do is:
- Edit the pcfiles/sync.config to specify the connction port (I’ll use rfcomm0)
#COM_PORT = 11 COM_PORT = ‘/dev/rfcomm0’ `
* Adding a Serial Port service for the bluetooth:
sdptool add service=SP –channel=3 `
* Getting ready for incomming connections on rfcomm0:
$> rfcomm listen /dev/rfcomm0 Waiting for connection on channel 1 `
* Considering that you have previously installed the push.py script in your phone, run it and choose your computer in the connect dialog. If everything was done correctly you should see a message on your computer like the following:
$> rfcomm listen /dev/rfcomm0 Waiting for connection on channel 1 Connection from 00:1C:9A:40:CB:BB to /dev/rfcomm0 Press CTRL-C for hangup
* And now, just run pcfiles/push script to get the terminal which will let you directly interact with the phone! [caption id="attachment_585" align="alignnone" width="150" caption="PUTools working console"][![Putools connected](http://hoyhabloyo.files.wordpress.com/2010/05/putools.png?w=150)](http://hoyhabloyo.files.wordpress.com/2010/05/putools.png)[/caption]
- Programming in your computer, testing your applications on it using an emulator, and once the applications are working correctly transferring them to the phone (which for me is the best option).
In order to do this, you’ll have to download the PyS60 emulation library (S60-compact) available in sourceforge and which will let you test a lot of your applications directly in your computer without needing to transfer them to your phone. (Notice that modules like camera or some fonts are not available but will be more than enough for letting us introduce in the world of PyS60 programming!).
What I usually do is programming the application on my phone, test that it works correctly and later on transferring to my phone with the single following command, and later on run the interpreter in the phone and selecting the transferred script.
$> obexftp -b 00:1C:9A:40:CB:BB -c C:\System\Apps\Python -p script.py `
Now it’s time to start coding our first applications in Python. I recommend reading the API and the following tutorial which is one of the best I could find:
In following posts I’ll show you how to code step by step a very simple eyecandy-but-useless application covering several aspects of the PyS60 API.