# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT """ This example solicits that devices that provide the current time service connect to it, initiates pairing and then prints the time every second. """ import time import adafruit_ble from adafruit_ble.advertising.standard import SolicitServicesAdvertisement from adafruit_ble.services.standard import CurrentTimeService radio = adafruit_ble.BLERadio() a = SolicitServicesAdvertisement() a.complete_name = "TimePlease" a.solicited_services.append(CurrentTimeService) radio.start_advertising(a) while not radio.connected: pass print("connected") while radio.connected: for connection in radio.connections: if not connection.paired: connection.pair() print("paired") cts = connection[CurrentTimeService] print(cts.current_time) time.sleep(1)
if a.value or b.value: self._update_time = time.monotonic() if time.monotonic() - self._update_time > self._timeout: if display.brightness > self._level: display.brightness = self._level else: if display.brightness == self._level: display.brightness = 1.0 dimmer = Dimmer() # Start advertising before messing with the display so that we can connect immediately. radio = adafruit_ble.BLERadio() advertisement = SolicitServicesAdvertisement() advertisement.complete_name = "CIRCUITPY" advertisement.solicited_services.append(AppleNotificationCenterService) def wrap_in_tilegrid(filename: str): # CircuitPython 6 & 7 compatible odb = displayio.OnDiskBitmap(open(filename, "rb")) return displayio.TileGrid(odb, pixel_shader=getattr(odb, 'pixel_shader', displayio.ColorConverter())) # # CircuitPython 7+ compatible # odb = displayio.OnDiskBitmap(filename) # return displayio.TileGrid(odb, pixel_shader=odb.pixel_shader)
serv_env_sense.measurement_period = 10000 # 10s last_update = 0 ble = BLERadio() # The Web Bluetooth dashboard identifies known boards by their # advertised name, not by advertising manufacturer data. ble.name = "BME680_02" bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, address=0x76) # The Bluefruit Playground app looks in the manufacturer data # in the advertisement. That data uses the USB PID as a unique ID. # Adafruit CLUE USB PID: # Arduino: 0x8071, CircuitPython: 0x8072, app supports either adv = SolicitServicesAdvertisement() adv.complete_name = "EnvSensing" adv.solicited_services.append(serv_env_sense) #adv.pid = 0x1802 last_t = 0 last_h = 0 last_p = 0 last_l = 0 while True: # Advertise when not connected. ble.start_advertising(adv) now_msecs = time.monotonic_ns() // 1000000 while not ble.connected: led_blink() ble.stop_advertising()
""" This example solicits that apple devices that provide notifications connect to it, initiates pairing, prints existing notifications and then prints any new ones as they arrive. """ import time import adafruit_ble from adafruit_ble.advertising.standard import SolicitServicesAdvertisement from adafruit_ble.services.apple import AppleNotificationService radio = adafruit_ble.BLERadio() a = SolicitServicesAdvertisement() a.complete_name = "NotifyPlease" a.solicited_services.append(AppleNotificationService) radio.start_advertising(a) while not radio.connected: pass print("connected") known_notifications = set() while radio.connected: for connection in radio.connections: if not connection.paired: connection.pair() print("paired") ans = connection[AppleNotificationService] for notification in ans: