bluetooth file transfer in python

Paul Boddie paul at boddie.org.uk
Tue Feb 12 19:14:00 EST 2008


On 12 Feb, 10:50, chartsoft <charts... at cwcom.net> wrote:
> I am a teacher and need to set up a computer with a bluetooth dongle
> to poll for mobile phones with bluetooth switched on in the area then
> send them a jpg file.

I guess you'd use OBEX to send the file, specifically using the "push"
mode of OBEX. Various tools such as hcitool and sdptool (found on GNU/
Linux distributions) and their counterparts exposed by Python
libraries such as PyBluez [1] would be appropriate for scanning for
devices.

> I understand that python is capeable of this.
>
> 1.) is it worth learning python to do this or can someone out there do
> it for me for a v small fee?
>
> 2.) If I am going to do it can anyone give me pointers in the best way
> to do it so I do not spend hours wasting time.

I've previously done OBEX-related things, mostly fetching things from
mobile phones, using the obexftp program [2] which is part of the
OpenOBEX project [3]. Naturally, you can call the obexftp program from
Python and interpret the responses and exit codes using functions in
the os, popen2 and subprocess modules. I believe that obexftp also
supports "push" mode, but you could probably find something else
related to OpenOBEX if it does not.

Since Bluetooth communications are supported using sockets in GNU/
Linux distributions and in Python (provided that the Bluetooth support
is detected and configured), you could communicate with phones using
plain network programming, but this would probably require you to
implement the OBEX protocols yourself - not a straightforward task for
a number of reasons, including one I mention below. Thus, it's
probably easier to go with obexftp at least initially.

There are a number of awkward things with obexftp and OpenOBEX,
however. Some phones do not follow the "standards" and the maintainer
of OpenOBEX wouldn't or just didn't include support for various
deviating Sony Ericsson phones, for example, thus requiring me to
patch the library myself. Although there may be a Python wrapper for
OpenOBEX, it's easier to just call obexftp as mentioned above, but
this means that you're limited to what that program can do.

Finally, and most significantly, OBEX isn't a totally free standard:
if you didn't already get the standards documents while they were
freely available, you now have to sign up with the quaintly named
Infrared Data Association [4] - a "pay to play" organisation with
restrictive redistribution terms on their specifications. Although I'd
recommend that anyone doing brand new stuff with mobile devices just
uses real standards instead of OBEX, I doubt that you have the choice.

Anyway, I hope that this helps you understand the subject area a bit
more.

Paul

P.S. It does also occur to me that desktop environments like KDE have
Bluetooth controls which could be automated in some way in order to
send files, but I haven't investigated this at all.

[1] http://org.csail.mit.edu/pybluez/
[2] http://triq.net/obexftp.html
[3] http://dev.zuckschwerdt.org/openobex/
[4] http://www.irda.org/



More information about the Python-list mailing list