ble_current_time_service.py
1 """ 2 This example solicits that devices that provide the current time service connect to it, initiates 3 pairing and then prints the time every second. 4 """ 5 6 import time 7 import adafruit_ble 8 from adafruit_ble.advertising.standard import SolicitServicesAdvertisement 9 from adafruit_ble.services.standard import CurrentTimeService 10 11 radio = adafruit_ble.BLERadio() 12 a = SolicitServicesAdvertisement() 13 a.complete_name = "TimePlease" 14 a.solicited_services.append(CurrentTimeService) 15 radio.start_advertising(a) 16 17 while not radio.connected: 18 pass 19 20 print("connected") 21 22 while radio.connected: 23 for connection in radio.connections: 24 if not connection.paired: 25 connection.pair() 26 print("paired") 27 cts = connection[CurrentTimeService] 28 print(cts.current_time) 29 time.sleep(1) 30 31 print("disconnected")