Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp7401711pxu; Fri, 25 Dec 2020 12:36:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJyd6fn399hOlzdqozEsUh0OI6heabXZjADw0R8DjKHnuapAN+poyzmoesujOWgu+vnFo6NP X-Received: by 2002:a17:907:3e06:: with SMTP id hp6mr31667238ejc.306.1608928583127; Fri, 25 Dec 2020 12:36:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608928583; cv=none; d=google.com; s=arc-20160816; b=OVO2fa2HNqfGvOfRvJ3YdZoUPV5idmx1cM4YeQtwRWDkU9rWzLO9Y+3P3Q5E7InkGo v4KDK3bIKD6xjIgpFQzcX5ATzers0EeLHb7fKZVLIbyAE3ZBveASssbIRLKPjZuBT+IA J5xVnx1L9bhhBta7YWsWAJIrDqteXl1T8r43wbn5Jdc71iyBmRVlwLXJ5dXTgS78s78w 39TL0AYFchwBeGWc1kYlTKf5qI2L2wT4btv25ssYuows8jOiwwJYBLEzZlGx7hZIkLas c4tRxk42gT8ZPA82+8fFJrMZ1T7mz+63sfNukhXYj/QpgT2TFY67/EFQPJWlJ7qptKNE kjyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=IjQcd2H3mHQ8IPa8tQ5kDw7zy6LluBe8VOLHE+DMLkU=; b=Jyu1BD46fu0Ns4K38Pn3jjZ796siVJaHkkq2Z9frXjYlL4p0oiYXPYg9nhTKxMDoml lnkU/00PVfoGNi90c5p7Szh7h0Hg59xmN5aApylgZn6HZmG4K3bpJBFWR+Mnz+cgKqlE 53xvna89NrdVpeLVZWSu5F/cOspwVvJI+EAr1TwuUYQPUCbwze6xoZcTm4EaLbH5ixVz XKi4d0c7EgV4XPmtG4i8eL9tWo345ePSECWiVCEhA/zpIbofHDBP5jNeE6CQ0OtJ2HK5 aWvPxB7qeRMjyjvlUnsaubTvo3QGq+hnrJ5FZCokqkkQlN2b/GnekMc8zjKCG3dXqnUH uDbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bbj7sqCo; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b22si15246433ejk.400.2020.12.25.12.35.41; Fri, 25 Dec 2020 12:36:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bbj7sqCo; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726641AbgLYUdT (ORCPT + 99 others); Fri, 25 Dec 2020 15:33:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726506AbgLYUdT (ORCPT ); Fri, 25 Dec 2020 15:33:19 -0500 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58C7BC061757 for ; Fri, 25 Dec 2020 12:32:39 -0800 (PST) Received: by mail-ot1-x32e.google.com with SMTP id d20so4443326otl.3 for ; Fri, 25 Dec 2020 12:32:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IjQcd2H3mHQ8IPa8tQ5kDw7zy6LluBe8VOLHE+DMLkU=; b=bbj7sqCoGqHKy9byDmc1EbOEpPTtDQ1dtq7jp0usASaBGV99ye5Y4V/BmX7RhHoEyx eiTXmNKZl1oiTPV8qoIRlKu9hCGiTb5FYWe/BCPxjt8tblQlt0Ff/BmMTY6+gcGWambo +z8m1njb9feUnfP3IvGF0u0Jj+jHXvw/yzm9J4mMqF2JaCngBww7PUDx/snVUhny0yCb 0M5VUp8ZyuGSiumutVG4IoLb4xqof/wivg6GkcBArnFsYo6RIJWmSX1k82SMvJoKQ3ns suQ9BCUIMp6tMyXNTtzv9CYBuKhekZYcen+f7L7noEkhrKHN9UCB9dd/e+Wuo47c4H9A u96A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IjQcd2H3mHQ8IPa8tQ5kDw7zy6LluBe8VOLHE+DMLkU=; b=iA5N0MTjixv1m7ToF0+yK7uMCwio7p5vk6Kt3/o/aUSIZVfKiejhJ5FZmjgQqgCgzV fE84X7N4tJoHL0iY1OA6iRF9jzunHagbRrK6NI7rloKWk06Di6+IXPbDghf5QwP8F7Lb Qan5l6sLs8BpbchkPgvk/39HAEwvsaMDX+4MD4onp5i4b4i/xHzwlIzC/S/bbeR9qOFr 0Rf1e0sDzBEBPcHq6JuIKEEp1fTttA0EXR9DPP8cxjGnhv1mhKHf065tJraPgEI0EGjp /KqM2fqt9T6zGAI9cm9fT5c042DM+8w+pkwaaGpr0EfCp2nBKdCs+O3J2IdX8eZDNoMR bYJQ== X-Gm-Message-State: AOAM530N5gt/1hyjiIw9WXiqBgdL4NxFNmwPeoJlxQtOnnNFm1Vcloi8 nO5XHXHKd7MxRrXRaNoiU1/QcJXMVOWv7wsj/ZdG7Qzs X-Received: by 2002:a9d:6255:: with SMTP id i21mr26611022otk.346.1608928357692; Fri, 25 Dec 2020 12:32:37 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: KeithG Date: Fri, 25 Dec 2020 14:32:26 -0600 Message-ID: Subject: Re: Request for help with btmgmt To: Barry Byford <31baz66@gmail.com> Cc: Bluez mailing list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Barry, Thanks for the help. I will look into it. I fear it may be a bit 'up hill' for me. Can you shed any light as to why: 1) bluetoothctl does not have a command to list the currently connected devices? 2) why btmgmt cannot be run except from the command line? Not even 'btmgmt info' can be run from a script. If it runs, I cannot tell as no output is ever generated and no error is ever listed in the journal. Keith On Wed, Dec 23, 2020 at 1:53 AM Barry Byford <31baz66@gmail.com> wrote: > > Hello Keith, > > On Wed, 23 Dec 2020 at 00:34, KeithG 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