maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   [ANNOUNCE] mbluetoothd (https://talk.maemo.org/showthread.php?t=26809)

bongo 2009-02-13 01:53

[ANNOUNCE] mbluetoothd
 
1 Attachment(s)
Hi,

as I needed an daemon to launch a mediaplayer when my bt headset connects I started a new project.

mbluetoothd is written in python and is able to execute commands when a bluetooth device connects or disconnects. There's also mbluetoothdsettings which can be used to add and delete commands to your database (which is sqlite3 in this case).

This is just a ALPHA!

Howto:

1. extract the zip archive
2. move mbluetoothd to /home/user/.bluetoothd
3. run 'python mbluetoothd.py &'
4. run 'python mbluetoothdsettings.py' to add/delete commands
5. Enjoy
6. Post your feedback

bongo 2009-02-13 01:57

Re: [ANNOUNCE] mbluetoothd
 
2 Attachment(s)
This is what mbluetoothdsettings looks like.

Matan 2009-02-13 09:41

Re: [ANNOUNCE] mbluetoothd
 
The functionality of mbluetoothd is already available in dbus-scripts, since bluetooth connect/disconnect events are reported on dbus. You could implement the GUI part to work with dbus-scripts rather than mbluetoothd, which would give it a better potential, since it could then be easily extended to other events (wifi connects, offline mode, etc.)

bongo 2009-02-13 11:43

Re: [ANNOUNCE] mbluetoothd
 
Yeah, I'm sure there are better ways to do this but in this case the plan was to develop something simple for my two or three bt devices. There's conler for wifi .....
And mbluetoothd uses dbus. The daemon is a very simple peace of code.

Matan 2009-02-15 20:51

Re: [ANNOUNCE] mbluetoothd
 
The python program at

http://my.arava.co.il/~matan/770/dbu...ts-settings.py

Is based on mbluetoothdsettings, implementing the functionality using dbus-scripts mbluetoothd.

On improvement, in the ADD dialog, the bt addresses of paired device are available for selection, instead of needing to write them.

There are still issues with permissions:
* The configuration directory is not writeable by user - this needs to be corrected in the dbus-scripts package.
* The dbus-scripts daemon needs to be restarted when the configuration file is written, which again requires root permissions. This may be fixed in a few ways.

After I solve those problems, I will start to add other event types:
* network connect/disconnect (either specific network or any).
* lock/unlock keys.
* slide keyboard open/close.
* entering/leaving offline mode.
* screen dimmed/blanked.
* charger connected/disconnected.
* etc.

(all those events are supported by dbus-scripts, only GUI is needed).



P.S. this is the first time I edit a python program, so there might be better ways to do much of what I do.

bongo 2009-02-15 21:07

Re: [ANNOUNCE] mbluetoothd
 
The mbluetooth gui was just a quick hack. I can provide a much better gui and I suggest we start a new project and work together on it.

Matan 2009-02-18 20:54

Re: [ANNOUNCE] mbluetoothd
 
That's what I intended to suggest with my message.

I worked on the program a bit, and now the two problems are solved (or actually, hacked around). I uploaded a working package called dbus-scripts-settings to extras-devel, which provides full functionality of mbluetoothsettings and also allows network connection/disconnection events.

I will be happy to cooperate with you on this project.

Source package is here:
http://repository.maemo.org/extras-d...ngs_1.0.tar.gz

tso 2009-02-18 21:54

Re: [ANNOUNCE] mbluetoothd
 
hmm, tried it, hit save after setting up a couple of bluetooth entries, and it seems to hang...

Matan 2009-02-18 22:16

Re: [ANNOUNCE] mbluetoothd
 
can you do:
while it hangs, run top and ps auxw, to see if some it is running in some loop or waiting for some external program (any process with PID greater than the one of dbus-scripts-settings is interesting).

Also, can you run it from a terminal (preferable by ssh to the IT) and see if it prints anything when pressing save?

Matan 2009-02-18 22:37

Re: [ANNOUNCE] mbluetoothd
 
OK. I see the problem. You need to run as root after installing the package

update-sudoers

I should test every package on a really really clean device, but it's unreasonable unless I have a device dedicated to testing.

svs57 2009-02-27 08:08

Re: [ANNOUNCE] mbluetoothd
 
I install package dbus-scripts-settings 1.1 and set when my BT headphone connected start /usr/bin/kagu. When I connect headphone kagu doesn't start. How can I debug why?

I know that it is possible to connect headphone using script.
Can anybody show me how.
Sorry for stupid questions.

Matan 2009-02-27 09:37

Re: [ANNOUNCE] mbluetoothd
 
What is the content of /etc/dbus-scripts.d/dbus-scripts-settings ?

The script runs as root, so if kagu needs to run as a user, you need to write some script that will use su or sudo to run kagu.

The way I debug is always use a script, instead of using the program directly, and I include a line such as:

date >> /tmp/my.log

so I can at least tell if the script ran when it was supposed to.

svs57 2009-02-27 13:22

Re: [ANNOUNCE] mbluetoothd
 
I write 2 scrips for start and stop kagu and test it from root.
It works. But when device connected kagu doesn't start.

cat /etc/dbus-scripts.d/dbus-scripts-settings
/usr/local/bin/start-kagu * * org.bluez.Adapter RemoteDeviceConnected 00:0D:3C:A6:CC:13
/usr/local/bin/stop-kagu * * org.bluez.Adapter RemoteDeviceConnected 00:0D:3C:A6:CC:13

dbus-scripts --debug --system
Parsing conf file /etc/dbus-scripts.d/....
Parsing conf file /etc/dbus-scripts.d/.....
Parsing conf file /etc/dbus-scripts.d/dbus-scripts-settings...
Parsing conf file /etc/dbus-scripts.d/dbus-scripts-example...
Script file /usr/local/bin/start-kagu: arg 1 = *, arg 2 = *, arg 3 = org.bluez.Adapter, arg 4 = RemoteDeviceConnected, arg 5 = 00:0D:3C:A6:CC:13,
Script file /usr/local/bin/stop-kagu: arg 1 = *, arg 2 = *, arg 3 = org.bluez.Adapter, arg 4 = RemoteDeviceConnected, arg 5 = 00:0D:3C:A6:CC:13,
=================================
Arg 1: org.freedesktop.DBus
Arg 2: :1.351
Arg 3: org.freedesktop.DBus
Arg 4: NameAcquired
Arg 5: :1.351
=================================
Arg 1: :1.49
Arg 2: null
Arg 3: org.kernel.kevent
Arg 4: add
=================================
Arg 1: :1.32
Arg 2: null
Arg 3: org.bluez.Adapter
Arg 4: RemoteDeviceConnected
Arg 5: 00:0D:3C:A6:CC:13
Script /usr/local/bin/start-kagu matches
Script /usr/local/bin/stop-kagu matches
=================================
Arg 1: :1.33
Arg 2: null
Arg 3: com.nokia.btcond.signal
Arg 4: connection_status
Arg 5: 00:0D:3C:A6:CC:13
Arg 6: connected
=================================
Arg 1: :1.32
Arg 2: null
Arg 3: org.bluez.Adapter
Arg 4: RemoteNameUpdated
Arg 5: 00:0D:3C:A6:CC:13
Arg 6: Nokia BH-501
=================================
Arg 1: :1.33
Arg 2: null
Arg 3: com.nokia.btcond.signal
Arg 4: link_key_ok
Arg 5: 00:0D:3C:A6:CC:13
=================================
Arg 1: :1.34
Arg 2: null
Arg 3: org.bluez.audio.Headset
Arg 4: Connected
=================================
Arg 1: :1.11
Arg 2: null
Arg 3: org.freedesktop.DBus.Properties
Arg 4: Notify
Arg 5: com.nokia.bluez_headset_proxy
Arg 6: State
Arg 7: Connected
=================================
Arg 1: :1.49
Arg 2: null
Arg 3: org.kernel.kevent
Arg 4: add
=================================
Arg 1: :1.34
Arg 2: null
Arg 3: org.bluez.audio.Headset
Arg 4: Playing
=================================
Arg 1: :1.11
Arg 2: null
Arg 3: org.freedesktop.DBus.Properties
Arg 4: Notify
Arg 5: com.nokia.bluez_headset_proxy
Arg 6: State
Arg 7: Playing
=================================
Arg 1: :1.34
Arg 2: null
Arg 3: org.bluez.audio.Control
Arg 4: Connected
=================================

svs57 2009-02-27 13:41

Re: [ANNOUNCE] mbluetoothd
 
I accidentlly kill dbus daemon. IT rebooted and know everything wokr :)

One more question.
Is it possible to execute script via dbus-script on headphone button press?

Now I use python script to pause kagu when button press.
I have to start it from xterm each time when I start kagu.
Will be nice if need only start BT on IT and nothing more :)

#!/usr/bin/env python2.5

from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)

import dbus
import gobject
import os

dbus_loop = gobject.MainLoop()
bus = dbus.SessionBus()

def on_button_pressed (sender=None):
os.system('echo pause > /home/user/.kagu/fifo')


headset = bus.get_object('com.nokia.osso_hp_ls_controller', '/com/nokia/osso_hp_ls_controller')
headset_iface = dbus.Interface(headset, dbus_interface='com.nokia.osso_hp_ls_controller.he adset')
headset_iface.connect_to_signal('button_pressed', on_button_pressed, sender_keyword='sender')

dbus_loop.run()

svs57 2009-02-27 13:48

Re: [ANNOUNCE] mbluetoothd
 
I mean something like this in /etc/dbus-scripts.d/dbus-scripts-settings
...
/usr/local/bin/pause-kagu * * com.nokia.osso_hp_ls_controller.headset button_pressed 00:0D:3C:A6:CC:13
or
/usr/local/bin/pause-kagu * * org.bluez.audio.Headset AnswerRequested 00:0D:3C:A6:CC:13

