Skip to content

Commit 5e5c88b

Browse files
committed
match updated API for Characteristic properties, etc.
1 parent 4441123 commit 5e5c88b

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

adafruit_ble/current_time_client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
class CurrentTimeClient:
3838
"""
39-
Set up a peripheral that solicits centrals for Current Time Service,
39+
Set up a peripheral that solicits centrals for Current Time Service.
4040
4141
:param str name: Name to advertise for server. If None, use default Advertisement name.
4242
@@ -50,7 +50,12 @@ class CurrentTimeClient:
5050
pass
5151
cts_client.discover()
5252
cts_client.pair()
53-
print(cts_client.current_local_time)
53+
print(cts_client.current__time)
54+
55+
To try the example above, open Settings->Bluetooth on your iOS device.
56+
After the program starts advertising, ``CIRCUITPYxxxx` will show up as a Bluetooth
57+
device for possible connection. Tap it, and then accept the pairing request.
58+
Then the time should print.
5459
"""
5560

5661
CTS_UUID = UUID(0x1805)
@@ -59,7 +64,7 @@ class CurrentTimeClient:
5964

6065
def __init__(self, name=None, tx_power=0):
6166
self._periph = Peripheral(name=name)
62-
self._advertisement = SolicitationAdvertisement(peripheral.name, (self.CTS_UUID,), tx_power=tx_power)
67+
self._advertisement = SolicitationAdvertisement(self._periph.name, (self.CTS_UUID,), tx_power=tx_power)
6368
self._current_time_char = self._local_time_char = None
6469

6570

adafruit_ble/uart_server.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* Author(s): Dan Halbert for Adafruit Industries
2929
3030
"""
31-
from bleio import Characteristic, CharacteristicBuffer, Peripheral, Service
31+
from bleio import Attribute, Characteristic, CharacteristicBuffer, Peripheral, Service
3232
from .advertising import ServerAdvertisement
3333
from .uart import NUS_SERVICE_UUID, NUS_RX_CHAR_UUID, NUS_TX_CHAR_UUID
3434

@@ -56,8 +56,14 @@ class UARTServer:
5656
"""
5757

5858
def __init__(self, *, timeout=1.0, buffer_size=64, name=None):
59-
self._read_char = Characteristic(NUS_RX_CHAR_UUID, write=True, write_no_response=True)
60-
self._write_char = Characteristic(NUS_TX_CHAR_UUID, notify=True)
59+
self._read_char = Characteristic(
60+
NUS_RX_CHAR_UUID,
61+
properties=Characteristic.WRITE | Characteristic.WRITE_NO_RESPONSE,
62+
read_perm=Attribute.NO_ACCESS, write_perm=Attribute.OPEN)
63+
self._write_char = Characteristic(
64+
NUS_TX_CHAR_UUID,
65+
properties=Characteristic.NOTIFY,
66+
read_perm=Attribute.OPEN, write_perm=Attribute.NO_ACCESS)
6167
self._read_buffer = CharacteristicBuffer(self._read_char,
6268
timeout=timeout, buffer_size=buffer_size)
6369

@@ -82,6 +88,10 @@ def connected(self):
8288
"""True if someone connected to the server."""
8389
return self._periph.connected
8490

91+
def disconnect(self):
92+
"""Disconnect from peer."""
93+
self._periph.disconnect()
94+
8595
def read(self, nbytes=None):
8696
"""
8797
Read characters. If ``nbytes`` is specified then read at most that many bytes.

0 commit comments

Comments
 (0)