Improving bluetooth stability #100
Replies: 4 comments 8 replies
-
I started with that and then refined it to make the connection more stable. You could try removing the bells and whistles and check it btproxys react differently |
Beta Was this translation helpful? Give feedback.
-
I have tried out the Could you try out the following script on a machine with bluetooth after pairing with one of your thermostats and tell me if you see a similar behaviour? You'll need to do a import logging
from time import sleep
import simplepyble
logging.basicConfig(level=logging.INFO, format="%(asctime)s: %(message)s")
def main():
adapters = simplepyble.Adapter.get_adapters()
if len(adapters) == 0:
logging.info("No adapters found")
logging.info("Please select an adapter:")
for i, adapter in enumerate(adapters):
logging.info(f"{i}: {adapter.identifier()} [{adapter.address()}]")
choice = int(input("Enter choice: "))
adapter = adapters[choice]
logging.info(f"Selected adapter: {adapter.identifier()} [{adapter.address()}]")
adapter.set_callback_on_scan_start(lambda: logging.info("Scan started."))
adapter.set_callback_on_scan_stop(lambda: logging.info("Scan complete."))
adapter.set_callback_on_scan_found(
lambda peripheral: logging.info(
f"Found {peripheral.identifier()} [{peripheral.address()}]"
)
)
adapter.scan_for(5000)
peripherals = adapter.scan_get_results()
logging.info("Please select a peripheral:")
for i, peripheral in enumerate(peripherals):
logging.info(f"{i}: {peripheral.identifier()} [{peripheral.address()}]")
choice = int(input("Enter choice: "))
peripheral = peripherals[choice]
logging.info(f"Connecting to: {peripheral.identifier()} [{peripheral.address()}]")
peripheral.connect()
try:
while True:
if peripheral.is_connected():
logging.info("Device is connected.")
else:
logging.info("Device is no longer connected.")
sleep(1)
except KeyboardInterrupt:
pass
finally:
peripheral.disconnect()
logging.info("Disconnected from the device.")
if __name__ == "__main__":
main() |
Beta Was this translation helpful? Give feedback.
-
Yes, the device goes into Bluetooth sleep after a while. Somewhere in this repo/issues/discussion I suggest to have a scan interval < 1m to keep it connected |
Beta Was this translation helpful? Give feedback.
-
You were absolutely right. Sending a command or resubscribing to the notify characteristic every 10 seconds prevents disconnects! |
Beta Was this translation helpful? Give feedback.
-
I haven't yet found a reason for the connection issues me and other people are facing especially when using bluetooth proxies.
What I am pretty sure of is that the disconnects seem to occur about every five minutes and last for about 30 seconds.
I am experimenting with a script that monitors BLE device availability to try to confirm this.
Regarding the overall bluetooth connection process, I have found the following article(s) in the Home Assistant Developer Docs which explain how bluetooth connection should be handled. Since the integration currently uses a different process to achieve the connection, I'd like to get your evaluation whether it would make sense to try out the methods described in that article or if they have already been tried out.
Beta Was this translation helpful? Give feedback.
All reactions