Reconnect if the BLE connection dies
This commit is contained in:
parent
2578fdca75
commit
06453f90e1
1 changed files with 18 additions and 25 deletions
23
solar_ble.py
23
solar_ble.py
|
@ -230,24 +230,13 @@ def write(fh, data):
|
||||||
dlgt = Delegate()
|
dlgt = Delegate()
|
||||||
|
|
||||||
prev = time.time() - INTERVAL
|
prev = time.time() - INTERVAL
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
with btle.Peripheral(MAC).withDelegate(dlgt) as dev:
|
with btle.Peripheral(MAC).withDelegate(dlgt) as dev:
|
||||||
|
|
||||||
# for svc in dev.services:
|
|
||||||
# print(svc, svc.uuid)
|
|
||||||
|
|
||||||
# print(dir(dev))
|
|
||||||
|
|
||||||
# wd = dev.getServiceByUUID(write_service)
|
|
||||||
|
|
||||||
# print(wd)
|
|
||||||
|
|
||||||
wd = dev.getCharacteristics(uuid=write_device)[0]
|
wd = dev.getCharacteristics(uuid=write_device)[0]
|
||||||
# print(cs)
|
|
||||||
# print(dir(cs))
|
|
||||||
# print(wd.write(b'\xf0\x03\x00\x0c\x00\x08\x91\xd1'))
|
|
||||||
|
|
||||||
# rd = dev.getCharacteristics(uuid=read_device)[0]
|
|
||||||
# print(rd.read())
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
dev.waitForNotifications(1)
|
dev.waitForNotifications(1)
|
||||||
|
@ -267,3 +256,7 @@ with btle.Peripheral(MAC).withDelegate(dlgt) as dev:
|
||||||
# write(wd, CMD_DISABLE_LOAD)
|
# write(wd, CMD_DISABLE_LOAD)
|
||||||
# else:
|
# else:
|
||||||
# write(wd, CMD_ENABLE_LOAD)
|
# write(wd, CMD_ENABLE_LOAD)
|
||||||
|
|
||||||
|
except btle.BTLEDisconnectError:
|
||||||
|
print(datetime.datetime.utcnow().isoformat(" "), "ERROR: Disconnected")
|
||||||
|
time.sleep(1)
|
||||||
|
|
Loading…
Reference in a new issue