Archive for the ‘n70’ Category

Programming PyS60 in Linux

May 17, 2010

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!
      Putools connected

      PUTools working console

  • 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.

Happy coding!

Howto: Using your mobile phone as a bluetooth modem

October 4, 2009

Hello everybody!

It’s been a long time since I don’t write about any computer stuff so here I’m back again showing you how to use your mobile phone as a bluetooth modem under Linux. I needed it a couple of weeks back when I was travelling and wanted to be able to check my e-mail anywhere so I hope it seems usefull for you tu.

First of all a few important facts:

  • I’m using a Nokia N70 but it should work with almost any device
  • I’m using a Spanish SIMYO card
  • I’m running a Debian GNU/Linux SO with some required packages (bluez, bluez-utils, wvdial)

Altough the process should be quite simple (pair your computer with your phone and then use it) I found lot of troubles while pairing that I’ll show how to solve.

First of all you should check if your mobile phone supports acting like a bluetooth modem so do ‘sdptool browse’ and look for something like “Dial-up Networking” (obviously have your bluetooth enabled in both PC and phone).


$> sdptool browse
Inquiring ...
Browsing 00:1C:9A:40:CB:BB ...

[…]

Service Name: Dial-Up Networking
Service RecHandle: 0x10017
Service Class ID List:
“Dialup Networking” (0x1103)
Protocol Descriptor List:
“L2CAP” (0x0100)
“RFCOMM” (0x0003)
Channel: 3
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
“Dialup Networking” (0x1103)
Version: 0x0100
[…]

Okey, now lets pair both devices (here is where I found most of my problems) as none of the pages I found showed how to do it. Pairing means allowing a connection from PC to mobile phone or vicebersa.

Edit your ‘/etc/bluetooth/rfcomm.conf’ to assign a device (MAC) and channel, use which you get in the previous step.


Mirage:/home/kets# cat /etc/bluetooth/rfcomm.conf
#
# RFCOMM configuration file.
#

rfcomm0 {
# Automatically bind the device at startup
bind no;

# Bluetooth address of the device
device 00:1C:9A:40:CB:BB;

# RFCOMM channel for the connection
channel 3;

# Description of the connection
comment “DUN to use N70 as modem”;
}

Now let’s try to connect using ‘rfcomm connect rfcomm0’ which will prompt a message in your mobile phone to allow or deny the incoming connection and probably a PIN number.


Mirage:/var/lib/bluetooth/00:1F:3A:DB:1E:29# rfcomm connect rfcomm0
Can't connect RFCOMM socket: Connection refused

If you get this ‘Connection refused‘ even if you are allowing it and inserting correctly your PIN (the one specified in /etc/bluetooth/hcid.conf’), it means that you need a key agent. Anyway check your syslog to see if this is what it’s going wrong:


tail -f /var/log/syslog

Sep 20 16:45:58 Mirage bluetoothd[2993]: pin_code_request (sba=00:1F:3A:DB:1E:29, dba=00:1C:9A:40:CB:BB)
Sep 20 16:45:58 Mirage bluetoothd[2993]: No agent available for 0 request

So, this mean that what’s going wrong is that you insert any PIN in you phone and the computer doesn’t recognize it so it denies the connection request. If you have the ‘gnome-bluetooth’ package installed it is said that it should prompt a PIN code to insert the same PIN that you inserted in your phone but, at least for me, it’s not working. The solution? Use bluetooth-agent which sadly doesn’t have any man page so I had to do several tests in order to make it work.

What you have to do before trying to connect using ‘rfcomm’ is telling the bluetooh agent which PIN are you going to use, so run:


Mirage:/# bluetooth-agent 1234

And after that try to connect:


rfcomm connect rfcomm0

(write 1234 in your phone and … :))

Connected /dev/rfcomm0 to 00:1C:9A:40:CB:BB on channel 3
Press CTRL-C for hangup

There you are!, you’ve finally paired your devices!. Now, the rest of the process is quite easy. Edit ‘/etc/wvdial.conf’ as following:


[Dialer SIMYO]
Modem = /dev/rfcomm0
Baud = 460800
Phone = *99***1#
Username =.
Password =.
Stupid Mode = on
Dial Command = ATDT
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init3 = AT+CGDCONT=1,"IP","gprs-service.com"
Modem Type = Analog Modem
New PPPD = yes
ISDN = 0
Ask Password = 0
Compuserve = 0
Force Address =
Idle Seconds = 3000
DialMessage1 =
DialMessage2 =
Auto DNS = 1

You might have to make some changes if you’re using a different network operator like phone number, username, password and the Init3 part where here it says “grps-service.com”. For the first one contact your operator, and for the following check in your mobile phone: tools -> settings -> connection -> access points, and choose the one you’re using to see the correct values.

Now we’re done, just run ‘wvdial SIMYO’, wait until the negotiation finishes and enjoy checking your e-mail or surfing the web:


