Created
February 18, 2024 23:43
-
-
Save av1d/b39c6ee5bdc4fd5669fa35597c509481 to your computer and use it in GitHub Desktop.
List all Bluetooth LE (BLE) services and properties of a device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bluepy.btle import Peripheral, UUID | |
device_address = "00:00:00:00:00:00" | |
peripheral = Peripheral(device_address, addrType='random') | |
services = peripheral.getServices() | |
for service in services: | |
characteristics = service.getCharacteristics() | |
for char in characteristics: | |
char_handle = char.getHandle() | |
char_uuid = char.uuid | |
char_props = char.propertiesToString() | |
try: | |
char_value = char.read() | |
except Exception as e: | |
print(f"Error reading value for characteristic {char_uuid}: {e}\n") | |
char_value = None | |
print("Characteristic UUID:", char_uuid) | |
print("Handle:", char_handle) | |
print("Properties:", char_props) | |
if char_value: | |
print("Value:", ":".join("{:02x}".format(x) for x in char_value)) | |
else: | |
print("Value: Not readable") | |
print() | |
peripheral.disconnect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment