Conversation

andrewleech

When using aioble/l2cap to send data from micropython to a cental like a phone, if the ble disconnects in the middle of a send process it can currently fail with the exception:

Traceback (most recent call last):
  File "aioble/l2cap.py", line 147, in send
TypeError: can't convert NoneType to int

This is because the send function is operating in a loop sending the data in chunks.
At the top of the function self._assert_connected() is already called which will raise a L2CAPDisconnectedError if the connection has already been dropped (as detected by self._cid is None however the chunk send loop can run for some time, a disconnect in the middle of this results in self._cid = None being passed to ble.l2cap_send() resulting in the exception above.

This PR simply adds the correct connection check immediately before each loop of l2cap_send().

@andrewleechandrewleech force-pushed the aioble_l2cap_send_disconnect branch from 7e1c9cf to a3bd39d Compare June 19, 2025 00:29
Sign up for free to join this conversation on . Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.