bongo 2009-02-27 14:39

Re: [ANNOUNCE] mbluetoothd
 
I tried to find a way to find out if the headphones are connected. The dbus signal is always the same for connect/disconnect :(

Matan 2009-02-27 16:44

Re: [ANNOUNCE] mbluetoothd
 
You seem to have both scripts running on connect. The on_disconnect (kagu_stop) should have RemoteDeviceDisconnect, not RemoteDeviceConnect.

As far as I can tell this is not a dbus-scripts-setting bug. Are you sure you selected disconnect for the second line?

About getting the same dbus signal for connect/disconnect - there are other such events, such as keyboard slide (same signal when openned and closed) USB device connect/disconnect. In such cases you need to have the script running on both events, and the script should use some other method for finding out which event actually happened (and be really careful of race conditions).

bongo 2009-02-27 16:59

Re: [ANNOUNCE] mbluetoothd
 
Quote:

Originally Posted by Matan (Post 267601)

About getting the same dbus signal for connect/disconnect - there are other such events, such as keyboard slide (same signal when openned and closed) USB device connect/disconnect. In such cases you need to have the script running on both events, and the script should use some other method for finding out which event actually happened (and be really careful of race conditions).

I know that, but how can I find out if the headphone is connected?

Matan 2009-02-27 19:41

Re: [ANNOUNCE] mbluetoothd
 
There is a file /sys/devices/platform/retu-headset/hookdet which apprently gives the value of retu adc 5. Values of less than 80 appear to indicate headset connected, while values of more, appear to indicate not connected.

svs57 2009-02-27 20:22

Re: [ANNOUNCE] mbluetoothd
 
It was mistake. I changed second line to disconnect.
I think the should be way to extend the program and add headphone button monitor.
Now I have one script to monitor connect/disconnect BT and one for monitor BT button.

bongo 2009-02-27 21:10

Re: [ANNOUNCE] mbluetoothd
 
Quote:

Originally Posted by Matan (Post 267638)
Values of less than 80 appear to indicate headset connected, while values of more, appear to indicate not connected.

Yeah, welcome to the digital world ... :D


All times are GMT. The time now is 12:34.

vBulletin® Version 3.8.8