hbldh / bleak

A cross platform Bluetooth Low Energy Client for Python using asyncio
MIT License
1.6k stars 280 forks source link

Cannot identify how to fetch an updated device name after connection #1484

Closed coderjoe closed 5 months ago

coderjoe commented 5 months ago

Description

I am working with a device that advertises under one device name, but upon successful connection and protocol negotiation it changes its device name to another name.

The mobile app I'm trying to emulate appears to make a second request to the Generic Access Service (0x1800) for Device Name (0x2a00). Unfortunately bleak does not appear to expose that service so I cannot make my own requests.

Per closed issue #250 I believe it was said that this data was wrapped up in the BLEDevice, but I am not sure how to get the updated device name once I have connected.

My debug logs show that DBus picks up the property change, but I do not know how to fetch the updated property.

What I Did

I am emulating the android application by performing a bluetooth device scan and looking for advertised devices by either a known address or product name.

Once connected, I listen for device updates on its RX characteristic, and perform a connection negotiation by sending a vendor specific command over its TX characteristic.

However the device name never gets updated even though bluez reports the correct change.

At timestamp 2023-12-25 15:18:28 the device.name output is HPA250B which is the advertised device name At timestamp 2023-12-25 15:18:28,936 output in the logs bluez reports the property change to the new name of HEPA 250 JB

But I cannot figure out how to reference this updated name in bleak.

import argparse
import asyncio
import logging

from uuid import UUID
from bleak import BleakClient, BleakScanner
from bleak.backends.characteristic import BleakGATTCharacteristic

logger = logging.getLogger(__name__)

address = "f4:5e:ab:bb:a8:94"
RX_UUID = UUID('{0000ffe4-0000-1000-8000-00805f9b34fb}')
TX_UUID = UUID('{0000ffe9-0000-1000-8000-00805f9b34fb}')

def notification_handler(characteristic: BleakGATTCharacteristic, data: bytearray):
    display_data("\n\n\nNotify from device: %s", data)

async def main(args: argparse.Namespace):
    logger.info("\n\n\nstarting find...")

    device = await BleakScanner.find_device_by_address(address)
    logger.info("\n\n\nDevice: %s", device)
    logger.info("\n\n\nDevice Details: %s", device.details)

    if device == None:
        logger.error("Could not find a matching device. Aborting...")
        return

    logger.info("\n\n\nconnecting to device...")

    async with BleakClient(device) as client:
        logger.info("\n\n\nConnected to address %s!", client.address)
        await client.start_notify(RX_UUID, notification_handler)

        mac_cmd = b'MAC+\xf4\x5e\xab\xbb\xa8\x94'
        logger.info("\n\n\nSending MAC Command: %s", mac_cmd)
        await client.write_gatt_char(TX_UUID, mac_cmd)

        await asyncio.sleep(10)
        logger.info("\n\n\nDevice: %s", device)
        logger.info("\n\n\nDevice Details: %s", device.details)

def display_data(msg: str, data: bytearray):
    logger.info(msg, ' '.join(list(map(lambda x: format(x,'02x'), data))))

if __name__ == "__main__":
    parser = argparse.ArgumentParser()

    parser.add_argument(
        "-d",
        "--debug",
        action="store_true",
        help="sets the log level to debug"
    )

    args = parser.parse_args()
    log_level = logging.DEBUG if args.debug else logging.INFO
    logging.basicConfig(
        level = log_level,
        format="%(asctime)-15s %(name)-8s %(levelname)s: %(message)s",
    )

    asyncio.run(main(args))
% python3 scanner.py -d
2023-12-25 15:18:28,205 asyncio  DEBUG: Using selector: EpollSelector
2023-12-25 15:18:28,206 __main__ INFO: 

starting find...
2023-12-25 15:18:28,225 bleak.backends.bluezdbus.manager DEBUG: initial properties: {'/org/bluez': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.AgentManager1': {}, 'org.bluez.ProfileManager1': {}}, '/org/bluez/hci0': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.Adapter1': {'Address': '9C:B6:D0:C1:FD:1C', 'AddressType': 'public', 'Name': 'computer', 'Alias': 'computer', 'Class': 8126732, 'Powered': True, 'Discoverable': False, 'DiscoverableTimeout': 60, 'Pairable': True, 'PairableTimeout': 0, 'Discovering': False, 'UUIDs': ['00001133-0000-1000-8000-00805f9b34fb', '0000110e-0000-1000-8000-00805f9b34fb', '00001105-0000-1000-8000-00805f9b34fb', '00001132-0000-1000-8000-00805f9b34fb', '00001200-0000-1000-8000-00805f9b34fb', '00001104-0000-1000-8000-00805f9b34fb', '00005005-0000-1000-8000-0002ee000001', '00001108-0000-1000-8000-00805f9b34fb', '0000110c-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb', '0000112f-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', '0000110b-0000-1000-8000-00805f9b34fb', '00001800-0000-1000-8000-00805f9b34fb', '0000111f-0000-1000-8000-00805f9b34fb', '0000110a-0000-1000-8000-00805f9b34fb', '00001106-0000-1000-8000-00805f9b34fb'], 'Modalias': 'usb:v1D6Bp0246d0540', 'Roles': ['central', 'peripheral']}, 'org.freedesktop.DBus.Properties': {}, 'org.bluez.GattManager1': {}, 'org.bluez.Media1': {}, 'org.bluez.NetworkServer1': {}, 'org.bluez.LEAdvertisingManager1': {'ActiveInstances': 0, 'SupportedInstances': 5, 'SupportedIncludes': ['appearance', 'local-name']}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.Device1': {'Address': 'F4:5E:AB:BB:A8:94', 'AddressType': 'public', 'Name': 'HEPA 250 JB', 'Alias': 'HEPA 250 JB', 'Paired': False, 'Trusted': True, 'Blocked': False, 'LegacyPairing': False, 'Connected': False, 'UUIDs': ['00001800-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', '0000fff0-0000-1000-8000-00805f9b34fb'], 'Modalias': 'bluetooth:v000Dp0000d0110', 'Adapter': '/org/bluez/hci0', 'ServicesResolved': False}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattService1': {'UUID': '0000fff0-0000-1000-8000-00805f9b34fb', 'Device': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94', 'Primary': True, 'Includes': []}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char0031': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '0000fff5-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023', 'Value': bytearray(b'\x05\x00\x00\x00\x00'), 'Flags': ['read']}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char0031/desc0033': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattDescriptor1': {'UUID': '00002901-0000-1000-8000-00805f9b34fb', 'Characteristic': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char0031', 'Value': bytearray(b'')}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char002d': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '0000ffe4-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023', 'Value': bytearray(b'\xa5\x00\x00\x00 \x00\x00\x91@\x86@\x00\x00\t\x00\x17;\x00\x00'), 'Notifying': False, 'Flags': ['read', 'notify'], 'NotifyAcquired': False}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char002d/desc0030': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattDescriptor1': {'UUID': '00002901-0000-1000-8000-00805f9b34fb', 'Characteristic': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char002d', 'Value': bytearray(b'')}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char002d/desc002f': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattDescriptor1': {'UUID': '00002902-0000-1000-8000-00805f9b34fb', 'Characteristic': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char002d', 'Value': bytearray(b'')}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char002a': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '0000fff3-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023', 'Value': bytearray(b''), 'Flags': ['write']}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char002a/desc002c': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattDescriptor1': {'UUID': '00002901-0000-1000-8000-00805f9b34fb', 'Characteristic': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char002a', 'Value': bytearray(b'')}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char0027': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '0000fff2-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023', 'Value': bytearray(b'\x02'), 'Flags': ['read']}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char0027/desc0029': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattDescriptor1': {'UUID': '00002901-0000-1000-8000-00805f9b34fb', 'Characteristic': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char0027', 'Value': bytearray(b'')}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char0024': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '0000ffe9-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023', 'Value': bytearray(b'\xa5\x00\x00-\x06Q\x00F\x00\x00\x00\t\x00\x17;\x00\x00d\x00\x00'), 'Flags': ['read', 'write']}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char0024/desc0026': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattDescriptor1': {'UUID': '00002901-0000-1000-8000-00805f9b34fb', 'Characteristic': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char0024', 'Value': bytearray(b'')}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattService1': {'UUID': '0000180a-0000-1000-8000-00805f9b34fb', 'Device': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94', 'Primary': True, 'Includes': []}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010/char0021': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '00002a50-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010', 'Value': bytearray(b'\x01\r\x00\x00\x00\x10\x01'), 'Flags': ['read']}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010/char001f': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '00002a2a-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010', 'Value': bytearray(b'\xfe\x00experimental'), 'Flags': ['read']}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010/char001d': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '00002a29-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010', 'Value': bytearray(b'Manufacturer Name\x00'), 'Flags': ['read']}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010/char001b': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '00002a28-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010', 'Value': bytearray(b'Software Revision\x00'), 'Flags': ['read']}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010/char0019': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '00002a27-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010', 'Value': bytearray(b'Hardware Revision\x00'), 'Flags': ['read']}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010/char0017': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '00002a26-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010', 'Value': bytearray(b'Firmware Revision\x00'), 'Flags': ['read']}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010/char0015': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '00002a25-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010', 'Value': bytearray(b'Serial Number\x00'), 'Flags': ['read']}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010/char0013': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '00002a24-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010', 'Value': bytearray(b'Model Number\x00'), 'Flags': ['read']}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010/char0011': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '00002a23-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0010', 'Value': bytearray(b'\x94\xa8\xbb\x00\x00\xab^\xf4'), 'Flags': ['read']}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service000c': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattService1': {'UUID': '00001801-0000-1000-8000-00805f9b34fb', 'Device': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94', 'Primary': True, 'Includes': []}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service000c/char000d': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': '00002a05-0000-1000-8000-00805f9b34fb', 'Service': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service000c', 'Value': bytearray(b''), 'Notifying': False, 'Flags': ['indicate']}, 'org.freedesktop.DBus.Properties': {}}, '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service000c/char000d/desc000f': {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattDescriptor1': {'UUID': '00002902-0000-1000-8000-00805f9b34fb', 'Characteristic': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service000c/char000d', 'Value': bytearray(b'')}, 'org.freedesktop.DBus.Properties': {}}}
2023-12-25 15:18:28,232 bleak.backends.bluezdbus.manager DEBUG: received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0): ['org.bluez.Adapter1', {'Discovering': <dbus_fast.signature.Variant ('b', True)>}, []]
2023-12-25 15:18:28,353 bleak.backends.bluezdbus.manager DEBUG: received D-Bus signal: org.freedesktop.DBus.ObjectManager.InterfacesAdded (/): ['/org/bluez/hci0/dev_53_56_14_AA_5E_24', {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.Device1': {'Address': <dbus_fast.signature.Variant ('s', 53:56:14:AA:5E:24)>, 'AddressType': <dbus_fast.signature.Variant ('s', random)>, 'Alias': <dbus_fast.signature.Variant ('s', 53-56-14-AA-5E-24)>, 'Paired': <dbus_fast.signature.Variant ('b', False)>, 'Trusted': <dbus_fast.signature.Variant ('b', False)>, 'Blocked': <dbus_fast.signature.Variant ('b', False)>, 'LegacyPairing': <dbus_fast.signature.Variant ('b', False)>, 'RSSI': <dbus_fast.signature.Variant ('n', -69)>, 'Connected': <dbus_fast.signature.Variant ('b', False)>, 'UUIDs': <dbus_fast.signature.Variant ('as', ['0000fe9f-0000-1000-8000-00805f9b34fb'])>, 'Adapter': <dbus_fast.signature.Variant ('o', /org/bluez/hci0)>, 'ServiceData': <dbus_fast.signature.Variant ('a{sv}', {'0000fe9f-0000-1000-8000-00805f9b34fb': <dbus_fast.signature.Variant ('ay', bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'))>})>, 'ServicesResolved': <dbus_fast.signature.Variant ('b', False)>}, 'org.freedesktop.DBus.Properties': {}}]
2023-12-25 15:18:28,359 bleak.backends.bluezdbus.manager DEBUG: received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94): ['org.bluez.Device1', {'RSSI': <dbus_fast.signature.Variant ('n', -48)>, 'TxPower': <dbus_fast.signature.Variant ('n', 0)>, 'Name': <dbus_fast.signature.Variant ('s', HPA250B)>, 'Alias': <dbus_fast.signature.Variant ('s', HPA250B)>}, []]
2023-12-25 15:18:28,363 bleak.backends.bluezdbus.manager DEBUG: received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_53_56_14_AA_5E_24): ['org.bluez.Device1', {}, ['RSSI']]
2023-12-25 15:18:28,363 bleak.backends.bluezdbus.manager DEBUG: received D-Bus signal: org.freedesktop.DBus.ObjectManager.InterfacesRemoved (/): ['/org/bluez/hci0/dev_53_56_14_AA_5E_24', ['org.freedesktop.DBus.Properties', 'org.freedesktop.DBus.Introspectable', 'org.bluez.Device1']]
2023-12-25 15:18:28,363 bleak.backends.bluezdbus.manager DEBUG: received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94): ['org.bluez.Device1', {}, ['TxPower', 'RSSI']]
2023-12-25 15:18:28,364 bleak.backends.bluezdbus.manager DEBUG: received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0): ['org.bluez.Adapter1', {'Discovering': <dbus_fast.signature.Variant ('b', False)>}, []]
2023-12-25 15:18:28,364 __main__ INFO: 

