From a010c746ae7d128f291050e22f555d76c390aeb8 Mon Sep 17 00:00:00 2001 From: nicolas-f <1382241+nicolas-f@users.noreply.github.com> Date: Wed, 3 Jul 2024 15:33:31 +0200 Subject: [PATCH] await more preventing disconnection2 --- services/pixljs_alert/zero_ble.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/pixljs_alert/zero_ble.py b/services/pixljs_alert/zero_ble.py index e4ee8ae..bc3f620 100644 --- a/services/pixljs_alert/zero_ble.py +++ b/services/pixljs_alert/zero_ble.py @@ -265,7 +265,7 @@ async def main(config): if mode == "install": print("Install mode connecting to Pixl.js") try: - async with (BleakClient(scan_result.device) as client): + async with ((BleakClient(scan_result.device) as client)): await client.start_notify(UART_TX_CHAR_UUID, scan_result.uart_data_received) nus = client.services.get_service(UART_SERVICE_UUID) rx_char = nus.get_characteristic(UART_RX_CHAR_UUID) @@ -278,7 +278,8 @@ async def main(config): scan_result.received_data = io.BytesIO() for buffer in slice_bytes(c, rx_char.max_write_without_response_size): await client.write_gatt_char(rx_char, buffer) - while time.time() - scan_result.received_data_time < 0.1 and not t.is_set(): + while ">" not in scan_result.received_data \ + .getvalue().decode("iso-8859-1") and not t.is_set(): await asyncio.sleep(0.1) return_messages = scan_result.received_data.getvalue().decode("iso-8859-1") if "mode=1" not in return_messages: