Simple test
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""
5This example solicits that apple devices that provide notifications connect to it, initiates
6pairing, prints existing notifications and then prints any new ones as they arrive.
7"""
8
9import time
10import adafruit_ble
11from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
12from adafruit_ble_apple_media import AppleMediaService
13
14# PyLint can't find BLERadio for some reason so special case it here.
15radio = adafruit_ble.BLERadio() # pylint: disable=no-member
16a = SolicitServicesAdvertisement()
17a.solicited_services.append(AppleMediaService)
18radio.start_advertising(a)
19
20while not radio.connected:
21 pass
22
23print("connected")
24
25known_notifications = set()
26
27i = 0
28while radio.connected:
29 for connection in radio.connections:
30 if not connection.paired:
31 connection.pair()
32 print("paired")
33
34 ams = connection[AppleMediaService]
35 print("App:", ams.player_name)
36 print("Title:", ams.title)
37 print("Album:", ams.album)
38 print("Artist:", ams.artist)
39 if ams.playing:
40 print("Playing")
41 elif ams.paused:
42 print("Paused")
43
44 if i > 3:
45 ams.toggle_play_pause()
46 i = 0
47 print()
48 time.sleep(3)
49 i += 1
50
51print("disconnected")