how to use org.bluez.AudioSource GetProperty

1.6k views Asked by At

how can i check weather the given device is connected. using org.bluez.AudioSource GetProperty I am using c and DBus,can anybody help me to get out of this...

1

There are 1 answers

2
Halim Qarroum On

I assume you've been looking into the BlueZ D-BUS API which is a precious documentation for everything related to listening on BlueZ's signals and query information. You can find it in any BlueZ source in the doc/ folder.

To check if a device is connected, you first need to get all the Bluetooth devices on your computer and their paths using D-BUS, I will not provide any C documentation as you can easily find plenty of examples about this using Google. I will instead show you what D-BUS calls you can make via dbus-send to get such an information.

Get Devices list:

dbus-send --system \  
  --dest=org.bluez \  
  --print-reply /  \  
  org.bluez.Manager.GetProperties

This returns an array of adapters with their paths.
Once you have these path(s) you can retrieve the list of all the Bluetooth devices paired with your adapter(s).

Get paired devices:

dbus-send --system \  
  --print-reply \  
  --dest=org.bluez \  
  /org/bluez/{pid}/hci0 \  
  org.bluez.Adapter.GetProperties  

This gives you the list of paired devices within the Devices array field.

Once you have the list of devices paired to your Bluetooth Adapter, you can know if it is connected to the AudioSource interface.

Get the devices connected to the AudioSource interface :

dbus-send --system \  
  --print-reply \  
  --dest=org.bluez \  
  /org/bluez/{pid}/hci0/dev_XX_XX_XX_XX_XX_XX \  
  org.bluez.AudioSource.GetProperties  

I find it more to convenient to first try d-bus calls using dbus-send because the D-BUS C API is a bit confusing and inconvenient to use.