1 year ago

#298514

test-img

jpwr

Per-connection notifications using BlueZ peripheral

I want to use BlueZ as a peripheral / GATT server, and have multiple central devices connect and subscribe to a particular characteristic. Then, I want to send a notification to only 1 of the connected centrals via a Python application. The subscription behavior is in a piece of code I can't control, so having only 1 central be subscribed is not an option. I also need the connection to stay active, so disconnecting from the other devices is also not an option.

I have the GATT server working, notifying all connected centrals via the PropertiesChanged DBus method, by following the example-gatt-server method. The DBus API does not provide a way to deliver a notification to a particular connection handle or connected device, so instead I think my application needs to interact with a BlueZ file descriptor directly. I found that adding the NotifyAcquired property could trigger a call to an implementation of AcquireNotify:

class Characteristic(dbus.service.Object):
    """
    org.bluez.GattCharacteristic1 interface implementation
    """
    def __init__(self, bus, index, uuid, flags, service):
        self.path = service.path + '/char' + str(index)
        self.bus = bus
        self.uuid = uuid
        self.service = service
        self.flags = flags
        self.descriptors = []
        dbus.service.Object.__init__(self, bus, self.path)

    def get_properties(self):
        return {
                GATT_CHRC_IFACE: {
                        'Service': self.service.get_path(),
                        'UUID': self.uuid,
                        'Flags': self.flags,
                        'Descriptors': dbus.Array(
                                self.get_descriptor_paths(),
                                signature='o'),
                        'NotifyAcquired': False
                }
        }

    ...

    @dbus.service.method(GATT_CHRC_IFACE, in_signature='a{sv}', out_signature='hq')
    def AcquireNotify(self, options):
        print('Default AcquireNotify called, returning error')
        raise NotSupportedException()

This leaves me with two questions:

  1. How do I generate the fd object that AcquireNotify is expected to return?
  2. How can I use the fd object to deliver a notification to a particular connected device?

bluez

0 Answers

Your Answer

Accepted video resources