Using Python to push files using bluetooth
November 19, 2007 at 09:32 AM | categories: python, oldblog | View Comments
Just jotting this down really. You need Lightblue installed, which also requires pybluez (hence bluez) and also openobex installed. OK, no further ado:
>>> from lightblue import *
>>>
>>> finddevices()
[('00:11:9F:C3:7E:A7', u'Nokia 6630', 5243404)]
>>> services = findservices("00:11:9F:C3:7E:A7")
>>> services
[('00:11:9F:C3:7E:A7', None, u'SDP Server'),
('00:11:9F:C3:7E:A7', 1, u'Hands-Free Audio Gateway'),
('00:11:9F:C3:7E:A7', 2, u'Headset Audio Gateway'),
('00:11:9F:C3:7E:A7', 10, u'OBEX File Transfer'),
('00:11:9F:C3:7E:A7', 11, u'SyncMLClient'),
('00:11:9F:C3:7E:A7', 12, u'Nokia OBEX PC Suite Services'),
('00:11:9F:C3:7E:A7', 9, u'OBEX Object Push'),
('00:11:9F:C3:7E:A7', 3, u'Dial-Up Networking'),
('00:11:9F:C3:7E:A7', 15, u'Imaging')]
>>>
>>> D = [ (x,y,z) for x,y,z in services if "obex" in z.lower() and "push" in z.lower()]
>>> D
[('00:11:9F:C3:7E:A7', 9, u'OBEX Object Push')]
>>> (device, channel, description) = D[0]
>>> obex.sendfile(device, channel, "/media/usbdisk/Kamaelia/cat-trans.png")
[btobexclient_connect] Connecting transport...
[btobexclient_connect] Connecting OBEX session...
[btobexclient_done] Request 0x00 successful
[btobexclient_put] Sending file 'cat-trans.png' (116671 bytes)...
[btobexclient_done] Request 0x02 successful
[btobexclient_disconnect] Disconnecting...
[btobexclient_done] Request 0x01 successful
[btobexserver_cleanup] entry.
>>>