-
-
Save Anden/321c6608e8f753024f5f4e726e2a43f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 = "" | |
manufacturer = dev.getValue(btle.ScanEntry.MANUFACTURER) | |
if manufacturer is not None and 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) | |
try: | |
if len(sys.argv) > 1 and sys.argv[1] == 'on': | |
lh.writeCharacteristic(0x12, b'\x01') | |
else: | |
lh.writeCharacteristic(0x12, b'\x00') | |
finally: | |
lh.disconnect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can turn on both stations with this (might take multiple attempts), but only one station shuts down when using the off command.
output:
Found LightHouse LHB-B9E3CCFD: address = d8:d1:0a:37:7d:fc
Found LightHouse LHB-A2A4E957: address = c7:4e:ab:90:7f:6e
Connecting to d8:d1:0a:37:7d:fc
Connecting to c7:4e:ab:90:7f:6e
Traceback (most recent call last):
File "./lh.py", line 34, in
lh.connect(device, addrType = btle.ADDR_TYPE_RANDOM)
File "/usr/lib/python3.8/site-packages/bluepy/btle.py", line 445, in connect
self._connect(addr, addrType, iface)
File "/usr/lib/python3.8/site-packages/bluepy/btle.py", line 439, in _connect
raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)
bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral c7:4e:ab:90:7f:6e, addr type: random