def ams_connect(self, start=time.time(), timeout=30): """ Connect to an Apple device using the ble_apple_media library """ self._status_update("AppleMediaService: Connect your phone now") radio = adafruit_ble.BLERadio() a = SolicitServicesAdvertisement() a.solicited_services.append(AppleMediaService) radio.start_advertising(a) while not radio.connected and not self._has_timed_out(start, timeout): pass self._status_update("AppleMediaService: Connected") for connection in radio.connections: if not connection.paired: connection.pair() self._status_update("AppleMediaService: Paired") self.ams = connection[AppleMediaService] return radio
import time import board import adafruit_ble from adafruit_ble.advertising.standard import SolicitServicesAdvertisement from adafruit_ble_apple_media import AppleMediaService from adafruit_ble_apple_media import UnsupportedCommand from adafruit_clue import clue import displayio from adafruit_bitmap_font import bitmap_font from adafruit_display_shapes.rect import Rect from adafruit_display_text import label # PyLint can't find BLERadio for some reason so special case it here. radio = adafruit_ble.BLERadio() # pylint: disable=no-member a = SolicitServicesAdvertisement() a.solicited_services.append(AppleMediaService) radio.start_advertising(a) while not radio.connected: pass print("connected") known_notifications = set() i = 0 if radio.connected: for connection in radio.connections: if not connection.paired: connection.pair()
# 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)
serv_env_sense = EnvironmentalSensingService() 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()
def check_timeout(self): 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)
""" 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: