SYMBIAN

SYMBIAN

The Symbian platform is an open source operating system for mobile devices. It was created by merging and integrating software assets contributed by Nokia, NTT DoCoMo, and Sony Ericsson, including Symbian OS, the S60, UIQ and MOAP(S) user interfaces.

Python for 60 Installation and Resources

For developing Python for S60 scripts all you need to have is a simple text editor (even notepad works) on your computer and an S60 phone for instant testing without a build or compiling process in between. As an alternative for testing you can use an S60 platform device emulator on your PC, too. In order to test and run a Python script on your S60 phone, you first need to

install the Python for S60 interpreter software to the phone, since it is not preinstalled.

This installation provides the needed Python execution environment

and a range of Standard and proprietary Python library modules. For testing

Python for S60 scripts on your PC via an S60 platform device emulator some

extra software has to be installed to your machine.

Software Installation on the Phone

1. Download the Python for S60 interpreter software to your computer

from the SourceForge’s PyS60 project website: http://sourceforge.

net/projects/pys60. It is available for free as a Symbian install file

(.SIS). Note, you need to choose the correct Python for S60 interpreter

software file based on your phone model (e.g., whether your model is based

on the 2nd or 3rd edition of the S60 developer platform).



2. Install the Python for S60 interpreter software to your phone via Bluetooth,vUSB cable, or Nokia PC Suite. After this, your phone is ready to run Python scripts. The Python icon should be visible on your phone’s desktop or inside one of its subfolders.

To make sure you have the latest installation instructions available, check

from Nokia’s wiki site or relevant PyS60 online tutorials:

http://wiki.opensource.nokia.com/projects/Python for S60

http://www.mobilenin.com/pys60/menu.htm

http://mobiledevices.kom.aau.dk/index.php?id=909

Software Installation on the PC (for S60 Platform Device Emulator Use)

1. Download (free) and install to your PC the S60 Platform SDK for Symbian

OS that includes the device emulator that allows applications to be

run and tested on the PC. It can be found from Forum Nokia’s website:

http://forum.nokia.com. (For details about the installation, read the

releasenote.txt file contained in the .zip file you download).

2. Download (free) and install the Python plug-in for the Symbian SDK.

According to the phone model you want to target with your applications,

you need a different plug-in to install on your PC. It can be found

from the SourceForge’s PyS60 project website http://sourceforge.net/

projects/pys60.

Writing a Python Script

How Python Runs Programs

The Python interpreter reads the program you have written and carries out

the code statements it contains. The simplest form of a Python program is



just a text file containing Python statements which are executed. Such a text

file is in our case the Python script that we are writing.

Three Basic Steps

Let us now look into how to write such a Python for S60 script and how to instantly run it on an S60 mobile phone or an emulator on your PC as an

alternative. There are three basic steps to take:

1. Write a Python script with a text editor on your computer and save it

with the .py file extension.

2. Move your *.py script file from your computer to your phone.

3. Start the Python interpreter application on the phone (or on the emulator)

by clicking on the Python icon on the desktop of your phone (Figure 2.1)

or emulator, then press options key and select Run script from the menu.

From the appearing list choose the name of your script and press ok. Your

script should now start up.

Detailed Explanation of Steps 1 and 2

1. You can use any simple or advanced text editor on Mac or PC or Linux

to write and edit your Python script. Some developers have preferences

regarding which editor to use. Useful editors are, e.g., ConTEXT or Pywin

which are freely downloadable on the Internet, but also Notepad works.

All you need to do is to write the Python code with the text-editor and

save the file with the ending .py. After the code is typed, the file is ready to

be executed on the mobile or an emulator without going through a build

or compiling process. In order to run it, the file needs to be uploaded to

the phone, or copied to a specific folder when using the emulator tool on your computer.

2. There are different possibilities available to move your Python script to

your phone. Depending which phone model you have either of the following

should work: a) using the Nokia PC suite (PC only), or a USB cable or

Bluetooth for connecting the phone as an external hard drive to then

copy paste your scripts from the PC to a folder you need to create on

your phone named Python or b) via Bluetooth sending your *.py file from

the computer (any OS) to your mobile where it will arrive in the message

inbox. Open the received message from the inbox in order to install the



Python script file. When asked to install your file as a script or a library,

choose Python script. When using the emulator, all you need to do is to

copy your script files to a specific folder on your computer.

Sending Data from Phone to Phone via Bluetooth RFCOMM

Bluetooth sockets can be set up for sending and receiving data using the Bluetooth

protocol RFCOMM. This can be done from phone to phone, or phone

to computer, or from phone to microcontroller that has a Bluetooth chip. For

example, the arduino board (http://www.arduino.cc/) is a microcontroller

board with a Bluetooth extension chip. This might be of interest to projects

dealing with social interaction through wearables, physical computing, and

mobile devices. Furthermore the sensor introduced in Chapter 21 is doing the

same.

To establish an RFCOMM connection from phone to phone over Bluetooth

two different scripts are needed. One phone runs the server side script and

the other phone runs the client side script. Since we cannot go into detail due

to lack of space we show here some code example of a simple chat application

(Listing 2.16, 2.17) including comments. Make sure you have Bluetooth

switched on at both phones. All we do is setting up a Bluetooth RFCOMM

connection between two phones and each side sends and receives a string.

With these two scripts a multiuser game can easily be created, too.

Here is the code for Bluetooth chat

import socket, appuifw

def chat_server():

server = socket.socket(socket.AF_BT, socket.SOCK_STREAM)

channel = socket.bt_rfcomm_get_available_server_channel(server)

server.bind((“”, channel))

server.listen(1)

socket.bt_advertise_service(u”btchat”, server, True, socket.RFCOMM)

socket.set_security(server, socket.AUTH | socket.AUTHOR)

print “Waiting for clients…”

conn, client_addr = server.accept()

print “Client connected!”

talk(conn, None)

def chat_client():

conn = socket.socket(socket.AF_BT, socket.SOCK_STREAM)



address, services = socket.bt_discover()

if ‘btchat’ in services:

channel = services[u'btchat']

conn.connect((address, channel))

print “Connected to server!”

talk(None, conn)

else:

appuifw.note(u”Target is not running a btchat server”,

“error”)

def receive_msg(fd):

print “Waiting for message..”

reply = fd.readline()

print “Received: ” + reply

appuifw.note(unicode(reply), “info”)

def send_msg(fd):

msg = appuifw.query(u”Send a message:”, “text”)

print “Sending: ” + msg

print >> fd, msg

def talk(client, server):

try:

if server:

fd = server.makefile(“rw”, 0)

receive_msg(fd)

if client:

fd = client.makefile(“rw”, 0)

while True:

send_msg(fd)

receive_msg(fd)

except:

appuifw.note(u”Connection lost”, “info”)

if client: client.close()

if server: server.close()

print “Bye!”

index = appuifw.popup_menu([u"New server", u"Connect to server"],

u”BTChat mode”)

if index != None:

if index:

chat_client()

else:

chat_server()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.