-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathble_device_info_service.py
39 lines (30 loc) · 1.01 KB
/
ble_device_info_service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# SPDX-FileCopyrightText: 2022 Scott Shawcroft for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
This example does a generic connectable advertisement and prints out the
manufacturer and model number of the device(s) that connect to it.
"""
import time
import adafruit_ble
from adafruit_ble.advertising.standard import Advertisement
from adafruit_ble.services.standard.device_info import DeviceInfoService
radio = adafruit_ble.BLERadio()
a = Advertisement()
a.connectable = True
radio.start_advertising(a)
# Info that the other device can read about us.
my_info = DeviceInfoService(manufacturer="CircuitPython.org", model_number="1234")
print("advertising")
while not radio.connected:
pass
print("connected")
while radio.connected:
for connection in radio.connections:
if not connection.paired:
connection.pair()
print("paired")
dis = connection[DeviceInfoService]
print(dis.manufacturer)
print(dis.model_number)
time.sleep(60)
print("disconnected")