2323`adafruit_ble.current_time_client`
2424====================================================
2525
26- UART-style communication by a Central as a GATT Client
26+ Connect to a Current Time Service, as a peripheral.
2727
2828* Author(s): Dan Halbert for Adafruit Industries
2929
@@ -43,14 +43,17 @@ class CurrentTimeClient:
4343 Example::
4444
4545 from adafruit_ble.current_time_client import CurrentTimeClient
46+ import time
4647
4748 cts_client = CurrentTimeClient()
4849 cts_client.start_advertising()
4950 while not cts_client.connected:
5051 pass
51- cts_client.discover()
52- cts_client.pair()
53- print(cts_client.current__time)
52+ # The first time a property is read, the client
53+ # will do discovery and pairing.
54+ while True:
55+ print(cts_client.current_time)
56+ time.sleep(5)
5457
5558 To try the example above, open Settings->Bluetooth on your iOS device.
5659 After the program starts advertising, ``CIRCUITPYxxxx` will show up as a Bluetooth
@@ -90,15 +93,13 @@ def disconnect(self):
9093 def _check_connected (self ):
9194 if not self .connected :
9295 raise OSError ("Not connected" )
96+ # Do discovery and pairing if not already done.
97+ if not self ._current_time_char :
98+ self ._discover ()
99+ self ._periph .pair ()
93100
94- def pair (self ):
95- """Pair with the connected central."""
96- self ._check_connected ()
97- self ._periph .pair ()
98-
99- def discover (self ):
101+ def _discover (self ):
100102 """Discover service information."""
101- self ._check_connected ()
102103 services = self ._periph .discover_remote_services ((self .CTS_UUID ,))
103104 if not services :
104105 raise OSError ("Unable to discover service" )
0 commit comments