Open black opened 4 days ago
Hi There!
The issue is that only one characteristic is being observed at a time because multiple observers are set up for conflicting traits.
To fix this, try setting up each observer sequentially with a slight delay between each one to give them time to establish properly. Here's a suggestion to modify your code using coroutines and launch
to handle multiple observers without interference:
GlobalScope.launch
): This ensures each characteristic gets its independent observer without blocking or interfering with the others.Give this a try, and it should help you read from multiple characteristics at the same time!
ble.connect(device)?.let { connection ->
connection.requestMTU(bytes = 64)
binding.connectionStatus.text = if (connection.isActive) "Connected" else "Not Connected"
connection.apply {
// Launch a coroutine to observe each characteristic sequentially
GlobalScope.launch {
observeString(characteristic = CHARACTERISTIC_UUID_ECG, charset = Charsets.UTF_8) { value: String ->
Log.d(TAG, "ECG::: $value")
binding.dataEcg.text = "ECG::: $value"
}
}
GlobalScope.launch {
observeString(characteristic = CHARACTERISTIC_UUID_IMU, charset = Charsets.UTF_8) { value: String ->
Log.d(TAG, "IMU::: $value")
binding.dataImu.text = "IMU::: $value"
}
}
GlobalScope.launch {
observeString(characteristic = CHARACTERISTIC_UUID_BATTERY, charset = Charsets.UTF_8) { value: String ->
Log.d(TAG, "BAT::: $value")
binding.dataBattery.text = "BAT::: $value"
}
}
}
}
@soheilkooklan I tried this already. This was the first response from claudeAi and ChatGPT both. It didn't work.
Hello @black thanks for the interest in the library :)
@LeandroSQ Hey, Can you help me with this one please?
Quick question, do these characteristics have notify enabled? you can check this using connection. notifiableCharacteristics
Yes, they do. Basically, I’ve written a small program in Arduino for the Seeed Xiao NRF54320 to transmit fake data like ECG, IMU, and battery status. The issue is that when I comment out the ECG observer, the IMU observer receives data and when both the ECG and IMU observers are commented out, I receive the battery status data. I can only receive data from one observer at a time.
And all of these read correctly if done one-by-one?
Another thing, are you able to put a breakpoint here and check if this gets called?
And all of these read correctly if done one-by-one?
Yes, that correct.
Another thing, are you able to put a breakpoint here and check if this gets called?
Hey This isn't getting called.
@soheilkooklan I tried this already. This was the first response from claudeAi and ChatGPT both. It didn't work.
That code was rewritten with ChatGPT. Another way is to check these options:
@soheilkooklan Pleases stop posting ChatGPT response. If I want, I could take help from ChatGPT myself. Stop spamming.
@soheilkooklan Pleases stop posting ChatGPT response. If I want, I could take help from ChatGPT myself. Stop spamming.
Your device may not be working with the features you want. I rewrote the code with ChatGPT just to save time and help you. There's no need to be rude—everyone here has problems they're trying to solve, just like you. This isn’t spam; it’s an attempt to offer assistance.
I am using the below code to read the multiple characteristics but only the first characteristics gets observed . When I remove the first observer then I started receiving from the next and so on. Basically it is only reading one characteristics at a time.