Skip to content

Commit 42c2dde

Browse files
committed
Connect to an address directly
This is helpful for reconnecting to a device we had already connected to. The `connect()` call will do its own scan when connecting.
1 parent 9ae0e7f commit 42c2dde

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

adafruit_ble/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,18 @@ def stop_scan(self):
276276
once empty."""
277277
self._adapter.stop_scan()
278278

279-
def connect(self, advertisement, *, timeout=4.0):
279+
def connect(self, peer, *, timeout=4.0):
280280
"""
281281
Initiates a `BLEConnection` to the peer that advertised the given advertisement.
282282
283-
:param advertisement Advertisement: An `Advertisement` or a subclass of `Advertisement`
284-
:param timeout float: how long to wait for a connection
283+
:param Advertisement peer: An `Advertisement`, a subclass of `Advertisement` or `Address`
284+
:param float timeout: how long to wait for a connection
285285
:return: the connection to the peer
286286
:rtype: BLEConnection
287287
"""
288-
connection = self._adapter.connect(advertisement.address, timeout=timeout)
288+
if not isinstance(peer, _bleio.Address):
289+
peer = peer.address
290+
connection = self._adapter.connect(peer, timeout=timeout)
289291
self._connection_cache[connection] = BLEConnection(connection)
290292
return self._connection_cache[connection]
291293

examples/ble_uart_echo_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# SPDX-License-Identifier: MIT
33

44
"""
5-
Can be used with ble_uart_echo_client.py or with the UART page on the Adafruit Bluefruit Connect app.
6-
Receives characters from the UARTService and transmits them back.
5+
Can be used with ble_uart_echo_client.py or with the UART page on the
6+
Adafruit Bluefruit Connect app. Receives characters from the UARTService
7+
and transmits them back.
78
"""
89

910
from adafruit_ble import BLERadio

0 commit comments

Comments
 (0)