ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Debian, Red Hat/Fedora, Solaris, DD-WRT, NetBSD, Mac OS8/9, Mac OSX, UMP/OS, ESX
Posts: 42
Rep:
Python Bluetooth file exchange
Hello,
I've run into a little problem, for which I seem to be unable to find an answer. The concept is the following: one machine runs a python script which advertises itself as 'OBEX File Transfer' and receives incoming data, using the Lightblue python module. The script itself is slightly different, but here's an example which effectively works in the same way:
Code:
import lightblue
# bind the socket, and advertise an OBEX service
sock = lightblue.socket()
try:
sock.bind(("", 0)) # bind to 0 to bind to a dynamically assigned channel
lightblue.advertise("OBEX File Transfer", sock, lightblue.OBEX)
# Receive a file and save it as MyFile.txt.
# This will wait and block until a file is received.
print "Waiting to receive file on channel %d..." % sock.getsockname()[1]
lightblue.obex.recvfile(sock, "MyFile.txt")
finally:
sock.close()
print "Saved received file to MyFile.txt!"
This works fine, though I would like to retain the original filename that is being sent to the machine, instead of overwriting a fixed file. Generating a new name wouldn't be such a problem, if I could get the MIME type or filename which is (presumably) being sent in the header of the request. Does anyone know of a way in python to receive incoming files and retain their filenames via Bluetooth?
Distribution: Debian, Red Hat/Fedora, Solaris, DD-WRT, NetBSD, Mac OS8/9, Mac OSX, UMP/OS, ESX
Posts: 42
Original Poster
Rep:
Maybe I should rephrase the end of my previous post; I would like to know two things, A) is this technically possible with python at this moment, and if so, then with what module/libraries?
If it is currently impossible, then I would prefer to find out the easy way, too.
Distribution: Debian, Red Hat/Fedora, Solaris, DD-WRT, NetBSD, Mac OS8/9, Mac OSX, UMP/OS, ESX
Posts: 42
Original Poster
Rep:
Well, to me the situation appears to be the following:
- Bluez features full support for the desired functionality.
- PyBluez or other Python Bluetooth modules do not contain this functionality as the bindings are missing in the Bluez libraries.
This would mean that I would need to add bindings in the Bluez libraries, recompile, add support for these new bindings in PyBluez or another Python Bluetooth module and then write the actual code that I would need...
My solution (well, ok, it's a workaround, really): get obex-pushd, a standalone application which receives incoming files, or 'objects' to be precise, as it uses OBEX Object Push rather than OBEX File Transfer.
If anyone is interested in extending Python's Bluetooth functionality, I'd be very interested in acquiring the resulting code/modules, and would also love to contribute. If I take it upon me to implement the required bindings, I will post it here.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.