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

bluepy-helper problems when passive scan is interrupted #282

Closed
beluga3858 opened this issue Jul 22, 2018 · 2 comments
Closed

bluepy-helper problems when passive scan is interrupted #282

beluga3858 opened this issue Jul 22, 2018 · 2 comments

Comments

@beluga3858
Copy link
Contributor

beluga3858 commented Jul 22, 2018

Using bluepy to passively scan for devices with manufacturer specific data (beacons, etc). Bluepy has issues if the scan is interrupted by other processes messing with the bluetooth subsystem. In my case this was another process using pygatt which by defaults resets the bluetooth stack before trying to connect by executing "sudo systemctl restart bluetooth" and "sudo hciconfig hci0 reset". Two cases:

interrupted by sudo hciconfig hci0 reset

... start a passive scan
Sent:  le on

Got: 'rsp=$mgmt code=$success\n'
Sent:  pasv

Got: 'rsp=$mgmt code=$success\n'
Got: "rsp=$stat state=$scan dst='(null) mtu=h0 sec='low\n"
Got: 'rsp=$scan addr=bE723780BBFFE type=h2 rssi=h4D flag=h0 d=b020106\n'

... Scan interrupted here by 'sudo hciconfig hci0 reset' in another process
... a little while later the scan timeout occurs
Select timeout
Sent:  pasvend

... this is the dying gasp of bluepy-helper exiting
Got: ''

... sometime later try scanning again
Sent:  le on

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/pi/mike/bluepy/test.py", line 91, in _worker
    Test._scanner.scan(10.0, passive=True)
  File "/home/pi/mike/bluepy/bluepy/btle.py", line 746, in scan
    self.start(passive=passive)
  File "/home/pi/mike/bluepy/bluepy/btle.py", line 684, in start
    self._mgmtCmd("le on")
  File "/home/pi/mike/bluepy/bluepy/btle.py", line 278, in _mgmtCmd
    self._writeCmd(cmd + '\n')
  File "/home/pi/mike/bluepy/bluepy/btle.py", line 274, in _writeCmd
    self._helper.stdin.write(cmd)
IOError: [Errno 32] Broken pipe

interrupted by sudo systemctl restart bluetooth

... start passive scan
Sent:  le on

Got: 'rsp=$mgmt code=$success\n'
Sent:  pasv

Got: 'rsp=$mgmt code=$success\n'
Got: "rsp=$stat state=$scan dst='(null) mtu=h0 sec='low\n"
Got: 'rsp=$scan addr=bE723780BBFFE type=h2 rssi=h4E flag=h0 d=b020106\n'
Got: 'rsp=$scan addr=bE723780BBFFE type=h2 rssi=h50 flag=h0 d=b020106\n'

... Scan interrupted here by 'sudo systemctl restart bluetooth' in another process
... Extraneous response 'mgmt success' huh?
Got: 'rsp=$mgmt code=$success\n'       

... sometime later try scanning again
Sent:  le on

... fails out early with no scan results
Got: "rsp=$stat state=$disc mtu=h0 sec='low\n"
Stopping  /home/pi/mike/bluepy/bluepy/bluepy-helper
@beluga3858
Copy link
Contributor Author

btle.py is starting an active scan instead of a passive scan if it receives a disconnect during passive scanning

Sent:  le on

Got: 'rsp=$mgmt code=$success\n'
Sent:  pasv

Got: 'rsp=$mgmt code=$success\n'
Got: "rsp=$stat state=$scan dst='(null) mtu=h0 sec='low\n"
Got: "rsp=$stat state=$disc mtu=h0 sec='low\n"
Sent:  scan

Fix added to pull request

IanHarvey added a commit that referenced this issue Jul 23, 2018
Merge #282: Fixes for passive scan interruption
@beluga3858
Copy link
Contributor Author

Fixed in release 1.2.0

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

1 participant