From 48520de2f70081812dc38975b99d6b66504cbdc4 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Tue, 5 Jul 2016 12:35:37 +0200 Subject: [PATCH] [ble] Can connect by advertised local name or by ID Signed-off-by: deadprogram --- platforms/ble/ble_adaptor.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/platforms/ble/ble_adaptor.go b/platforms/ble/ble_adaptor.go index d98d1b13..87162546 100644 --- a/platforms/ble/ble_adaptor.go +++ b/platforms/ble/ble_adaptor.go @@ -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.