dlech / bleak-winrt

Python binding for WinRT for Bleak
https://pypi.org/project/bleak-winrt
MIT License
10 stars 3 forks source link

Response is always "None" when trying to write into a writable characteristic #3

Closed dimonoid closed 2 years ago

dimonoid commented 2 years ago

Windows 11 Pro, OS build 22000.675, bleak~=0.14.3, Bleak-winrt version~=1.1.1

Unable to write into a characteristic, but reading and notifications work fine

I checked through BLE Scanner on Android and BleuIO, writing works fine both ways, so there is an issue with Bleak or WinRT. Device is not receiving anything (I monitor through COM port)

I tried older versions of Bleak-winrt, getting the same error.

Here is a piece of code:

a = await self.client.get_services()
                                  for c in a.characteristics.values():
                                    try:
                                        b = await self.client.write_gatt_char(c, B"123ABC")  # Issue is in here
                                        print(b)
                                    except Exception as e:
                                        print("Test error 2:", e)
                                        if "Access Denied" not in str(e):
                                            print("Have a look!", e)
                                    await asyncio.sleep(0.1)
dlech commented 2 years ago

This looks like you are using Bleak rather than using bleak-winrt directly, so you should post issues at https://github.com/hbldh/bleak instead. Even better, use https://github.com/hbldh/bleak/discussions instead of issues unless you are 90% certain there is a bug in Bleak.

It also looks like you are trying to write to every single characteristic on the device, but not all characteristics can be written, so you get an error. Just pick one characteristic and write to it.

dimonoid commented 2 years ago

Correct, I try to write to all of them, but none of them are successful. Error is always the same, "Access Denied" to ones which don't have writing properties, but returns successfully "None" for properties which should be writable.

But absolutely nothing goes through to the device.

dimonoid commented 2 years ago

Solved

I had to use "response=True", otherwise remote device wasn't receiving anything for some reason (even though I don't need confirmation that write request is successful). Also activated response on device side.

Related: https://github.com/hbldh/bleak/issues/59