So suppose i have a device whose mac address i already have, and is connected to my laptop, I want to get its information (metadata), without scanning if possible as device doesnt show up while scanning but is connected to my laptop,
`import asyncio
from bleak import BleakClient
Replace with the MAC address of your Bluetooth device
MAC_ADDRESS = “XX:XX:XX:XX:XX:XX”
async def get_device_info(mac_address):
async with BleakClient(mac_address) as client:
if client.is_connected:
print(f”Connected to {mac_address}”)
# List all services and characteristics
services = await client.get_services()
for service in services:
print(f"Service: {service.uuid}")
for characteristic in service.characteristics:
print(f" Characteristic: {characteristic.uuid}")
if "read" in characteristic.properties:
try:
value = await client.read_gatt_char(characteristic.uuid)
print(f" Value: {value}")
except Exception as e:
print(f" Failed to read characteristic: {e}")
else:
print(f"Failed to connect to {mac_address}")
loop = asyncio.get_event_loop()
loop.run_until_complete(get_device_info(MAC_ADDRESS))
`
This is the python code that “scans” and tells me the information but its inconsistent with the connection so if there is a way i can get the info with the already connected device on linux and windows both.
maybe some way other than python?