23
23
`adafruit_ble.current_time_client`
24
24
====================================================
25
25
26
- UART-style communication by a Central as a GATT Client
26
+ Connect to a Current Time Service, as a peripheral.
27
27
28
28
* Author(s): Dan Halbert for Adafruit Industries
29
29
@@ -43,14 +43,17 @@ class CurrentTimeClient:
43
43
Example::
44
44
45
45
from adafruit_ble.current_time_client import CurrentTimeClient
46
+ import time
46
47
47
48
cts_client = CurrentTimeClient()
48
49
cts_client.start_advertising()
49
50
while not cts_client.connected:
50
51
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)
54
57
55
58
To try the example above, open Settings->Bluetooth on your iOS device.
56
59
After the program starts advertising, ``CIRCUITPYxxxx` will show up as a Bluetooth
@@ -90,15 +93,13 @@ def disconnect(self):
90
93
def _check_connected (self ):
91
94
if not self .connected :
92
95
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 ()
93
100
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 ):
100
102
"""Discover service information."""
101
- self ._check_connected ()
102
103
services = self ._periph .discover_remote_services ((self .CTS_UUID ,))
103
104
if not services :
104
105
raise OSError ("Unable to discover service" )
0 commit comments