sysofwan / ha-triones

Home Assistant integration for BLE based Triones/HappyLighting lights
MIT License
50 stars 22 forks source link

Write characteristic UUID not found #3

Open Colorado4Wheeler opened 2 years ago

Colorado4Wheeler commented 2 years ago

I also detailed this on your announcement post on HASS forums.

The light gets detected but then when you select the light it refuses to connect to it and add it to HA.

2021-11-21 16:17:52 ERROR (MainThread) [custom_components.triones] Error getting status: Characteristic with UUID 0000ffd4-0000-1000-8000-00805f9b34fb could not be found!
2021-11-21 16:17:52 DEBUG (MainThread) [custom_components.triones] Traceback (most recent call last):
  File "/config/custom_components/triones/triones.py", line 73, in update
    await self._device.start_notify(R_CHARACTERISTIC_UUID, create_status_callback(future))
  File "/usr/local/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 915, in start_notify
    raise BleakError(
bleak.exc.BleakError: Characteristic with UUID 0000ffd4-0000-1000-8000-00805f9b34fb could not be found!

2021-11-21 16:17:52 DEBUG (MainThread) [custom_components.triones]  cc 23 33
sysofwan commented 2 years ago

Thanks for reporting and the helpful error log. I have an idea on fixing this, but it might take some time. I assumed that the characteristic UUID is the same for all Triones. Apparently not, so the implementation needs to query for the characteristics UUIDs first.

sysofwan commented 2 years ago

I did more digging into this. I think the implementation correctly follows this protocol.

It is possible that your device is using different UUIDs. Can you connect to your device using a BLE debug app (such as this) and share the service and characteristic UUID it exposes?

sysofwan commented 2 years ago

Found more characteristic UUIDs from another open source Triones implementation.

Do try the latest code if it fixes the issue. Otherwise, I will need you to do BLE scanning of your device the find the necessary UUIDs.

claudiocn commented 2 years ago
This error originated from a custom integration.

Logger: custom_components.triones
Source: custom_components/triones/triones.py:101
Integration: Triones (documentation, issues)
First occurred: 15:06:06 (3 occurrences)
Last logged: 15:06:13

Error getting status: [org.bluez.Error.Failed] Software caused connection abort

Have the same problem, too. To give some context, it was this one: https://pt.aliexpress.com/item/33002886875.html

sysofwan commented 2 years ago

@claudiocn this looks like a different error. Please enable debugging for full error trace.

claudiocn commented 2 years ago

here it is:

2021-12-08 16:27:49 ERROR (MainThread) [custom_components.triones] Error getting status: [org.bluez.Error.Failed] Software caused connection abort
2021-12-08 16:27:49 DEBUG (MainThread) [custom_components.triones] Traceback (most recent call last):
File "/home/homeassistant/.homeassistant/custom_components/triones/triones.py", line 69, in update
await self._device.connect(timeout=20)
File "/srv/homeassistant/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 278, in connect
assert_reply(reply)
File "/srv/homeassistant/lib/python3.9/site-packages/bleak/backends/bluezdbus/utils.py", line 23, in assert_reply
raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] Software caused connection abort
2021-12-08 16:27:49 DEBUG (MainThread) [custom_components.triones] cc 23 33
claudiocn commented 2 years ago

Seems to be a timeout, don't know why :\

sysofwan commented 2 years ago

@claudiocn this is common. See this issue. It is a BLE connection issue that will self recover. The debug log “cc 23 e3” shows that it successfully recovered and sent a BLE message.

I will make an update to the logs to make it clearer.

claudiocn commented 2 years ago

But the problem is: it doesn't connect at all when setupping.

Just to give a try, tested with the following tool and it worked perfectly: https://github.com/vinceroti/bt-triones

sysofwan commented 2 years ago

Oh, so it never finish setup. The library you tested is using your browser’s (local) Bluetooth hardware, not Home Assistant’s.

For troubleshooting:

  1. Make sure no other device is connected to the light. It will refuse connection otherwise.
  2. Retry a few times. I do see this error intermittently, but it usually goes away after a few times.
claudiocn commented 2 years ago

Disconnected from the other library. Didn't work. Turned it off and on again. Didn't work. Retried a couple of times and nothing.

