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

[Bug] GATT operation failed for unknown reasons. with Spike Prime Hub #740

Closed
davidwu226 opened this issue Oct 19, 2022 · 17 comments
Closed
Labels
bug Something isn't working OS: macOS Issues that only occur on macOS topic: bluetooth Issues involving bluetooth

Comments

@davidwu226
Copy link

Describe the bug
After upgrading pybricks-micropython to b83536e69693e64e312343ec6b9a79c513fdc24f, when I try to use bluetooth to connect on code, I get an error GATT operation failed for unknown reason. The previous commit at ed2e5849f52211f0e3e98d269e861c4fb08752c2 seems to work fine.

To reproduce
Steps to reproduce the behavior:

  1. Check out pybricks-micropython at b83536e69693e64e312343ec6b9a79c513fdc24f
  2. Deploy to Spike Prime Hub.
  3. Go to beta.pybricks.com and connect via Bluetooth.
  4. See error.

Expected behavior
The editor should have connected to the hub via bluetooth.

Screenshots
Screen Shot 2022-10-19 at 4 41 41 PM

@davidwu226 davidwu226 added the triage Issues that have not been triaged yet label Oct 19, 2022
@dlech
Copy link
Member

dlech commented Oct 20, 2022

What operating system are you using? Can you click the Copy Error Message button and paste the error here so we can see the full error?

@dlech dlech added the topic: bluetooth Issues involving bluetooth label Oct 20, 2022
@davidwu226
Copy link
Author

I'm on Mac OSX 12.4 (M1-based) with Chrome 106.0.5249.119.

Here's from the copy error message:

GATT operation failed for unknown reason.

@dlech dlech added OS: macOS Issues that only occur on macOS bug Something isn't working and removed triage Issues that have not been triaged yet labels Oct 20, 2022
@laurensvalk
Copy link
Member

Check out pybricks-micropython at pybricks/pybricks-micropython@b83536e

This is in the middle of big revisions to the Bluetooth code.

Before digging into this, you may want to try:

  • pybricks/pybricks-micropython@0aeb8bf: This is just before we started revising bluetooth extensively. This will still work with beta.pybricks.com as it is today.
  • pybricks/pybricks-micropython@7d7434f: This is the latest version on the master branch. This completes the Bluetooth revisions but it is not yet compatible with beta.pybricks.com. This should come in a week or two when we release the next beta version.

@davidwu226
Copy link
Author

davidwu226 commented Oct 20, 2022

Thanks @laurensvalk for responding so quickly! As I mentioned, the previous commit (ed2e584) worked without problems.

And yes, I did try the latest version of the master branch (which also does not work) -- that was what failed for me first so I decided to find the earliest commit that cause this to break (b83536e).

FWIW, I also tried pybricks/pybricks-micropython@b83536e against pybricks/pybricks-code@81d52db and it did not work either.

@laurensvalk
Copy link
Member

laurensvalk commented Oct 20, 2022

As I mentioned, the previous commit (ed2e584) worked without problems.

Right, anything before those Bluetooth changes is supposed to work with https://beta.pybricks.com/ up to today.

And yes, I did try the latest version of the master branch (which also does not work)

No matching Pybricks Code version was released (or even pushed) at the time, I think.

But since you are able to run Pybricks Code locally, it would be great if you want to try the latest version of the master branches of both, together.

To be specific, e.g.:

pybricks/pybricks-micropython@57efb61

with

pybricks/pybricks-code@7e726ff

I've been running those all day today. Would be great to know if the issue persists in that case.

Thanks!

@davidwu226
Copy link
Author

Just tried pybricks/pybricks-micropython@57efb61 with pybricks/pybricks-code@7e726ff still not working:

No Characteristics matching UUID c5f50003-8280-46da-89f4-6d8051e4aeef found in Service with UUID c5f50001-8280-46da-89f4-6d8051e4aeef.

@dlech
Copy link
Member

dlech commented Oct 20, 2022

Can you do a Bluetooth packet capture as described at https://bleak.readthedocs.io/en/latest/troubleshooting.html#macos while trying to connect?

We changed the layout of the GATT attributes on the device and I have a hunch that macOS may be serving up a cached attribute database instead of reading it from the hub.

@davidwu226
Copy link
Author

Sure, here's the capture from PacketLogger:

btcap.zip

@davidwu226
Copy link
Author

@dlech I think your hunch is correct.

I cleared my Bluetooth cache and it seemed to work now:

https://stackoverflow.com/questions/20553957/how-can-i-clear-the-corebluetooth-cache-on-macos

@davidwu226
Copy link
Author

Bummer... spoke too soon. Now the Bluetooth connects but the hub seems to crash and reset when I try to open up the interactive Python session.

@dlech
Copy link
Member

dlech commented Oct 20, 2022

Thanks! I'm working on a fix to use random Bluetooth addresses to avoid the caching issues.

The REPL issue is also being worked on in #741.

@laurensvalk
Copy link
Member

laurensvalk commented Oct 20, 2022

Bummer... spoke too soon. Now the Bluetooth connects but the hub seems to crash and reset when I try to open up the interactive Python session.

The REPL issue is also being worked on in #741.

REPL shouldn't currently crash, so feel free to open an issue if that persists.

@laurensvalk
Copy link
Member

Thanks for testing on the cutting edge. Hopefully it doesn't spoil your first impression of Pybricks 😅 .

@dlech
Copy link
Member

dlech commented Oct 20, 2022

Bummer... spoke too soon. Now the Bluetooth connects but the hub seems to crash and reset when I try to open up the interactive Python session.

See #744 (comment) for workaround.

@dlech
Copy link
Member

dlech commented Nov 26, 2022

It seems like this issue is resolved. Let us know if it isn't.

@dlech dlech closed this as completed Nov 26, 2022
@mrinalraghupathi
Copy link

I get the same error (randomly but not always) while running the following code on the robot inventor hub.

Mac OS: Ventura 13.2 (running Intel i5)
Chrome: Version 109.0.5414.119 (Official Build) (x86_64)

Code being run

from pybricks.hubs import InventorHub
from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch

hub = InventorHub()

hub.light.on(color=Color.RED)

wait(1000)

Error message

GATT operation failed for unknown reason.

@mrinalraghupathi
Copy link

I was making a screencast to show folks how to use pybricks at the same time. It seems the error only happens when the screencast software is also running (OBS studio).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working OS: macOS Issues that only occur on macOS topic: bluetooth Issues involving bluetooth
Projects
None yet
Development

No branches or pull requests

4 participants