[ble] Can connect by advertised local name or by ID

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2016-07-05 12:35:37 +02:00
parent 500283c87f
commit 48520de2f7
1 changed files with 9 additions and 3 deletions

View File

@ -154,9 +154,15 @@ func (b *BLEAdaptor) StateChangeHandler(d gatt.Device, s gatt.State) {
}
func (b *BLEAdaptor) DiscoveryHandler(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
id := strings.ToUpper(b.UUID())
if strings.ToUpper(p.ID()) != id {
return
// try looking by local name
if a.LocalName == b.UUID() {
b.uuid = p.ID()
} else {
// try looking by ID
id := strings.ToUpper(b.UUID())
if strings.ToUpper(p.ID()) != id {
return
}
}
// Stop scanning once we've got the peripheral we're looking for.