Skip to content
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

peripheral.observe didUpdateNotificationStateForCharacteristic #653

Open
DayDayUpAllInOne opened this issue Mar 10, 2024 · 3 comments
Open

Comments

@DayDayUpAllInOne
Copy link

DayDayUpAllInOne commented Mar 10, 2024

When I use the code below,The kable library reports an error

actual suspend fun notify(device: BleDeviceEntity): Flow<ByteArray> {
    val notifyCharacteristic = characteristicOf(
      uuidFrom(bleUuid.serviceUuid).toString(),
      uuidFrom(bleUuid.notifyUuid).toString()
    )
    return device.peripheral.observe(notifyCharacteristic)
}

error message:

W/Kable/Delegate: 890FF1DD-33D3-AF4F-2CD8-7340E8C3B112 890FF1DD-33D3-AF4F-2CD8-7340E8C3B112 didUpdateNotificationStateForCharacteristic
  service: 8C858000-0302-41C5-B46E-CF057C562025
  characteristic: 8C858000-0302-4D46-BEC2-EE689169F628
  error: Error Domain=CBATTErrorDomain Code=10 "The attribute could not be found." UserInfo={NSLocalizedDescription=The attribute could not be found.}

error

How to solve this problem? Thanks!

@twyatt
Copy link
Member

twyatt commented Mar 11, 2024

What version of Kable are you using?

@DayDayUpAllInOne
Copy link
Author

What version of Kable are you using?

hi twyatt, the Kable version I use is 0.24.0, this problem occurs on iOS, Android is normal

@DayDayUpAllInOne
Copy link
Author

DayDayUpAllInOne commented Mar 11, 2024

I added the observationExceptionHandler method, and the program can receive the notification data from the Bluetooth device normally.

val peripheral = defaultScope.peripheral(it) {
    onServicesDiscovered {
        bleLogger.i("""BleClient/startScan/onServicesDiscovered:${it.peripheralName}""")
    }
    observationExceptionHandler { cause ->
        // Log failure instead of propagating associated `observe` flow.
        bleLogger.i("""BleClient/startScan/observationExceptionHandler:$cause""")
    }
}

Log:

Runner[1678:356710] W/Kable/Delegate: 890FF1DD-33D3-AF4F-2CD8-7340E8C3B112 890FF1DD-33D3-AF4F-2CD8-7340E8C3B112 didUpdateNotificationStateForCharacteristic
  service: 8C858000-0302-41C5-B46E-CF057C562025
  characteristic: 8C858000-0302-4D46-BEC2-EE689169F628
  error: Error Domain=CBATTErrorDomain Code=10 "The attribute could not be found." UserInfo={NSLocalizedDescription=The attribute could not be found.}
>>> info#ESIot/ble <<<BleClient/startScan/observationExceptionHandler:com.juul.kable.IOException: Error Domain=CBATTErrorDomain Code=10 "The attribute could not be found." UserInfo={NSLocalizedDescription=The attribute could not be found.}/1710152968286

Why does the program become normal after adding the observationExceptionHandler method?

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

No branches or pull requests

2 participants