PyMaemo/Quick start guide

Line 1: Line 1:
= Running Python code on N900 (quick start guide) =
= Running Python code on N900 (quick start guide) =
-
This article will describe the necessary steps to get your Python application running on N900. For the instructions to work, you need to have Internet connectivity on your device (e.g. WLAN or GPRS).
+
This article will describe the necessary steps to get your Python application running on N900.
-
== Installing OpenSSH ==
+
It will cover:
-
OpenSSH is needed to run commands remotely on your N900. This will make testing on the device a lot easier.
+
* Installation of necessary packages and USB connectivity setup
 +
* How to transfer the application files to the N900
 +
* How to run the application
-
If you are able to access the Internet from your N900 (e.g. using WLAN or GPRS) follow these instructions:
+
What will '''not''' be covered:
-
# Enable extras repository. See http://wiki.maemo.org/Extras#Using_Extras for how to do it.
+
* Programming environment setup
-
# Install the package named "OpenSSH Client and Server". The client is also needed so we can enable USB networking in the next session, by ssh'ing to root@localhost. Optionally, you can install the rootsh package to enable local root access. See http://wiki.maemo.org/Root_access for details.
+
* Application packaging and deployment
-
# The installation will ask for a new root password. Choose a good one.
+
-
# Wait for installation to complete.
+
-
== Enabling USB networking ==
+
== Requirements ==
-
USB networking allows fast remote access to the device. To enable it, follow these steps (you need to repeat them every time you reboot the device):
+
Before continuing, make sure you have:
-
# If the USB cable is plugged and in "Mass storage mode", unplug the cable and plug it again, now selecting "PC Suite Mode".
+
Tablet requirements:
-
# On N900, open "X Terminal" and run:
+
-
ssh root@localhost ifup usb0
+
-
This command will ask for SSH fingerprint confirmation (because it is the first connection), and after typing the root password, USB networking will be enabled.
+
* Some kind of connectivity to the tablet (e.g. WLAN or GPRS), so that you can install required packages.
 +
* The N900 USB cable, which will be used to transfer files to the tablet.
-
Now configure the host. This is dependent on which OS (or Linux distro) you use, see http://wiki.maemo.org/USB_networking#Host_USB_Network_Configuration for detailed instructions for various OSes and Linux distros.
+
Host requirements:
-
From now on you can connect to the N900 from your PC by using:
+
* A SSH client. For Linux, OpenSSH (through the "ssh" command) is enough. For Windows, [http://en.sourceforge.jp/projects/ttssh2/releases/ Tera Term] can be used.
 +
* A SCP/SFTP client. For Linux, OpenSSH (through the "scp" command) is enough. The KDE/GNOME environments also have built-in support for these protocols. For Windows, you can try [http://winscp.net/eng/index.php WinSCP] or [http://filezilla-project.org/ FileZilla].
-
ssh root@192.168.2.15
+
For the purposes of this tutorial, you will '''not''' need Scratchbox installed. Scratchbox would only be necessary if you are unable to test your applications on the actual tablet.
-
== Preparing the N900 for Python Development ==
+
== Installing required packages on N900 ==
-
To enable the full power for Python development for Maemo, you must enable the "extras-devel" repository on your device. ''Be advised that this might be a risky operation'' because extras-devel contains many untested and possibly broken packages. But it also contains the latest versions of all available Python bindings for Maemo, which we are interested on.
+
You will need to install two applications on the tablet:
-
To enable extras-devel add a new catalogue to the Application Manager, as instructed in http://wiki.maemo.org/Extras-devel (did you see the big warning on that page?)
+
* OpenSSH Server
 +
* rootsh
-
Next, you need to install the packages you use (or plan to) on your application by running (through SSH):
+
OpenSSH is needed to run commands remotely on your N900. This will make testing on the device a lot easier.
-
apt-get update && apt-get install <packages>
+
rootsh allow to run commands as root on the X Terminal (using "sudo gainroot"). See http://wiki.maemo.org/Root_access for other options to enable root access.
-
Where <packages> are the list of packages you are going to use. For instance, for a general GUI application, you will probably need at least "python-gtk2" and "python-hildon". See http://wiki.maemo.org/PyMaemo/Components for the current list of available packages.
+
To install these applications, follow these steps:
-
== Running the Python application on the device ==
+
# Enable extras repository. See http://wiki.maemo.org/Extras#Using_Extras for how to do it.
 +
# Install the packages listed above.
 +
# The installation will ask for a new root password for SSH access. Choose a good one.
 +
# Wait for installation to complete.
-
Now that you have the N900 properly setup, you just need to copy the Python code to the device and run it.
+
== Enabling USB networking ==
-
=== Single file applications ===
+
USB networking allows to easily and quickly transfer files to the device and connect to it using SSH. To enable it, follow these steps (you need to repeat them every time you reboot the device):
-
If your application consists of a single .py file, you can just copy it to the device using:
+
# If the USB cable is plugged and in "Mass storage mode", unplug the cable and plug it again, now selecting "PC Suite Mode".
 +
# On N900, open "X Terminal" and run:
 +
sudo gainroot
 +
ifup usb0
 +
# Now you need to configure the host. This is dependent on which OS (or Linux distro) you use, see http://wiki.maemo.org/USB_networking#Host_USB_Network_Configuration for detailed instructions for various OSes and Linux distros.
-
  scp my_script.py root@192.168.2.15:/root
+
From now on you can connect to the N900 using any SSH client and the following information:
 +
  Host: 192.168.2.15
 +
Port: 22
 +
User: root
 +
Password: the password setup earlier
-
And to run the application on N900:
+
For instance, from a Linux terminal, you can connect to the tablet using this command:
-
  ssh root@192.168.2.15 run-standalone.sh python2.5 /root/my_script.py
+
  ssh root@192.168.2.15
-
The application should then open on the device's screen, and any errors will be print on the terminal where you run the command below.
+
== Preparing the N900 for Python Development ==
-
Alternatively, you can use this single command to run the code "on the fly" (i.e. without copying anything to the device):
+
To enable the full power for Python development for Maemo, you must enable the "extras-devel" repository on your device. ''Be advised that this might be a risky operation'' because extras-devel contains many untested and possibly broken packages. But it also contains the latest versions of all available Python bindings for Maemo, which we are interested on.
-
cat my_script.py | ssh root@192.168.2.15 run-standalone.sh python2.5
+
Note that the requirement to enable the "extras-devel" repository might be removed later.
-
===Multiple file applications ===
+
To enable extras-devel add a new catalogue to the Application Manager, as instructed in http://wiki.maemo.org/Extras-devel (did you see the big warning on that page?)
-
For applications which contain more than one file (e.g. images, or other Python files), you need to make all the necessary files accessible on the device. The simplest way is to copy all the code to some directory on the device, which you could do by using this single line:
+
Next, you can install the basic Python environment on the tablet by running this command on the SSH terminal:
-
  tar -cf- my_application_dir/ | ssh root@192.168.2.15 tar -C /root -xvf-
+
  apt-get update && apt-get install maemo-python-device-env
-
This command uses a combination of tar and ssh to copy all files under a directory recursively (taking care to keep permissions intact). Then, to run the application, use a command like this:
+
== Running the Python application on the device ==
-
ssh root@192.168.2.15 run-standalone.sh python2.5 /root/my_application_dir/my_script.py
+
Now that you have the N900 properly setup, you just need to copy the Python code to the device and run it.
-
 
+
-
Alternatively, you can install the "sshfs" package on your PC (it is available at least on Debian and Ubuntu systems), and run:
+
-
 
+
-
sshfs root@192.168.2.15:/root some_local_dir
+
-
 
+
-
This will make the N900's /root directory accessible on some_local_dir directory on the PC. You can copy files to some_local_dir and they will be transparently copied to the device. To run the application, use the same command as shown earlier.
+
-
 
+
-
Once you don't need to access the directory anymore, run:
+
-
 
+
-
umount some_local_dir
+
-
sshfs can also be used the other way around: you can access your application's directory directly from the N900 (so no copying is needed at all). For that, install the "sshfs" package on N900 by running:
+
The simplest way to copy files it to use a SFTP or SCP client. There are many free clients available for most OSes (we listed some examples on the "Requirements" section). On the Linux command line, you can use:
-
  apt-get install sshfs
+
  scp -pr my_application/ root@192.168.2.15:/root/my_application/
-
Make sure you have OpenSSH server installed on your PC, and run:
+
Replace "my_application/" with the path to the directory which contains your application files.
-
ssh root@192.168.2.15 # this will log into the N900
+
Finally, to run the application on the tablet, use (from a SSH terminal):
-
mkdir /root/host_fs
+
-
sshfs <USER>@192.168.2.14:/path/to/my_application_dir /root/host_fs
+
-
run-standalone.sh python2.5 /root/host_fs/my_script.py
+
-
Once you don't need to access the directory anymore, run:
+
  cd /root/my_application
-
  ssh root@192.168.2.15 umount /root/host_fs
+
python my_application.py
[[Category:N900]]
[[Category:N900]]
[[Category:Python]]
[[Category:Python]]

Revision as of 15:49, 16 December 2009

Contents

Running Python code on N900 (quick start guide)

This article will describe the necessary steps to get your Python application running on N900.

It will cover:

  • Installation of necessary packages and USB connectivity setup
  • How to transfer the application files to the N900
  • How to run the application

What will not be covered:

  • Programming environment setup
  • Application packaging and deployment

Requirements

Before continuing, make sure you have:

Tablet requirements:

  • Some kind of connectivity to the tablet (e.g. WLAN or GPRS), so that you can install required packages.
  • The N900 USB cable, which will be used to transfer files to the tablet.

Host requirements:

  • A SSH client. For Linux, OpenSSH (through the "ssh" command) is enough. For Windows, Tera Term can be used.
  • A SCP/SFTP client. For Linux, OpenSSH (through the "scp" command) is enough. The KDE/GNOME environments also have built-in support for these protocols. For Windows, you can try WinSCP or FileZilla.

For the purposes of this tutorial, you will not need Scratchbox installed. Scratchbox would only be necessary if you are unable to test your applications on the actual tablet.

Installing required packages on N900

You will need to install two applications on the tablet:

  • OpenSSH Server
  • rootsh

OpenSSH is needed to run commands remotely on your N900. This will make testing on the device a lot easier.

rootsh allow to run commands as root on the X Terminal (using "sudo gainroot"). See http://wiki.maemo.org/Root_access for other options to enable root access.

To install these applications, follow these steps:

  1. Enable extras repository. See http://wiki.maemo.org/Extras#Using_Extras for how to do it.
  2. Install the packages listed above.
  3. The installation will ask for a new root password for SSH access. Choose a good one.
  4. Wait for installation to complete.

Enabling USB networking

USB networking allows to easily and quickly transfer files to the device and connect to it using SSH. To enable it, follow these steps (you need to repeat them every time you reboot the device):

  1. If the USB cable is plugged and in "Mass storage mode", unplug the cable and plug it again, now selecting "PC Suite Mode".
  2. On N900, open "X Terminal" and run:
sudo gainroot
ifup usb0
  1. Now you need to configure the host. This is dependent on which OS (or Linux distro) you use, see http://wiki.maemo.org/USB_networking#Host_USB_Network_Configuration for detailed instructions for various OSes and Linux distros.

From now on you can connect to the N900 using any SSH client and the following information:

Host: 192.168.2.15
Port: 22
User: root
Password: the password setup earlier

For instance, from a Linux terminal, you can connect to the tablet using this command:

ssh root@192.168.2.15

Preparing the N900 for Python Development

To enable the full power for Python development for Maemo, you must enable the "extras-devel" repository on your device. Be advised that this might be a risky operation because extras-devel contains many untested and possibly broken packages. But it also contains the latest versions of all available Python bindings for Maemo, which we are interested on.

Note that the requirement to enable the "extras-devel" repository might be removed later.

To enable extras-devel add a new catalogue to the Application Manager, as instructed in http://wiki.maemo.org/Extras-devel (did you see the big warning on that page?)

Next, you can install the basic Python environment on the tablet by running this command on the SSH terminal:

apt-get update && apt-get install maemo-python-device-env

Running the Python application on the device

Now that you have the N900 properly setup, you just need to copy the Python code to the device and run it.

The simplest way to copy files it to use a SFTP or SCP client. There are many free clients available for most OSes (we listed some examples on the "Requirements" section). On the Linux command line, you can use:

scp -pr my_application/ root@192.168.2.15:/root/my_application/

Replace "my_application/" with the path to the directory which contains your application files.

Finally, to run the application on the tablet, use (from a SSH terminal):

cd /root/my_application
python my_application.py