Device: F4:5E:AB:BB:A8:94: HPA250B
2023-12-25 15:18:28,364 __main__ INFO: 

Device Details: {'path': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94', 'props': {'Address': 'F4:5E:AB:BB:A8:94', 'AddressType': 'public', 'Name': 'HPA250B', 'Alias': 'HPA250B', 'Paired': False, 'Trusted': True, 'Blocked': False, 'LegacyPairing': False, 'Connected': False, 'UUIDs': ['00001800-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', '0000fff0-0000-1000-8000-00805f9b34fb'], 'Modalias': 'bluetooth:v000Dp0000d0110', 'Adapter': '/org/bluez/hci0', 'ServicesResolved': False, 'RSSI': -48, 'TxPower': 0}}
2023-12-25 15:18:28,364 __main__ INFO: 

connecting to device...
2023-12-25 15:18:28,365 bleak.backends.bluezdbus.client DEBUG: Connecting to device @ F4:5E:AB:BB:A8:94
2023-12-25 15:18:28,368 bleak.backends.bluezdbus.client DEBUG: Connecting to BlueZ path /org/bluez/hci0/dev_F4_5E_AB_BB_A8_94
2023-12-25 15:18:28,670 bleak.backends.bluezdbus.manager DEBUG: received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94): ['org.bluez.Device1', {'Connected': <dbus_fast.signature.Variant ('b', True)>}, []]
2023-12-25 15:18:28,936 bleak.backends.bluezdbus.manager DEBUG: received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94): ['org.bluez.Device1', {'Name': <dbus_fast.signature.Variant ('s', HEPA 250 JB)>, 'Alias': <dbus_fast.signature.Variant ('s', HEPA 250 JB)>}, []]
2023-12-25 15:18:29,393 bleak.backends.bluezdbus.manager DEBUG: received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94): ['org.bluez.Device1', {'ServicesResolved': <dbus_fast.signature.Variant ('b', True)>}, []]
2023-12-25 15:18:29,394 __main__ INFO: 

Connected to address F4:5E:AB:BB:A8:94!
2023-12-25 15:18:29,560 bleak.backends.bluezdbus.manager DEBUG: received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char002d): ['org.bluez.GattCharacteristic1', {'Notifying': <dbus_fast.signature.Variant ('b', True)>}, []]
2023-12-25 15:18:29,561 __main__ INFO: 

Sending MAC Command: b'MAC+\xf4^\xab\xbb\xa8\x94'
2023-12-25 15:18:29,649 bleak.backends.bluezdbus.client DEBUG: Write Characteristic 0000ffe9-0000-1000-8000-00805f9b34fb | /org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char0024: b'MAC+\xf4^\xab\xbb\xa8\x94'
2023-12-25 15:18:31,180 bleak.backends.bluezdbus.manager DEBUG: received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94/service0023/char002d): ['org.bluez.GattCharacteristic1', {'Value': <dbus_fast.signature.Variant ('ay', bytearray(b'\xa5\x00\x00\x00 \x00\x00\x91@\x86@\x00\x00\t\x00\x17;\x00\x00'))>}, []]
2023-12-25 15:18:31,181 __main__ INFO: 

Notify from device: a5 00 00 00 20 00 00 91 40 86 40 00 00 09 00 17 3b 00 00
2023-12-25 15:18:39,658 __main__ INFO: 

Device: F4:5E:AB:BB:A8:94: HPA250B
2023-12-25 15:18:39,658 __main__ INFO: 

Device Details: {'path': '/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94', 'props': {'Address': 'F4:5E:AB:BB:A8:94', 'AddressType': 'public', 'Name': 'HPA250B', 'Alias': 'HPA250B', 'Paired': False, 'Trusted': True, 'Blocked': False, 'LegacyPairing': False, 'Connected': False, 'UUIDs': ['00001800-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', '0000fff0-0000-1000-8000-00805f9b34fb'], 'Modalias': 'bluetooth:v000Dp0000d0110', 'Adapter': '/org/bluez/hci0', 'ServicesResolved': False, 'RSSI': -48, 'TxPower': 0}}
2023-12-25 15:18:39,659 bleak.backends.bluezdbus.client DEBUG: Disconnecting ({/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94})
2023-12-25 15:18:42,392 bleak.backends.bluezdbus.manager DEBUG: received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94): ['org.bluez.Device1', {'ServicesResolved': <dbus_fast.signature.Variant ('b', False)>}, []]
2023-12-25 15:18:42,393 bleak.backends.bluezdbus.manager DEBUG: received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94): ['org.bluez.Device1', {'Connected': <dbus_fast.signature.Variant ('b', False)>}, []]
2023-12-25 15:18:42,393 bleak.backends.bluezdbus.client DEBUG: Device disconnected (/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94)
2023-12-25 15:18:42,393 bleak.backends.bluezdbus.client DEBUG: _cleanup_all(/org/bluez/hci0/dev_F4_5E_AB_BB_A8_94)

Logs

See above program output for debug logs.

In particular timestamp 2023-12-25 15:18:28 for the advertised device name and timestamp 2023-12-25 15:18:28,936 for the bluez property update debug log.

coderjoe commented 5 months ago

Updated to reference the correct other issue, meant #250 not 150

dlech commented 5 months ago

You can probably read the device name characteristic. Also see https://github.com/hbldh/bleak/issues/849#issuecomment-1255370264 about a proposed enhancement for a name property on the BleakClient object.

coderjoe commented 5 months ago

Thank you @dlech I appreciate the suggestion, but I could not figure out how to query the Device Name characteristic from within bleak. Attempts to reference it by UUID give me problems as the Generic Access Service (0x1800) does not seem listed as an available service.

Is there some other way to query it without being able to find the service via bleak?

coderjoe commented 5 months ago

Ok no - the problem was on my end, the format of the UUID I was passing was valid for the UUID library, but a typo in my code had it being interpreted as a string. As a result the error

bleak.exc.BleakError: Characteristic with UUID {00002a00-0000-1000-8000-00805f9b34fb} could not be found!

Had me believing that I could not read that characteristic. That was wrongminded - it works fine when I create my UUID properly.

My mistake - thank you for your suggestion as it eventually lead me to the correct solution!