hbldh / bleak

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

bleak isnot scanning the custom service and gives error when you try to read it .. it says Characteristic 9fb23f86-7f0a-11ee-b962-0242ac120002 was not found! #1458

Open roysiki opened 10 months ago

roysiki commented 10 months ago

plus this is the code i am using

import asyncio
from bleak import BleakScanner, BleakClient

uuid_read_level_characteristic = '9fb23f86-7f0a-11ee-b962-0242ac120002'

async def main():
    devices = await BleakScanner.discover()
    for device in devices:
        if device.name == 'RoyFunDrink':
            print("MAC ID of device: " + device.address)
            async with BleakClient(device.address) as client:
                for service in client.services:
                    print(service)
                    for ch in service.characteristics:
                        if 'notify' in ch.properties:
                            print("  ", ch, ch.properties)
                read_level = await client.read_gatt_char(uuid_read_level_characteristic)
                hex_string = ''.join(format(x, '02x') for x in read_level)
                decoded_string = bytes.fromhex(hex_string).decode('utf-8')
                print("Received data: " + decoded_string)

asyncio.run(main())

though in nrf you can see the characteristic and can read the value as well WhatsApp Image 2023-11-16 at 13 16 23

but in output i am getting this

[Running] python -u "c:\python\new_fun.py"
MAC ID of device: C2:08:51:5F:5F:C0
00001801-0000-1000-8000-00805f9b34fb (Handle: 1): Generic Attribute Profile
00001800-0000-1000-8000-00805f9b34fb (Handle: 9): Generic Access Profile
00001523-1212-efde-1523-785feabcd123 (Handle: 16): Nordic LED Button Service
   00001524-1212-efde-1523-785feabcd123 (Handle: 17): Button ['read', 'notify']
00001523-1212-efde-1523-785feabcd123 (Handle: 22): Nordic LED Button Service
8d53dc1d-1db7-4cd3-868b-8a527460aa84 (Handle: 31): SMP Service
   da2e7828-fbce-4e01-ae9e-261174997c48 (Handle: 32): SMP Characteristic ['write-without-response', 'notify']
Traceback (most recent call last):
  File "c:\python\new_fun.py", line 22, in <module>
    asyncio.run(main())
  File "C:\Users\AppData\Local\Programs\Python\Python38\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Users\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File "c:\python\new_fun.py", line 17, in main
    read_level = await client.read_gatt_char(uuid_read_level_characteristic)
  File "C:\Users\AppData\Local\Programs\Python\Python38\lib\site-packages\bleak\__init__.py", line 711, in read_gatt_char
    return await self._backend.read_gatt_char(char_specifier, **kwargs)
  File "C:\Users\AppData\Local\Programs\Python\Python38\lib\site-packages\bleak\backends\winrt\client.py", line 823, in read_gatt_char
    raise BleakError(f"Characteristic {char_specifier} was not found!")
bleak.exc.BleakError: Characteristic 9fb23f86-7f0a-11ee-b962-0242ac120002 was not found!

run simple example as well

import asyncio
from bleak import BleakClient

address = "C2:08:51:5F:5F:C0"
MODEL_NBR_UUID = "9fb23f86-7f0a-11ee-b962-0242ac120002"

async def run(address):
    async with BleakClient(address) as client:
        model_number = await client.read_gatt_char(MODEL_NBR_UUID)
        print("Model Number: {0}".format("".join(map(chr, model_number))))

loop = asyncio.get_event_loop()
loop.run_until_complete(run(address))

but still it keep saying

[Running] python -u "c:\python\new_fun.py"
Traceback (most recent call last):
  File "c:\python\new_fun.py", line 13, in <module>
    loop.run_until_complete(run(address))
  File "C:\Users\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File "c:\python\new_fun.py", line 9, in run
    model_number = await client.read_gatt_char(MODEL_NBR_UUID)
  File "C:\Users\AppData\Local\Programs\Python\Python38\lib\site-packages\bleak\__init__.py", line 711, in read_gatt_char
    return await self._backend.read_gatt_char(char_specifier, **kwargs)
  File "C:\Users\AppData\Local\Programs\Python\Python38\lib\site-packages\bleak\backends\winrt\client.py", line 823, in read_gatt_char
    raise BleakError(f"Characteristic {char_specifier} was not found!")
bleak.exc.BleakError: Characteristic 9fb23f86-7f0a-11ee-b962-0242ac120002 was not found!

[Done] exited with code=1 in 8.454 seconds
dlech commented 10 months ago

Can you enable debug logging and share the output?