All of lore.kernel.org
 help / color / mirror / Atom feed
From: Barry Byford <31baz66@gmail.com>
To: KeithG <ys3al35l@gmail.com>
Cc: Bluez mailing list <linux-bluetooth@vger.kernel.org>
Subject: Re: Request for help with btmgmt
Date: Wed, 23 Dec 2020 07:53:34 +0000	[thread overview]
Message-ID: <CAAu3APaGmCAA8JGKgFcg4wzJLT4y05BhvYu6uA05COdvEyauow@mail.gmail.com> (raw)
In-Reply-To: <CAG17S_Oy_N_YPo6x5pmZ05p4MqH_gDUrRS0TR3ydQVG9BvmYEw@mail.gmail.com>

Hello Keith,

On Wed, 23 Dec 2020 at 00:34, KeithG <ys3al35l@gmail.com> wrote:
>
> I am developing a RPi based audio player. We are trying to add
> bluetooth capability to this player. We use alsa and not pulse-audio,
> so we need a bit more granular info to get it to run. I have written a
> script which is designed to be triggered by udev when a BT device is
> added or removed. This script will then use bluetoothctl to get the
> capabilities of the device and also add or remove it from a dynamic
> database list of MACs in redis. I have a simple script working as I
> want from the cli. The key command I am using is 'btmgmt con' which is
> the only command I have found that tells me what MACs are currently
> connected. I can run this command from the command line as root. I can
> set the setuid bit of btmgmt and also get it to run as a user (http in
> this case). I cannot, ever, get this command to run when triggered
> from udev. I get no response and no error.
>
> 1) Why is this particular command (query attached BT MACs) not part of
> bluetoothctl?  Is there a security issue?
> 2) Why can I not run 'btmgmt con' in a script (bash or php) triggered
> by udev when the device is added or removed?
> 3) is there a 'better way' for me to know what device MAC addresses
> are attached? I have not found another simple way to get this info.
>
> What I am doing in the script is: if an audio source is attached, I
> want to run a bluealsa-aplay service. When an audio sink is attached,
> I want to re-set my audio output to the bluealsa device. If it is not
> an audio device, I do not care, but do keep track of what is attached
> in my database so that the next time the script runs that it is not
> queried and is 'known'.
>
> Thanks for the help.
>
> Keith

I would suggest that the D-Bus API would be a more appropriate way to
get the information you want.

The "get managed objects" functionality is a good way to iterate
through all the devices that BlueZ knows about.
There are examples at:
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/bluezutils.py
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/list-devices

The D-Bus API also allows your code to execute callbacks when a device
is added or its connection state changes.
This is done with the InterfacesAdded and PropertiesChanged signals.

If you are going to use Python I would suggest the
https://pypi.org/project/pydbus/ library is a more "Pythonic" set of
D-Bus bindings.

The API is documented at:
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc

Regards,
Barry

  reply	other threads:[~2020-12-23  7:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-23  0:32 Request for help with btmgmt KeithG
2020-12-23  7:53 ` Barry Byford [this message]
2020-12-25 20:32   ` KeithG
2020-12-26 16:28     ` KeithG

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAAu3APaGmCAA8JGKgFcg4wzJLT4y05BhvYu6uA05COdvEyauow@mail.gmail.com \
    --to=31baz66@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=ys3al35l@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.