From 42c2dde1b666d933f309ec4064b9fd55dee62b07 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 10 Sep 2021 12:04:36 -0700 Subject: [PATCH 1/3] 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. --- adafruit_ble/__init__.py | 10 ++++++---- examples/ble_uart_echo_test.py | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/adafruit_ble/__init__.py b/adafruit_ble/__init__.py index c730ea8..d550b8c 100755 --- a/adafruit_ble/__init__.py +++ b/adafruit_ble/__init__.py @@ -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] diff --git a/examples/ble_uart_echo_test.py b/examples/ble_uart_echo_test.py index e069919..cb938ef 100644 --- a/examples/ble_uart_echo_test.py +++ b/examples/ble_uart_echo_test.py @@ -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 From acf5caef618927a79d8158e316b0253f2fd33684 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 10 Sep 2021 12:45:51 -0700 Subject: [PATCH 2/3] Fix docs --- adafruit_ble/__init__.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/adafruit_ble/__init__.py b/adafruit_ble/__init__.py index d550b8c..30f3ef4 100755 --- a/adafruit_ble/__init__.py +++ b/adafruit_ble/__init__.py @@ -32,7 +32,7 @@ class BLEConnection: Represents a connection to a peer BLE device. It acts as a map from a `Service` type to a `Service` instance for the connection. - :param bleio_connection _bleio.Connection: the native `_bleio.Connection` object to wrap + :param _bleio.Connection bleio_connection: the native `_bleio.Connection` object to wrap """ @@ -227,15 +227,15 @@ def start_scan( :param float timeout: the scan timeout in seconds. If None, will scan until `stop_scan` is called. :param float interval: the interval (in seconds) between the start - of two consecutive scan windows - Must be in the range 0.0025 - 40.959375 seconds. + of two consecutive scan windows + Must be in the range 0.0025 - 40.959375 seconds. :param float window: the duration (in seconds) to scan a single BLE channel. - window must be <= interval. + window must be <= interval. :param int minimum_rssi: the minimum rssi of entries to return. :param bool active: request and retrieve scan responses for scannable advertisements. :return: If any ``advertisement_types`` are given, - only Advertisements of those types are produced by the returned iterator. - If none are given then `Advertisement` objects will be returned. + only Advertisements of those types are produced by the returned iterator. + If none are given then `Advertisement` objects will be returned. :rtype: iterable """ if not advertisement_types: @@ -280,7 +280,8 @@ def connect(self, peer, *, timeout=4.0): """ Initiates a `BLEConnection` to the peer that advertised the given advertisement. - :param Advertisement peer: An `Advertisement`, a subclass of `Advertisement` or `Address` + :param Advertisement peer: An `Advertisement`, a subclass of `Advertisement` + or `_bleio.Address` :param float timeout: how long to wait for a connection :return: the connection to the peer :rtype: BLEConnection From 3d960fb22042e3ab977b0f48fe94f311175fa69a Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 13 Sep 2021 10:50:01 -0700 Subject: [PATCH 3/3] Remove type from peer param --- adafruit_ble/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adafruit_ble/__init__.py b/adafruit_ble/__init__.py index 30f3ef4..d6eee48 100755 --- a/adafruit_ble/__init__.py +++ b/adafruit_ble/__init__.py @@ -280,8 +280,7 @@ def connect(self, peer, *, timeout=4.0): """ Initiates a `BLEConnection` to the peer that advertised the given advertisement. - :param Advertisement peer: An `Advertisement`, a subclass of `Advertisement` - or `_bleio.Address` + :param peer: An `Advertisement`, a subclass of `Advertisement` or `_bleio.Address` :param float timeout: how long to wait for a connection :return: the connection to the peer :rtype: BLEConnection