From Openmoko

Jump to: navigation, search


An Idiot's introduction to DBus using python on the GTA02

I have recently stared playing with DBus on my GTA02. Allow me to say, that when I say Idiot, I am referring to myself. I am not a software developer, more of a guy who likes playing with software, so I generally need things spelled out for me, or have to poke around for myself. When reading the documents I on dbus, I found myself getting a little confused, so to get things straight in my head, I returned to the old faithful equivalent of a "hello world" program. Let me know if it is of any help.


There is a ton of great background info out there and on this wiki, a good place to start is here [1]


What we are going to do here is make the blue power LED on your free runner turn on and off. Very simple stuff ;)


First thing we have to do, is find the name space to use for our little program. The best way to do this is explore the DBus on your openmoko. Login to your GTA02 and issue the following command:

root@om-gta02:~# mdbus -s

What we get is a dump of the name space. You will then want to start to dig a little deeper looking for the LED. It so happens that the LED interface is located in org.freesmartphone.odeviced . We get the details by using the mdbus tool again.

root@om-gta02:~# mdbus -s org.freesmartphone.odeviced     

Ahha! It so happens that the interface is at: /org/freesmartphone/Device/LED/gta02_power_blue
Next thing we need to know about is the methods that we can us on this interface. For that we scoot over to the FSO website [2] for some docs on our LED [3] . Reading those auto docs, we now know that we want to use the method SetBrightness.

The Program

So lets put this all together and then I will walk through which each one line means:

#!/usr/bin/env python

import dbus
import time

system_bus = dbus.SystemBus()

led_object = system_bus.get_object('org.freesmartphone.odeviced', '/org/freesmartphone/Device/LED/gta02_power_blue')
led_interface = dbus.Interface(led_object, dbus_interface='org.freesmartphone.Device.LED')


- Lines 1-5: we are loading the required libs for our little program. dbus is the python lib for interfacing with the dbus middle-ware.
- Line 6: we create our base dbus object from the SystemBus class. This object will be used to create our particular dbus object.
- Line 8: we create our particular dbus object. This is a representation of the device as represented by the dbus at the name space /org/freesmartphone/Device/LED/gta02_power_blue
- Line 9: we create our interface out of the object created in line 8.
- Line 11: we INTERACT! =) Here we are using the documented method 'SetBrightness' on the interface we created. This method takes a value between 0-100. 0 if off, 100 is brightest.
- Line 12: we let the program sleep (ie wait on its hands) for three seconds.
- Line 13: we turn off the LED by setting its brightness to 0.


If this sort of thing is a help to anyone, let me know and I will start putting up progressively more advanced pages. This is the most bare bones intro into the great dbus framework Mickey Lauer and the folks on the FSO have been working on.
--Sparrow 23:15, 8 March 2009 (UTC)

Personal tools