Skip to content

aioble: Raise correct error if l2cap disconnects in middle of send. #1006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andrewleech
Copy link
Contributor

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants