Skip to content

Fix connect() with a passed BLE device; always close the transport - #125

Merged
fdlamotte merged 1 commit into
meshcore-dev:mainfrom
hamsolodev:ble-device-address-disconnect
Nov 22, 2026
Merged

fdlamotte merged 1 commit into
meshcore-dev:mainfrom
hamsolodev:ble-device-address-disconnect

Conversation

@hamsolodev

Copy link
Copy Markdown
Contributor

What was wrong (#119, C1 and C2)

  • C1: create_ble(device=...) always failed. In BLEConnection.connect, the device branch never set self.address, and the method returns self.address. So it returned None once the link was up, and MeshCore.connect() raised "Failed to connect to device". I first saw this with a real radio.
  • C2: ConnectionManager.disconnect() closed the transport only when _is_connected was set. Two kinds of link were left open:
    • a link whose connect() returned None after the transport came up (C1, or "Could not find UART service");
    • a link marked lost by handle_disconnect() after a failed or timed-out write.

What changed

  • The device branch takes the address from the client, as the scan branch already does.
  • disconnect() always calls self.connection.disconnect(); each transport's disconnect() already does nothing on a closed link. DISCONNECTED is still emitted only for a link that was connected.

Verified with unit tests in tests/unit/test_ble_device_and_disconnect.py. They fail on current main. The whole suite passes on 3.11 and 3.14.

Something I noticed while writing these, not changed here: EventDispatcher.stop() sets running = False before queue.join(). With two or more events still queued, the loop exits after the first and join() waits for ever. Dispatching two events and then calling stop() hangs it. Happy to send that separately if you'd like.

Part of #119.

- BLEConnection.connect() with a device never set self.address, and
  returned it, so after the link came up it returned None and
  MeshCore.connect() raised "Failed to connect to device". It now takes
  the address from the client, as the scan branch does.
- ConnectionManager.disconnect() closed the transport only when it was
  marked connected. A link stays open after a connect() that returned None
  once the transport was up (the above, or "Could not find UART service"),
  and after handle_disconnect() marked it lost on a failed write. It now
  always closes it; each transport's disconnect() does nothing on a closed
  link. DISCONNECTED is still emitted only for a connected link.

Part of meshcore-dev#119 (C1, C2).
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