Skip to content

Commit 672f51c

Browse files
committed
UARTClient now works both directions
1 parent cee6816 commit 672f51c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

adafruit_ble/scanner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def service_uuids(self):
145145

146146
if concat_uuids:
147147
for i in range(0, len(concat_uuids), 2):
148-
uuid_values.append(struct.unpack("<H", concat_uuids[i:i+2]))
148+
uuid_values.extend(struct.unpack("<H", concat_uuids[i:i+2]))
149149

150150
concat_uuids = self.item(AdvertisingPacket.ALL_128_BIT_SERVICE_UUIDS)
151151
concat_uuids = concat_uuids if concat_uuids else self.item(
@@ -155,7 +155,6 @@ def service_uuids(self):
155155
for i in range(0, len(concat_uuids), 16):
156156
uuid_values.append(concat_uuids[i:i+16])
157157

158-
print(uuid_values)
159158
return [bleio.UUID(value) for value in uuid_values]
160159

161160
@property

adafruit_ble/uart_client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class UARTClient:
5757
uart_client.write('abc')
5858
"""
5959

60-
def __init__(self, *, timeout=5.0, buffer_size=64):
60+
def __init__(self, *, timeout=1.0, buffer_size=64):
6161
self._buffer_size = buffer_size
6262
self._timeout = timeout
6363
self._read_char = self._write_char = self._read_buffer = None
@@ -67,7 +67,8 @@ def connect(self, address, timeout):
6767
"""Try to connect to the peripheral at the given address.
6868
6969
:param bleio.Address address: The address of the peripheral to connect to
70-
:param float/int timeout: Try to connect for timeout seconds.
70+
:param float/int timeout: Try to connect for ``timeout`` seconds.
71+
Not related to the timeout passed to ``UARTClient()``.
7172
"""
7273
self._central.connect(address, timeout, service_uuids=(NUS_SERVICE_UUID,))
7374

@@ -83,10 +84,14 @@ def connect(self, address, timeout):
8384
self._read_char = characteristic
8485
if not self._write_char or not self._read_char:
8586
raise OSError("Remote UART missing needed characteristic")
87+
88+
# Enable notifications from the server (the peripheral).
89+
self._read_char.set_cccd(notify=True)
8690
self._read_buffer = CharacteristicBuffer(self._read_char,
8791
timeout=self._timeout,
8892
buffer_size=self._buffer_size)
8993

94+
9095
def disconnect(self):
9196
"""Disconnect from the peripheral."""
9297
self._central.disconnect()

0 commit comments

Comments
 (0)