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
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
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!
[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
plus this is the code i am using
though in nrf you can see the characteristic and can read the value as well
but in output i am getting this
run simple example as well
but still it keep saying