Skip to content

Instantly share code, notes, and snippets.

@gingershaped
Created October 10, 2024 18:32
Show Gist options
  • Save gingershaped/d0336649c3da9f89775b22fcb78ea451 to your computer and use it in GitHub Desktop.
Save gingershaped/d0336649c3da9f89775b22fcb78ea451 to your computer and use it in GitHub Desktop.
# 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, ProvideServicesAdvertisement
from adafruit_ble.services.standard.device_info import DeviceInfoService
radio = adafruit_ble.BLERadio()
radio.name = "CUI"
my_info = DeviceInfoService(manufacturer="CircuitPython.org", model_number="1234")
a = ProvideServicesAdvertisement(my_info)
a.connectable = True
radio.stop_advertising()
for connection in radio.connections:
connection.disconnect()
radio.start_advertising(a)
print("advertising")
while not radio.connected:
pass
print("connected")
while radio.connected:
for connection in radio.connections:
time.sleep(1)
if not connection.paired:
connection.pair(bond=False)
print("paired")
print(connection.paired, connection.connected)
dis = connection[DeviceInfoService]
print(dis.manufacturer)
print(dis.model_number)
time.sleep(60)
print("disconnected")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment