Skip to content

fix: remove BleakClient.pair() call that breaks BLE on no-PIN devices#159

Open
ecapuano wants to merge 1 commit into
meshtastic:mainfrom
ecapuano:fix/remove-ble-pair-call
Open

fix: remove BleakClient.pair() call that breaks BLE on no-PIN devices#159
ecapuano wants to merge 1 commit into
meshtastic:mainfrom
ecapuano:fix/remove-ble-pair-call

Conversation

@ecapuano
Copy link
Copy Markdown

Summary

  • Removes the BleakClient.pair() call in BluetoothConnection._connect() that causes ATT error 0x0e ("Unlikely Error") on Meshtastic devices with Bluetooth PIN disabled
  • The pair() call corrupts the GATT connection state on Linux/BlueZ, causing all subsequent characteristic reads/notifications to fail
  • This is the required configuration since PIN support is not yet implemented (Bluetooth PIN Support #37)

Details

The pair() call was intended as best-effort ("should not harm if not needed"), but on devices without PIN:

  1. pair() triggers an ATT protocol error 0x0e on the BlueZ stack
  2. Although caught by the bare except, the pairing attempt corrupts the BLE connection state
  3. Subsequent GATT operations (start_notify, read_gatt_char) fail with BleakDBusError or NotConnected
  4. The integration reports "Unable to connect to the device" and never completes setup

bluetoothctl connect works fine from the host — the issue is specifically the pair() call from within Bleak/habluetooth.

For devices that do require pairing, the pair() call also did not work reliably due to Bleak limitations (hbldh/bleak#1434), as noted in the removed comment.

Testing

Tested on:

  • HAOS 17.1 / HA 2026.3.4 (aarch64, Raspberry Pi 5)
  • Meshtastic integration v0.6.1
  • Elecrow ThinkNode-M4 with BLE enabled, PIN disabled
  • RPi built-in BCM43438 Bluetooth adapter (hci0)

Before: "Unable to connect to the device" every time
After: Connection succeeds, integration sets up normally

Fixes #99
Related: #37

Test plan

  • Verify BLE connection succeeds on device with PIN disabled
  • Verify BLE connection still succeeds on device with PIN enabled (if tester has one)
  • Verify GATT characteristic reads/writes work after connection

🤖 Generated with Claude Code

…ices without PIN

The pair() call after BLE connection establishment causes an ATT protocol
error 0x0e ("Unlikely Error") on Meshtastic devices with Bluetooth PIN
disabled. Although the pair() call is wrapped in a try/except, on
Linux/BlueZ it corrupts the GATT connection state — subsequent
characteristic reads and notifications fail, causing the integration to
never complete setup and report "Unable to connect to the device."

The pair() call was documented as best-effort ("should not harm if not
needed"), but it actively prevents connection on no-PIN devices, which is
the required configuration since PIN support is not yet implemented (meshtastic#37).
For devices that do require pairing, the call also did not work reliably
due to Bleak limitations (hbldh/bleak#1434).

Fixes meshtastic#99

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 27, 2026

CLA assistant check
All committers have signed the CLA.

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.

Unable to connect to device.

2 participants