Skip to content

Commit 0b0c45a

Browse files
authored
Merge pull request #155 from adafruit/tannewt-patch-1
Add Device Info Service example
2 parents 630b949 + d60b45a commit 0b0c45a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

examples/ble_device_info_service.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# SPDX-FileCopyrightText: 2022 Scott Shawcroft for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
This example does a generic connectable advertisement and prints out the
6+
manufacturer and model number of the device(s) that connect to it.
7+
"""
8+
9+
import time
10+
import adafruit_ble
11+
from adafruit_ble.advertising.standard import Advertisement
12+
from adafruit_ble.services.standard.device_info import DeviceInfoService
13+
14+
radio = adafruit_ble.BLERadio()
15+
a = Advertisement()
16+
a.connectable = True
17+
radio.start_advertising(a)
18+
19+
# Info that the other device can read about us.
20+
my_info = DeviceInfoService(manufacturer="CircuitPython.org", model_number="1234")
21+
22+
print("advertising")
23+
24+
while not radio.connected:
25+
pass
26+
27+
print("connected")
28+
29+
while radio.connected:
30+
for connection in radio.connections:
31+
if not connection.paired:
32+
connection.pair()
33+
print("paired")
34+
dis = connection[DeviceInfoService]
35+
print(dis.manufacturer)
36+
print(dis.model_number)
37+
time.sleep(60)
38+
39+
print("disconnected")

0 commit comments

Comments
 (0)