Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Nov 16, 2023 · 1 comment
Labels
Backend: WinRT Issues or PRs relating to the WinRT backend more info required Issues does not have a reproducible test case, has insufficent logs or otherwise needs more feedback

Comments

@roysiki
Copy link

roysiki commented Nov 16, 2023

  • bleak version: 0.21.1
  • Python version:3.8.10
  • Operating System: windows
    I am facing this problem of connecting to service . though it scan devices around you and make connection without any problem.. but when you try to scan services and characteristic it doesn't show .. though these services you can see on nrf app and it works there ... and when you give your uuid so you can read the specific characteristic from gatt it end up giving me error that no characteristic found

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
Copy link
Collaborator

dlech commented Nov 18, 2023

Can you enable debug logging and share the output?

@dlech dlech added Backend: WinRT Issues or PRs relating to the WinRT backend more info required Issues does not have a reproducible test case, has insufficent logs or otherwise needs more feedback labels May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend: WinRT Issues or PRs relating to the WinRT backend more info required Issues does not have a reproducible test case, has insufficent logs or otherwise needs more feedback
Projects
None yet
Development

No branches or pull requests

2 participants