I am using BlueZ-obexd and pydbus to create a python obex client for opp file transfer. So far, I have been able to get file transfer working, and I am trying to implement RemoveSession from the API to trigger only after the transfer has completed or failed. I know there is a status property in the API too, but I have absolutely no idea how to use it. I don't have a lot of experience with dbus or pydbus, so any help would be great. My code is below.
import pydbus
import time
import subprocess
# Setup of device specific values
address = subprocess.check_output("bluetoothctl paired-devices", shell=True)
dev_id = str(address)[9:26]
TRANSFER_IFACE = 'org.bluez.obex.Transfer1'
ses = pydbus.SessionBus()
obex = ses.get('org.bluez.obex', '/org/bluez/obex')
ses1 = obex.CreateSession(dev_id, {'Target': pydbus.Variant('s', 'OPP')})
ses1_dbus = ses.get('org.bluez.obex', ses1)
props = ses1_dbus.SendFile('/home/pi/Desktop/image.jpg')
obex.RemoveSession(ses1)
The documentation for
SendFilesays that a DBus object path and a dictionary of properties is returned. The interface of the object returned isorg.bluez.obex.Transfer1which allows theStatusto be monitored.The ideal way to monitor this status is with the event loop from GLib.MainLoop and watch for the
PropertiesChangedsignal on the DBus object path returned bySendFile.Also, with getting the paired device information, there is a BlueZ DBus API for getting that information without the need to do a
subprocesscall tobluetoothctl.I've tried to do an example of both: