-
-
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() |
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 scan
self.start(passive=passive)
File "/usr/local/lib/python3.8/dist-packages/bluepy/btle.py", line 797, in start
self._mgmtCmd(self._cmd()+"end")
File "/usr/local/lib/python3.8/dist-packages/bluepy/btle.py", line 312, in _mgmtCmd
raise 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
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 :)
Replace the final if block with this code to toggle the lighthouse state, when no argument is specified.
That is, this change will turn the lighthouse off when it's already on, and on when it's already off.
In Ubuntu, I also put the following in a file named
lighthouse.desktop
on my desktop and click it when I want to turn them on or off. Make sure to edit the lineExec=/path/to/lh.py
with the actual path.This actually works better for me right now than the semi-broken Windows power management.
Also, make sure to set
chmod u+x
on both the.desktop
file andlh.py
.Full modified script can be found in this fork:
https://gist.github.com/waylonflinn/d525e08674ec3abb5c98cd41d1fd2f24