Skip to content

Commit

Permalink
Merge pull request #1 from DidierLoiseau/main
Browse files Browse the repository at this point in the history
Add --on and --off to just switch the lighthouses on or off
  • Loading branch information
risa2000 authored Feb 20, 2022
2 parents c3b6824 + e575a2e commit 6611adc
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 246 deletions.
18 changes: 9 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# VIM backups
*~

# Utility
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# VIM backups
*~

# Utility
.vscode/
43 changes: 22 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
MIT License

Copyright (c) 2020 risa2000

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License

Copyright (c) 2020 risa2000
Copyright (c) 2022 DidierLoiseau

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
78 changes: 40 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
# lh2ctrl
## Power management of Valve v2 lighthouses over Bluetooth LE

This project is mimicking the original [`lhctrl` project](https://github.com/risa2000/lhctrl), which dealt with v1 lighthouses. It is based on the work @nouser2013 did on [Pimax forum thread](https://community.openmr.ai/t/how-to-power-off-basestations-remotely-solved/15205). He also made a Windows implementation of the ideas [here on GitHub](https://github.com/nouser2013/lighthouse-v2-manager/). The difference between this project and the one above is that this project is targeting linux platform and uses the same BT LE Python interface as the original `lhctrl` did.

### BT LE protocol simplified ###
While v1 lighthouses used a quite convoluted protocol to keep the lighthouse running the v2 lighthouses are much simpler. Using BT LE GATT protocol, one just needs to write zero or one to one particular characteristics (**00001525-1212-efde-1523-785feabcd124**) in order to either power on or off the lighthouse.

### Solution
The implemented solution [lh2ctrl.py](/pylhctrl/lh2ctrl.py) uses Python `bluepy` package to access `bluez` BT LE API. The script writes to a particular characteristic to start or stop the lighthouse.

#### Usage
```
usage: lh2ctrl.py [-h] [-g GLOBAL_TIMEOUT] [-i INTERFACE]
[--try_count TRY_COUNT] [--try_pause TRY_PAUSE] [-v]
lh_mac [lh_mac ...]
Wakes up and runs Valve v2 lighthouse(s) using BT LE power management
positional arguments:
lh_mac MAC address(es) of the lighthouse(s) (in format
aa:bb:cc:dd:ee:ff)
optional arguments:
-h, --help show this help message and exit
-g GLOBAL_TIMEOUT, --global_timeout GLOBAL_TIMEOUT
time (sec) how long to keep the lighthouse(s) alive
(0=forever) [0]
-i INTERFACE, --interface INTERFACE
The Bluetooth interface on which to make the
connection to be set. On Linux, 0 means /dev/hci0, 1
means /dev/hci1 and so on. [0]
--try_count TRY_COUNT
number of tries to set up a connection [5]
--try_pause TRY_PAUSE
sleep time when reconnecting [2]
-v, --verbose increase verbosity of the log to stdout
```
# lh2ctrl
## Power management of Valve v2 lighthouses over Bluetooth LE

This project is mimicking the original [`lhctrl` project](https://github.com/risa2000/lhctrl), which dealt with v1 lighthouses. It is based on the work @nouser2013 did on [Pimax forum thread](https://community.openmr.ai/t/how-to-power-off-basestations-remotely-solved/15205). He also made a Windows implementation of the ideas [here on GitHub](https://github.com/nouser2013/lighthouse-v2-manager/). The difference between this project and the one above is that this project is targeting linux platform and uses the same BT LE Python interface as the original `lhctrl` did.

### BT LE protocol simplified ###
While v1 lighthouses used a quite convoluted protocol to keep the lighthouse running the v2 lighthouses are much simpler. Using BT LE GATT protocol, one just needs to write zero or one to one particular characteristics (**00001525-1212-efde-1523-785feabcd124**) in order to either power on or off the lighthouse.

### Solution
The implemented solution [lh2ctrl.py](/pylhctrl/lh2ctrl.py) uses Python `bluepy` package to access `bluez` BT LE API. The script writes to a particular characteristic to start or stop the lighthouse.

#### Usage
```
usage: lh2ctrl.py [-h] [-g GLOBAL_TIMEOUT | --on | --off] [-i INTERFACE]
[--try_count TRY_COUNT] [--try_pause TRY_PAUSE] [-v]
lh_mac [lh_mac ...]
Wakes up and runs Valve v2 lighthouse(s) using BT LE power management
positional arguments:
lh_mac MAC address(es) of the lighthouse(s) (in format
aa:bb:cc:dd:ee:ff)
optional arguments:
-h, --help show this help message and exit
-g GLOBAL_TIMEOUT, --global_timeout GLOBAL_TIMEOUT
time (sec) how long to keep the lighthouse(s) alive
(0=forever) [0]
--on just switch the devices on and stop
--off just switch the devices off and stop
-i INTERFACE, --interface INTERFACE
The Bluetooth interface on which to make the
connection to be set. On Linux, 0 means /dev/hci0, 1
means /dev/hci1 and so on. [0]
--try_count TRY_COUNT
number of tries to set up a connection [5]
--try_pause TRY_PAUSE
sleep time when reconnecting [2]
-v, --verbose increase verbosity of the log to stdout
```
Loading

0 comments on commit 6611adc

Please sign in to comment.