I'm trying to get a bluetoothe device working in Python on Bluez5. Currently I have the following:
#set up a bluez profile to advertise device capabilities from a loaded service record
def init_bluez_profile(self):
print("Configuring Bluez Profile")
#setup profile options
service_record=self.read_sdp_service_record()
opts = {
"ServiceRecord":service_record,
"Role":"server",
"RequireAuthentication":False,
"RequireAuthorization":False,
"Name":BTKbDevice.MY_DEV_NAME,
"AutoConnect":True
}
#retrieve a proxy for the bluez profile interface
bus = dbus.SystemBus()
self.manager = dbus.Interface(bus.get_object("org.bluez","/org/bluez"), "org.bluez.ProfileManager1")
self.profile = BTKbBluezProfile(bus, BTKbDevice.PROFILE_DBUS_PATH)
self.manager.RegisterProfile(BTKbDevice.PROFILE_DBUS_PATH, BTKbDevice.UUID, opts)
print("Profile registered ")
This code executes properly and the profile code is the standard one from teh bluez test cases:
class BTKbBluezProfile(dbus.service.Object):
fd = -1
@dbus.service.method("org.bluez.Profile1",
in_signature="", out_signature="")
def Release(self):
print("Release")
mainloop.quit()
@dbus.service.method("org.bluez.Profile1",
in_signature="", out_signature="")
def Cancel(self):
print("Cancel")
@dbus.service.method("org.bluez.Profile1", in_signature="oha{sv}", out_signature="")
def NewConnection(self, path, fd, properties):
self.fd = fd.take()
print("NewConnection(%s, %d)" % (path, self.fd))
for key in properties.keys():
print ('key ' + key + ' value ' + properties[key])
if key == "Version" or key == "Features":
print(" %s = 0x%04x" % (key, properties[key]))
else:
print(" %s = %s" % (key, properties[key]))
@dbus.service.method("org.bluez.Profile1", in_signature="o", out_signature="")
def RequestDisconnection(self, path):
print("RequestDisconnection(%s)" % (path))
if (self.fd > 0):
os.close(self.fd)
self.fd = -1
def __init__(self, bus, path):
dbus.service.Object.__init__(self, bus, path)
However when I get connections/disconnections nothing works. I've tried playing around with the various options but I just can't get anything to register. The documentation is light and there seems to be little debugging info I can get on the dbus communication. Has anybody succeeded in regsitering a profile and/or obtaining more debugging information on the bluez interaction?
Thanks.
from Bluez Profile Registration
No comments:
Post a Comment