LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-13-2011, 06:27 PM   #1
PelliX
Member
 
Registered: Apr 2006
Location: Enschede
Distribution: Debian, Red Hat/Fedora, Solaris, DD-WRT, NetBSD, Mac OS8/9, Mac OSX, UMP/OS, ESX
Posts: 42

Rep: Reputation: 15
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?

Many thanks in advance,

PelliX

Last edited by PelliX; 02-14-2011 at 01:41 PM.
 
Old 02-14-2011, 05:05 PM   #2
PelliX
Member
 
Registered: Apr 2006
Location: Enschede
Distribution: Debian, Red Hat/Fedora, Solaris, DD-WRT, NetBSD, Mac OS8/9, Mac OSX, UMP/OS, ESX
Posts: 42

Original Poster
Rep: Reputation: 15
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.
 
Old 02-16-2011, 11:45 PM   #3
PelliX
Member
 
Registered: Apr 2006
Location: Enschede
Distribution: Debian, Red Hat/Fedora, Solaris, DD-WRT, NetBSD, Mac OS8/9, Mac OSX, UMP/OS, ESX
Posts: 42

Original Poster
Rep: Reputation: 15
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.

Thanks,

PelliX
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python - How to get text file data into an array on python. golmschenk Programming 4 11-11-2013 09:15 AM
Using python to edit a python file. deathalele Programming 2 08-27-2008 12:34 PM
Python: how to import a python file that doesn't end in .py? BrianK Programming 5 04-15-2008 12:35 PM
how to exchange two columns of a file jackk294 Programming 8 07-11-2006 11:37 PM
linus/win file exchange andreamazza Red Hat 1 09-22-2004 01:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration