ttu / lego-boost-browser

Library for controlling Lego Boost with Web Bluetooth API
MIT License
29 stars 10 forks source link

GATT not working #5

Open mayardamaury opened 2 years ago

mayardamaury commented 2 years ago

Hi !

I've encoutered an issue trying to run your script, when I try to connect Vernie, the GATT throws a generic error. I've not been able to get where this is coming from, although I'm not very skilled regarding bluetooth connectivity (which is why I was delighted to run into this, thank you for making it opensource !)

Here's what's going on in the console

hub.ts:455 
Writing to device {data: Uint8Array(8), secondArg: true, callback: ƒ}

hub.ts:465 
Error while writing: �2Q   - Error NotSupportedError: GATT Error Unknown.

/local_url/#:1 
Uncaught (in promise) DOMException: GATT operation failed for unknown reason.

legoBoost.ts:91
handleGattDisconnect

legoBoost.ts:98
 Disconnected
2
legoBoost.ts:91 handleGattDisconnect

Here are the bluetooth log associated with the connection attempt :

[21:24:18] OnConnectionStatusChanged() status=0

[21:24:09] Unexpected GattCommunicationStatus: 1

[21:24:08] OnConnectionStatusChanged() status=1

[21:24:08] OnGattDiscoveryComplete() success=1

[21:24:08] StartGattDiscovery()

[21:24:08] No advertisement flags found.

[21:24:04] Web Bluetooth Device Chooser initiating Bluetooth discovery session

Do you have any idea of how this bug may be fixed ?

mayardamaury commented 2 years ago

update : exact same bug is encoutered on https://legoboost.azurewebsites.net/

Navigator is last version of google chrome on windows 11 so it should be bluetooth compatible. Maybe something is wrong with my configuration ?

ttu commented 2 years ago

Hi! Thanks for the issue and logs.

Unfortunately I couldn't reproduce the issue.

Tested with Google Chrome: Version 97.0.4692.71 (Language: English) OS: Windows 11 (Language: English)

What language you are using in your OS and with browser?

mayardamaury commented 2 years ago

I've noticed serious improvement, let me answer to yoru question first : The browser is just running your JS with the connect() function called from index.html and I'm running on windows 11

So, the GATT error seems to be a sync issue on attempts to write on the device. BUT, I'm not quite sure about this since simple restarting the browser a number of times allows me to connect almost without issue.

I'd say almost because once connected, I have to follow a precise step-by-step in order to be able to reconnect. The sequence is :

Reconnecting before the device turning off or without emptying caches or losing connection by any other means wil lresult in systematically getting the error above. Only solution then is to restart the navigator

So it's working but not quite stable

ttu commented 2 years ago

Thanks for the description! It seems that this is related to already known issue with disconnects. Issue: https://github.com/ttu/lego-boost-browser/issues/2

Unfortunately I haven't had time to dig into it, but thanks for the detailed steps how to reproduce the problem.