gatt icon indicating copy to clipboard operation
gatt copied to clipboard

Multiple connections

Open raowhizz opened this issue 9 years ago • 4 comments
trafficstars

As a central, how can I make multiple connections at the same time ? Also what is the max number of peripheral connections allowed by GATT ?

raowhizz avatar Dec 15 '15 12:12 raowhizz

Haven't tried multiple connections when running as a central, but did 4 concurrent connections when running as a peripheral. The number of concurrency is determined by the hardware/firmware.

roylee17 avatar Dec 16 '15 05:12 roylee17

@roylee17 Which OS and Hardware did you use to achieve 4 concurrent connections?

moogle19 avatar Jan 06 '16 10:01 moogle19

Broadcom - BCM4334, on Linux.

roylee17 avatar Jan 06 '16 10:01 roylee17

Turns out you can have multiple connect on linux as a central. (do not know about other platforms) First you have to do

d, err := gatt.NewDevice([]gatt.Option{
        gatt.LnxMaxConnections(5),
        gatt.LnxDeviceID(-1, true),
    }...)

Then, that is probably a bug, you can not connect to different devices at same time. Otherwise only first connected device gets the connected callback. You have to do the connection one at a time. I did it in following way:

mu.Lock()
go func(count int) {
    time.Sleep(time.Duration(count) * 5 * time.Second)
    p.Device().Connect(p)
}(count)
count++
mu.Unlock()

helinwang avatar Mar 23 '16 22:03 helinwang