btmgmt provided no response
chemax opened this issue · 5 comments
Hi. When i'm triyng to get adapters list
go-bluetooth/examples/btmgmt/btmgmt.go
Line 11 in 03c23c6
i have error "btmgmt provided no response".
I'm use it on raspbian 10. How i can fix it?
Seems a setup issue to me, ensure btmgmt is working first. If you find a fix, please share a PR!
Closing, please reopen if you have updates. Thanks
I can confirm that the issue still persists.
I tried to run the example you provide in the example
directory, but found out that you have a very simple wrapper on top of it. So, I wrote a test to avoid using your wrapper method:
package scratch
import (
"bytes"
"fmt"
"log"
"os/exec"
"testing"
)
func TestBTMGMT(t *testing.T) {
cmd := exec.Command("btmgmt", "info")
outb, errb := new(bytes.Buffer), new(bytes.Buffer)
cmd.Stdout = outb
cmd.Stderr = errb
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
fmt.Println("out:", outb.String(), "err:", errb.String())
}
The result I've got:
=== RUN TestBTMGMT
out: err:
--- PASS: TestBTMGMT (0.01s)
PASS
This is something really weird with the btmgmt
, it outputs the result of running it without the Go wrapper as it intended to.
My setup is:
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
Kernel: Linux scanner 5.15.6-051506-generic #202112010437 SMP Wed Dec 1 09:47:58 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
go version go1.17.3 linux/amd64
Thank you for reporting your tests, it is weird indeed. I suspect it being related to permission issues, eg. missing the cap cap_net_admin
Please consider using another approach, like hciconfig or bluetoothctl if it fit your needs
If you sort it out, a PR is welcome!
The approach with the hciconfig
package worked fine for me, thanks!
hciInterface, err := hciconfig.GetAdapter(rcv.nic)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to get the bluetooth interface [hci=%s]", hci)
}
Great, need to take some time and clean up those wrappers.. Closing, please reopen if needed!