Skip to content

Instantly share code, notes, and snippets.

@prefiks
Created September 3, 2019 21:34
Show Gist options
  • Save prefiks/e614116fc3983a8e7e5fe326800dc101 to your computer and use it in GitHub Desktop.
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()
@Patola
Copy link

Patola commented Jan 16, 2021

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

@Firestorm7893
Copy link

Firestorm7893 commented Jan 17, 2021

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

@Firestorm7893
Copy link

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

@prefiks
Copy link
Author

prefiks commented Jan 17, 2021

Hi,

Please take look at https://github.com/DavidRisch/steamvr_utils, it expnads on this script, and maybe it will work for you.

@Firestorm7893
Copy link

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment