muka / go-bluetooth

Golang bluetooth client based on bluez DBus interfaces
Apache License 2.0
653 stars 122 forks source link

How to set it up so that it can be connected directly without pairing? #192

Open cyub opened 9 months ago

cyub commented 9 months ago

I want to use the go-bluetooth package to configure wifi (WiFi setup over BLE). When operating our app, a pairing pop-up window always pops up. How to connect the ble device directly without popping up the pairing pop-up window. Our ble device driver uses bluez5.63. Can anyone give some advice?

cyub commented 8 months ago

I found that when using btmgmt to set pairable to false after Advertise, the central device, such as a mobile phone, etc., can no longer pop up the pairing window. This will solve the problem. The code example is as follows:

options := service.AppOptions{
    AdapterID:  adapterID,
    AgentCaps:  agent.CapNoInputNoOutput,
    UUIDSuffix: "-0000-1000-8000-00805F9B34FB",
    UUID:       "1234",
}

a, err := service.NewApp(options)
if err != nil {
    return err
}
defer a.Close()

...

ancel, err := a.Advertise(timeout)
if err != nil {
    return err
}

btmgmt := hw.NewBtMgmt(adapterID)
btmgmt.SetPairable(false)