Mirage:/home/kets# wvdial SIMYO
--> WvDial: Internet dialer version 1.60
--> Cannot get information for serial port.
--> Initializing modem.
--> Sending: ATZ
ATZ
OK
--> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
OK
--> Sending: AT+CGDCONT=1,"IP","gprs-service.com"
AT+CGDCONT=1,"IP","gprs-service.com"
OK
--> Modem initialized.
--> Idle Seconds = 3000, disabling automatic reconnect.
--> Sending: ATDT*99***1#
--> Waiting for carrier.
ATDT*99***1#
CONNECT
~[7f]}#@!}!} } }2}#}$@#}!}$}%\}"}&} }*} } g}%~
--> Carrier detected. Starting PPP immediately.
--> Starting pppd at Fri Sep 25 00:12:36 2009
--> Pid of pppd: 9543
--> Using interface ppp0
--> pppd: ��[0c]
--> pppd: ��[0c]
--> pppd: ��[0c]
--> pppd: ��[0c]
--> local IP address 95.214.14.79
--> pppd: ��[0c]
--> remote IP address 10.6.6.6
--> pppd: ��[0c]
--> primary DNS address 195.230.105.134
--> pppd: ��[0c]
--> secondary DNS address 195.230.105.135
--> pppd: ��[0c]

That was all. Hope it helps 🙂

Control remoto con Nokia N70

January 5, 2008

Este blog no prometía nada de informática y Linux pero como se supone que tiene que reflejar mis actividades voy a comentar una que llevaba bastante tiempo rondándome por la cabeza y así sirve para que a otros no les pase lo mismo.

Hace tiempo que trasteo con los móviles, el bluetooth y el ansia de poder controlar mi ordenador mientras estoy tirado en la cama. Conseguí hacerlo con mi anterior móvil, un SonyEricsson T610 y ahora que tengo un Nokia N70, se suponía que todo iba a ser mucho más fácil pero no lo ha sido, así que voy a explicar más o menos como he conseguido hacerlo.

Para empezar diré que hay muchas maneras y programas para hacerlo pero tras mucho buscar y probar, el único que me daba resultados medio decentes era el PyS60RemoteControl que sirve para cualquier móvil capaz de interpretar Python. No entraré en detalles de como instalarlo, ya que se puede encontrar en la página del programa y en los readmes que lo acompañan. Sin embargo a la hora de la configuración ha sido bastante complicado, así que aquí expongo como hacerlo funcionar ya que en la web del programa no hay casi ninguna explicación.

Una vez bajado lo primero que hay que hacer es configurar el programa, para ello se utiliza el archivo PyS60RemoteControl.conf, simplemente hay que tocar el primer bloque de código, donde dice ‘connections’:

{ 'connections': { 'bluetooth': { 'classname': 'Bluetooth',
'host': '00:80:5A:20:4E:F7',
'port': 0},
'emulator': { 'classname': 'Socket',
'host': '127.0.0.1',
'port': 33000},
'serial': {'classname': 'Serial', 'port': 12},
'socket': { 'classname':'Socket',
'host': '0.0.0.0',
'port': 33000}},

Lo único que hay que especificar es, donde dice host, poner nuestra dirección MAC del dispositivo bluetooth del ordenador, se puede sacar haciendo un ‘hcitool dev’

Después de hacer esto ya se puede conseguir la conectividad entre el ordenador y el móvil, pero probablemente sólo funcione el plugin del XMMS.

Si queremos poder utilizar el móvil para emular el ratón y el teclado (que se puede hacer pero en ningún sitio viene explicado como y me he tenido que buscar la vida), lo único que hay que hacer es tener soporte en el kernel para ‘user level driver support’ que se encuentra en:


Device Drivers --->
Input device support --->
Miscellaneous devices --->
User level driver support

Da igual ponerlo incrustado en el kernel o como módulo, pero si lo ponéis como módulo, acordaros de cargarlo mediante el comando ‘modprobe uinput’ y agregarlo al /etc/modules (o usar la herramienta modconf que lo agregará directamente al cargarlo la primera vez). Gracias a esto podéis usar el móvil para controlar el ordenador al hacer presentaciones o chorradillas así.

Para poder controlar el VLC no hay que nadar nada extraño excepto a la hora de arrancar el programa para ver los videos, agregar la siguiente opción ‘–extraintf http’ que arrancar el servidor http. A mi por defecto me utilizar el puerto 8080, así que tendréis que cambiar en el archivo de configuración del VLC el puerto, osea que el archivo ‘plugins/VLC.conf’ quedaría así


...
'http_host': 'localhost:8080',
...

Ahora ya podéis ver los videos tirados en la cama y subir y bajar el volumen, cambiar entre fullscreen mode o normal, pausar, avanzar… ¡a disfrutar!

Aun así sigo sin conseguir hacer funcionar:

  • Que se vea la pantalla del ordenador en el móvil (se supone que al utilizar el ratón se tendría que ver).
  • Configurar el plugin del ratón para que responda a mis teclas y no a las que vienen por defecto.

¡Espero que os sirva de ayuda!