2021-12-08 17:05:57 ERROR (MainThread) [custom_components.triones] No supported read/write UUIDs found
2021-12-08 17:05:57 DEBUG (MainThread) [custom_components.triones] cc 23 33
2021-12-08 17:06:06 ERROR (MainThread) [custom_components.triones] No supported read/write UUIDs found
2021-12-08 17:06:06 DEBUG (MainThread) [custom_components.triones] cc 23 33
2021-12-08 17:06:13 ERROR (MainThread) [custom_components.triones] No supported read/write UUIDs found
2021-12-08 17:06:13 DEBUG (MainThread) [custom_components.triones] cc 23 33
2021-12-08 17:07:12 ERROR (MainThread) [custom_components.triones] Error getting status: Device with address FF:FF:CD:02:EE:19 could not be found. Try increasing `timeout` value or moving the device closer.
2021-12-08 17:07:12 DEBUG (MainThread) [custom_components.triones] Traceback (most recent call last):
File "/home/homeassistant/.homeassistant/custom_components/triones/triones.py", line 69, in update
await self._device.connect(timeout=20)
File "/srv/homeassistant/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 216, in connect
raise BleakError(
bleak.exc.BleakError: Device with address FF:FF:CD:02:EE:19 could not be found. Try increasing `timeout` value or moving the device closer.
2021-12-08 17:07:12 DEBUG (MainThread) [custom_components.triones] cc 23 33
sysofwan commented 2 years ago

Thanks, this is have better logs and is the same issue here. No supported read/write UUIDs found means that the read UUID for your device is not known. Unfortunately, Triones uses many different UUIDs.

The test tool you used will only do writes to your device, but not reads (it does not know the current device state). The missing UUID here is for reads.

Can you help do this:

It is possible that your device is using different UUIDs. Can you connect to your device using a BLE debug app (such as this) and share the service and characteristic UUID it exposes?

claudiocn commented 2 years ago

image

claudiocn commented 2 years ago

From what I see, it's doing a match, it's a known UUID :\

image

sysofwan commented 2 years ago

Yeah, it’s weird. I’ll add some more debug logs later to figure this out.

claudiocn commented 2 years ago

Well, using it directly through the gatttool tool, did the following commands and using the source code in the bt-triones to get the values to be sent, did the following and it's working perfectly from the RPi from where I'm using Home Assistant:

values come from here (from bt-triones source code): image image image

sysofwan commented 2 years ago

Can you add logs to the triones.py:72 uuid detection code to see why it’s not finding the uuid?

You can modify the code inside config/custom_components/triones folder, and restart HA afterwards.

claudiocn commented 2 years ago

It seems to be empty.

2021-12-08 20:00:01 INFO (MainThread) [custom_components.triones] {}
2021-12-08 20:00:01 ERROR (MainThread) [custom_components.triones] No supported read/write UUIDs found
2021-12-08 20:00:01 DEBUG (MainThread) [custom_components.triones] cc 23 33

image

sysofwan commented 2 years ago

Try logging self._device.services.characteristics.values() instead

claudiocn commented 2 years ago
                LOGGER.info(self._device)
                LOGGER.info(self._device.services)
                LOGGER.info(self._device.services.characteristics.values())
2021-12-08 20:06:01 INFO (MainThread) [custom_components.triones] BleakClientBlueZDBus, FF:FF:CD:02:EE:19
2021-12-08 20:06:01 INFO (MainThread) [custom_components.triones] <bleak.backends.service.BleakGATTServiceCollection object at 0x7f4a0c90d0>
2021-12-08 20:06:01 INFO (MainThread) [custom_components.triones] dict_values([])
sysofwan commented 2 years ago

Not sure why the library is not detecting any characteristics. You can check if it detects it if we go through each service. Sample code here.

Meanwhile, you can hardcode the uuid in code too as a workaround. Just set self._write_uuid and self._read_uuid in the __init__ method in triones.py.

claudiocn commented 2 years ago

Did some digging with that sample code. the list of services is empty. Can't do a ".values()" but printing for each loop returns zero iterations. Really strange.

Probably because of that, even if I put the UUID, it doesn't work:

2021-12-08 20:59:23 DEBUG (MainThread) [custom_components.triones] Traceback (most recent call last):
File "/home/homeassistant/.homeassistant/custom_components/triones/triones.py", line 90, in update
await self._device.start_notify(self._read_uuid, create_status_callback(future))
File "/srv/homeassistant/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 915, in start_notify
raise BleakError(
bleak.exc.BleakError: Characteristic with UUID 0000ffd9-0000-1000-8000-00805f9b34fb could not be found!
2021-12-08 20:59:23 DEBUG (MainThread) [custom_components.triones] cc 23 33
claudiocn commented 2 years ago

Not sure if this is useful, but here's some additional information:

pi@raspberrypi:~ $ gatttool -i hci0 -b FF:FF:CD:02:EE:19 --characteristics
Discover all characteristics failed: Request attribute has encountered an unlikely error
pi@raspberrypi:~ $ gatttool -i hci0 -b FF:FF:CD:02:EE:19 --primary
attr handle = 0x0001, end grp handle = 0x0004 uuid: 0000ffd0-0000-1000-8000-00805f9b34fb
attr handle = 0x0005, end grp handle = 0x0007 uuid: 0000ffd5-0000-1000-8000-00805f9b34fb
pi@raspberrypi:~ $ gatttool -i hci0 -b FF:FF:CD:02:EE:19 --char-read
A valid handle is required
pi@raspberrypi:~ $ gatttool -i hci0 -b FF:FF:CD:02:EE:19 --interactive
[FF:FF:CD:02:EE:19][LE]> exit
pi@raspberrypi:~ $ gatttool -i hci0 -b FF:FF:CD:02:EE:19 --char-desc
handle = 0x0001, uuid = 00002800-0000-1000-8000-00805f9b34fb
handle = 0x0002, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x0003, uuid = 0000ffd4-0000-1000-8000-00805f9b34fb
handle = 0x0004, uuid = 00002902-0000-1000-8000-00805f9b34fb
handle = 0x0005, uuid = 00002800-0000-1000-8000-00805f9b34fb
handle = 0x0006, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x0007, uuid = 0000ffd9-0000-1000-8000-00805f9b34fb
sysofwan commented 2 years ago

Another guess is we need to call await self._device.get_services() explicitly before querying the services in some implementation. Example here.

Can you try it?

wroblear commented 2 years ago

the same problem, No supported read/write UUIDs found I have changed UUIDs for that which I got in Bluetootk scanner app, the same, any idea? I see that there is no new information since 12.2021,

dave-code-ruiz commented 2 years ago

I create supported code repository for uuid 0000fff3-0000-1000-8000-00805f9b34fb is elk-bledom strip.

https://github.com/dave-code-ruiz/elkbledom-ha