BluezDbus BluezApplication

For references of this implementation see of a bluezdbus application:

Advertising: https://gitlab.com/allthenticate/dependencies/bluez/-/blob/master/doc/advertising-api.txt GATT: https://gitlab.com/allthenticate/dependencies/bluez/-/blob/master/doc/gatt-api.txt DBUS: https://dbus.freedesktop.org/doc/dbus-specification.html dbus-next: https://python-dbus-next.readthedocs.io/_/downloads/en/latest/pdf/

class able.bluezdbus.application.BluezApplication(name, adapter_path=None, auto_recover=False, auto_configure=False)[source]

Bases: dbus_next.service.ServiceInterface

The high level application that abstracts Dbus Calls

Parameters
  • name (str) – the name that this application should request on the dbus

  • auto_recover (bool) – if True will try to recover if bluez restarts, defaults to False

  • adapter_path (Optional[str]) – what is the path to the hardware adapter, will be the first one discovered if not provided, eg. /org/bluez/hci0

  • auto_configure (bool) – if True will try to set bluez settings at startup, defaults to False

async add_advertisement(advertisement)[source]

Adds an le_advertisement object to the application

Return type

None

add_characteristic(service, characteristic, is_comms_char=False)[source]

Adds a characteristic to the application, this must done before running start_application()

TODO(Bernie): What kind of validation should we do here?

Parameters
  • is_comms_char (bool) – if True the characteristic will become the comms characteristic, defaults to False

  • service (ABleService) – the service which the characteristic will be added under

  • characteristic (ABleCharacteristic) – the characteristic you wish to add to the service

Return type

None

Returns

None

add_connect_callback(callback)[source]

Adds a user-defined callback function to the application to be called after connecting to a central device. :type callback: Callable :param callback: the function to be called after a successful connection :rtype: None :return: None

add_disconnect_callback(callback)[source]

Adds a user-defined callback function to the application to be called after disconnecting from a central device. :type callback: Callable :param callback: the function to be called after a successful disconnect :rtype: None :return: None

add_service(service)[source]

Adds a bluez service to the application, this must be done before running start_application()

Raises
  • TypeError – if service is not of type BluezService

  • RuntimeError – if the service has already been added to the application

Parameters

service (ABleService) – the service to add to the bluez application

Return type

None

Returns

None

property bus: dbus_next.aio.message_bus.MessageBus

Property which returns the bus of this application if it is defined

Return type

MessageBus

async cleanup()[source]

This function should be called when the program exits and will handle all cleanup similar to a destructor.

TODO(Bernie): Debug handling here

Return type

None

Returns

None

property communication_characteristic: able.bluezdbus.characteristic.BluezCharacteristic

Property which returns the marked comms characteristic or raises an exception

Return type

BluezCharacteristic

connect_callback(callback_data)[source]

Handler for the new connections being signalled from bluez. Verifies that the central was not already connected and is being stored in the connected_centrals dictionary (this would mean we lost state). Adds an entry to the new connection queue so that a peripheral server can accept the new connection. Adds a new ABleCentral to the connected centrals dictionary. Calls an optional user defined callback last.

Parameters

callback_data (DeviceCallbackData) – data including the identifier required to create ABleCentral

Return type

None

Returns

None

async disconnect(central)[source]

Call bluez to disconnect a connected central, this will not update the connected state of the central because the disconnect callback will handle that.

# TODO(Bernie, Ori): Test the reliability of using remove_device vs disconnect

Parameters

central (ABleCentral) – The central object to force a disconnect.

Return type

None

Returns

None

disconnect_callback(callback_data)[source]

Handler for disconnections being signalled by bluez. Updates the disconnected ABleCentral’s state to be disconnected. Removes the central from the connected centrals dictionary (if it was there, it will not be present if the connection was established before the application was running) and the new connection queue if it is present. Calls an optional user defined callback last.

Parameters

callback_data (DeviceCallbackData) – data regarding the central which disconnected

Return type

None

Returns

None

async get_proxy_interface(bus_name, path, interface_name)[source]

Gets a proxy interface using the _get_proxy_object method

Return type

ProxyInterface

async refresh_advertisement(advertisement)[source]

Hack to try to update params by stopping and restarting the interface

async remove_advertisement(advertisement)[source]

Removes an le_advertisement object from the application

Return type

None

async reset_bus()[source]

Reset the bus. This will remove any current handlers and match rules

Return type

None

async setup()[source]

Setup the application and get it on the dbus, this is a necessary function call to initialize the object.

Return type

None

Returns

None

async start_interface()[source]

Starts the GATT manager interface by registering it with the bluez service manager. Note that any services and their respective characteristics must be added before this is called.

Returns

None