lhctrl icon indicating copy to clipboard operation
lhctrl copied to clipboard

Example command and implimentation

Open clockwinder opened this issue 5 months ago • 6 comments

I've been setting up a Vive on Linux, and after discovering the lack of lighthouse power control, I discovered your solution!

After starting the script, the lighthouses turn on, then the py script crashes. Is this because my command isn't properly utilizing your control system?

$ python lhctrl.py --lh_b_mac 40:4E:36:9E:1F:F5 --lh_b_id 5B3A36CF -i 1 -v
Booting up "B" lighthouse
Connecting to 40:4E:36:9E:1F:F5 at Tue Jul  8 11:36:34 2025 -> conn
Writing char-cs to 0x35 : 1202003ccf363a5b000000000000000000000000 -> {'rsp': ['wr']}
Reading char-cs from 0x35 -> Traceback (most recent call last):
  File "/home/user/Downloads/lhctrl-1.0.0/pylhctrl/lhctrl.py", line 218, in <module>
    main(args)
    ~~~~^^^^^^
  File "/home/user/Downloads/lhctrl-1.0.0/pylhctrl/lhctrl.py", line 191, in main
    loop(args)
    ~~~~^^^^^^
  File "/home/user/Downloads/lhctrl-1.0.0/pylhctrl/lhctrl.py", line 151, in loop
    hndl_io(args.lh_b_mac, args.hndl, ping_b, args.try_count, args.try_pause, args.verbose, args.interface)
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Downloads/lhctrl-1.0.0/pylhctrl/lhctrl.py", line 133, in hndl_io
    resw, resr = writeReadCmd(lh, hndl, cmd, verb)
                 ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Downloads/lhctrl-1.0.0/pylhctrl/lhctrl.py", line 93, in writeReadCmd
    return res, readCmd(lh, hndl, verb)
                ~~~~~~~^^^^^^^^^^^^^^^^
  File "/home/user/Downloads/lhctrl-1.0.0/pylhctrl/lhctrl.py", line 85, in readCmd
    res = lh.readCharacteristic(hndl)
  File "/usr/local/lib/python3.13/site-packages/bluepy/btle.py", line 530, in readCharacteristic
    resp = self._getResp('rd')
  File "/usr/local/lib/python3.13/site-packages/bluepy/btle.py", line 407, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/usr/local/lib/python3.13/site-packages/bluepy/btle.py", line 362, in _waitResp
    raise BTLEDisconnectError("Device disconnected", resp)
bluepy.btle.BTLEDisconnectError: Device disconnected

What is an example command when the script is being properly used?

clockwinder avatar Jul 08 '25 17:07 clockwinder

@clockwinder From the snippet you posted the calling syntax looks alright. The problem is that your basestation disconnects before replying. Which is how I read the exception bluepy throws. Are you running v1 or v2 lighthouse? Is the status LED green?

risa2000 avatar Jul 08 '25 19:07 risa2000

V1 Lighthouse, two of them in b/c mode. The status light is green on both, and when the script is run they wake and go into purple(?) mode with the letter indicator, then fall asleep a bit after the script crashes.

I currently have them "paired" but disconnected to my KDE environment. Not sure if that's accurate, or relevant, but thought it worth noting.

My device looks like it supports bt-le: https://www.tp-link.com/us/home-networking/usb-adapter/ub400/

clockwinder avatar Jul 08 '25 22:07 clockwinder

You should not need to pair the bases for the LH control to work. The TP-Link BT-USB adapter could be a suspect, but to be honest I never did any testing of different hardware. The only configuration I ran it on was a Raspberry Pi 3B (and later 3B+) with built-in BT and there it worked as expected. Today I do not even have any v1 LH to test, so I guess you are on your own. Just out of curiosity, did you test your setup on Windows with SteamVR headset (you need an "official" headset, with an integrated BT to be able to control bases remotely - e.g. OG Vive, Vive Pro, Index).

risa2000 avatar Jul 08 '25 22:07 risa2000

I've been running the Vive on windows since release, and the V1 power control for lighthouses has always worked (after updating the lighthouses when power control was added).

Well, maybe I'll pull out a PiZeroW and try it on that? Using a whole B3+ feels overkill.

clockwinder avatar Jul 08 '25 22:07 clockwinder

If you can, you may. PiZeroW should be enough. I was using RPi 3B because it was running some other stuff and was just conveniently available.

risa2000 avatar Jul 08 '25 22:07 risa2000

So much work to get back a feature that should just be working...

clockwinder avatar Jul 08 '25 22:07 clockwinder