-
-
Save prefiks/e614116fc3983a8e7e5fe326800dc101 to your computer and use it in GitHub Desktop.
| #!/usr/bin/python3 | |
| from bluepy import btle | |
| import sys | |
| class DiscoLH(btle.DefaultDelegate): | |
| def __init__(self): | |
| self.devices = [] | |
| btle.DefaultDelegate.__init__(self) | |
| def handleDiscovery(self, dev, isNewDev, isNewData): | |
| if not isNewDev: | |
| return | |
| isLH = False | |
| name = "" | |
| if dev.getValue(btle.ScanEntry.MANUFACTURER)[0:4] == b'\x5d\x05\x00\x02': | |
| print('Found LightHouse %s: address = %s' % | |
| (dev.getValue(btle.ScanEntry.COMPLETE_LOCAL_NAME), dev.addr)) | |
| self.devices.append(dev.addr) | |
| if __name__ == '__main__': | |
| scanner = btle.Scanner() | |
| delegate = DiscoLH() | |
| scanner.withDelegate(delegate) | |
| scanner.scan(2) | |
| for device in delegate.devices: | |
| lh = btle.Peripheral() | |
| print("Connecting to %s" % (device)) | |
| lh.connect(device, addrType = btle.ADDR_TYPE_RANDOM) | |
| if len(sys.argv) > 1 and sys.argv[1] == 'on': | |
| lh.writeCharacteristic(0x12, b'\x01') | |
| else: | |
| lh.writeCharacteristic(0x12, b'\x00') | |
| lh.disconnect() |
Yes, run the command as root, or use setcap on bluepy
sudo setcap cap_net_raw+e /home/waylonflinn/.local/lib/python3.8/site-packages/bluepy/bluepy-helper
sudo setcap cap_net_admin+eip /home/waylonflinn/.local/lib/python3.8/site-packages/bluepy/bluepy-helper
Ok thanks now it doesn't make that error anymore. But looks like my lightouses don't seem to care 😢
The script exits without any error but the stations do not start
Update: just noticed the script is supposed to say when it found a lighthouse. But I'm getting no output whatsoever, so i guess it's not finding them
Hi,
Please take look at https://github.com/DavidRisch/steamvr_utils, it expnads on this script, and maybe it will work for you.
Fixed the problem, I forgot my base stations where 1.0 and not 2.0 so it would not be able to find them anyway. https://github.com/risa2000/lhctrl this is the script for 1.0 if anyone is interested
Thanks for the help :)
I know this code is really old, but has anybody had troubles with this error?
Traceback (most recent call last):File "lh.py", line 35, in <module>scanner.scan(2)File "/usr/local/lib/python3.8/dist-packages/bluepy/btle.py", line 852, in scanself.start(passive=passive)File "/usr/local/lib/python3.8/dist-packages/bluepy/btle.py", line 797, in startself._mgmtCmd(self._cmd()+"end")File "/usr/local/lib/python3.8/dist-packages/bluepy/btle.py", line 312, in _mgmtCmdraise BTLEManagementError("Failed to execute management command '%s'" % (cmd), rsp)bluepy.btle.BTLEManagementError: Failed to execute management command 'scanend' (code: 13, error: Invalid Parameters)It's a really frustrating issue, and it happens even with a different bluetooth adapter