Untitled

mail@pastecode.io avatar
unknown
python
8 days ago
1.3 kB
1
Indexable
Never
import asyncio
from bleak import BleakClient, BleakScanner

async def scan_devices():
    print("Scanning for Bluetooth devices...")
    devices = await BleakScanner.discover()
    for device in devices:
        print(f"Found device: {device.name} - {device.address}")

async def uuid_info(device_address):
    async with BleakClient(device_address) as client:
        services = client.services
        for service in services:
            #print(f"Service: {service.uuid}")
            for characteristic in service.characteristics:
                #print(f"  Characteristic: {characteristic.uuid} (Properties: {characteristic.properties})")
                UUID = characteristic.uuid
                print(UUID)
                
                text = device_address +","+ UUID
                with open("BTinfo.txt", "w")as file:
                    file.write(text)

async def all_combined():
    await scan_devices()
    device_address = input("Device Address = ")
    await uuid_info(device_address)
    #write_uuid = input("Write UUID = ") #2
    #read_uuid = input("Read,Write,Notify,Indicate UUID = ") #1
    
    #text = device_address +","+ write_uuid +","+ read_uuid
    #with open("BTinfo.txt", "w")as file:
        #file.write(text)

asyncio.run(all_combined())
Leave a Comment