Skip to content

Reading encrypted characteristcs returns error 132 but bond state becomes BONDED #347

@mecoFarid

Description

@mecoFarid

I have a simple setup as follows, where I am trying to bond with a host BL device by reading encrypted characteristics. This code sometimes succeeds but fails most of the time.

class BleClient (context: Context): BleManager(context){
  fun connectAdapter(): Flow<ConnectionState> = stateAsFlow().also {
    connect([BluetoothDevice])
      .useAutoConnect(true)
      .enqueue()
  }

  fun bond(): Flow<BondState> =
    bondingStateAsFlow().also {
      readEncryptedCharacteristic()
    }

  private fun readEncryptedCharacteristic() {
    super.readCharacteristic([ENCRYPTED_CHARACTERISTIC]).enqueue()
  }
}

Usage

  val bleClient = BleClient(context)
  // Wait for adapter connection to be ready
  bleClient.connectAdapter().first { it == ConnectionState.Ready }
  // Wait until bonded
  val bonded  =  bleClient.bond().first { it = BondState.Bonded }
  Log.i(TAG, "Bond state: $bonded")

When bleClient.bond().first { it = BondState.Bonded } is executed both host and the client displays a pairing dialog, once I click on "confirm" on both machines. The logcat shows the following logs: How is that even possible that reading encrypted characteristics fails but bond state becomes Bonded?

com.example.app E/BleManager: onCharacteristicRead error 132
com.example.app I/BleClient: Bond state: : no.nordicsemi.android.ble.ktx.state.BondState$Bonded@d9512fe

Note: error 132 means GhattDevice is busy

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions