Skip to content

Connect to an address directly #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions adafruit_ble/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,18 @@ def stop_scan(self):
once empty."""
self._adapter.stop_scan()

def connect(self, advertisement, *, timeout=4.0):
def connect(self, peer, *, timeout=4.0):
"""
Initiates a `BLEConnection` to the peer that advertised the given advertisement.

:param advertisement Advertisement: An `Advertisement` or a subclass of `Advertisement`
:param timeout float: how long to wait for a connection
:param Advertisement peer: An `Advertisement`, a subclass of `Advertisement` or `Address`
:param float timeout: how long to wait for a connection
:return: the connection to the peer
:rtype: BLEConnection
"""
connection = self._adapter.connect(advertisement.address, timeout=timeout)
if not isinstance(peer, _bleio.Address):
peer = peer.address
connection = self._adapter.connect(peer, timeout=timeout)
self._connection_cache[connection] = BLEConnection(connection)
return self._connection_cache[connection]

Expand Down
5 changes: 3 additions & 2 deletions examples/ble_uart_echo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# SPDX-License-Identifier: MIT

"""
Can be used with ble_uart_echo_client.py or with the UART page on the Adafruit Bluefruit Connect app.
Receives characters from the UARTService and transmits them back.
Can be used with ble_uart_echo_client.py or with the UART page on the
Adafruit Bluefruit Connect app. Receives characters from the UARTService
and transmits them back.
"""

from adafruit_ble import BLERadio
Expand Down