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

Adapter needs to be reset after a scan, errors instead #4

Closed
wsidl opened this issue Sep 3, 2019 · 5 comments
Closed

Adapter needs to be reset after a scan, errors instead #4

wsidl opened this issue Sep 3, 2019 · 5 comments

Comments

@wsidl
Copy link
Contributor

wsidl commented Sep 3, 2019

When running a scan for devices and the Auto Connect times out, I will try a manual connection and search with a longer timeout and will get this error:

>>> dev = d.discover(list_all=True, timeout=20)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/testble/local/lib/python2.7/site-packages/pyanova/pyanova.py", line 188, in discover
    devices = self._adapter.scan(run_as_root=True, timeout=timeout)
  File "/home/pi/testble/local/lib/python2.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 353, in scan
    raise BLEError(message)
pygatt.exceptions.BLEError: BLE adapter requires reset after a scan as root- call adapter.reset()

Maybe try performing a reset then retrying?

wsidl added a commit to wsidl/pyanova that referenced this issue Sep 3, 2019
c3V6a2Vy#4
Adding a retry loop to allow resetting the BLE adapter so it can perform another scan
@c3V6a2Vy
Copy link
Owner

c3V6a2Vy commented Sep 5, 2019

As the message suggested though, it likely that you are not running it with privileged permission (like root). You can setup password less access for HCI Tool like as suggested in the README.

Can you try running with root to see if it solves the problem?

@wsidl
Copy link
Contributor Author

wsidl commented Sep 5, 2019

That's right, it's not running as root and I shouldn't have to. So implementing the other solution the message suggested is to reset the adapter (adapter.reset()).

Having given the fix a try locally, I can easily get the scan to work multiple times without having to raise permissions.

@c3V6a2Vy
Copy link
Owner

c3V6a2Vy commented Sep 6, 2019

You are right, running it as a super user is not ideal.

I am wondering if you have to retry more than once to get it fixed or it'll always succeed after the first retry. If it always succeed maybe it should be just as easy as calling reset() after the scan without retrying many times?

I also suspect that a manual discovery right after a failed auto_connect() will always fail because of it was never reset properly. Your fix could solve both issues.

@wsidl
Copy link
Contributor Author

wsidl commented Sep 11, 2019

I've been able to get it to work consistently with a single retry. But considering how flaky these connections are, may be good to give it a couple of extra.

@c3V6a2Vy
Copy link
Owner

I did find BLE connections could be more unstable than others, even with my two devices placed still, not sure why exactly.

As a simple library the user should not be bugged by the occasional connection drop, a retry do give them a peace of mind.

Code merged and closing this issue now.

Thank you again for your time and contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants