paypal / gatt

Gatt is a Go package for building Bluetooth Low Energy peripherals
BSD 3-Clause "New" or "Revised" License
1.13k stars 284 forks source link

Multiple connections #57

Open raowhizz opened 8 years ago

raowhizz commented 8 years ago

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 ?

roylee17 commented 8 years ago

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.

moogle19 commented 8 years ago

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

roylee17 commented 8 years ago

Broadcom - BCM4334, on Linux.

helinwang commented 8 years ago

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()