aioble connection management

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
anichang
Posts: 4
Joined: Sun May 09, 2021 12:55 am

aioble connection management

Post by anichang » Fri Dec 31, 2021 2:20 pm

I have the following listener asyncio task:

Code: Select all

    # Serially wait for connections. Don't advertise while a central is connected.
    async def _pListen(self):
        while True:
            print("\nBLE advertising")
            async with await aioble.advertise(
                BLE_ADV_INTERVAL_MS,
                name=self.name,
                services=[s.uuid for s in self.service],
                appearance=self.appearance,
            ) as self.connection:
                print("\n", self.connection.device, "connected")
                await self.connection.disconnected(timeout_ms=None)
                print("\n", self.connection.device, "disconnected")
When timeout_ms=None everything works fine but connection never drops and I suppose I might get random deadlocks at some conditions in time. If I remove the timeout_ms parameter, by defaults it disconnects after 60000ms giving me a

Code: Select all

lld_pdu_get_tx_flush_nb HCI packet count mismatch (0, 1)
and making the device unresponsive any more (repl works, but ble is frozen).

I would like to leave the default 60 seconds there, but being able to reset the timeout on each rx/tx (keep-alive). Does it make sense or I got it completely wrong?

More in general, what's the reccomended behaviour for BLE? Do I need to connect before every data transmission (and disconnect right after) or I can have a single long lasting session transmitting data from time to time, or ... ?

ChrisO
Posts: 48
Joined: Mon Apr 06, 2020 6:16 pm

Re: aioble connection management

Post by ChrisO » Fri Feb 18, 2022 3:40 pm

Unfortunately I'm running into the same issue when using aioble.
I have two PoC's. one using bluetooth and the other using aioble, and the latter seems to silently drop the connection after about a minute, despite any tweaks to the timeout.
code after `await connection.disconnected` is never reached and therefor the esp won't start advertising.


did you make any progress with this issue?
Chris

Post Reply