Comments (11)
Hello there. Sorry for no response - we're discussing how to address this issue. Usually any error during communication means the connection is no longer active and usable. We will get back to you.
from rxandroidble.
The problem is: Bonding for BLE on Android is pain in the ass.
Each producer (like htc, Samsung or Xiaomi) has implement this procedure on a different way.
Some devices you can bond, others will bond automatically if you access an encrypted characteristic. If they will bond automatically, on some devices it works in background without you have to do something. Other devices throws an error (like status 137) and you have to repeat it.
And I thought Bluetooth is a standard :-D.
Thanks for the good work so far.
from rxandroidble.
@tatewaki I have the feeling you're mixing bonding with connecting, I believe those are not the same.
from rxandroidble.
I know that bonding and connection is not the same. And because of that, I reported the issue.
RxAndroidBle will disconnect on an error relating to bonding. But there is no need to disconnect.
from rxandroidble.
I have the same issue, is there any work around for now without needing to reconnect after bonding is successful?
from rxandroidble.
Hello @asmirsabanovic
A workaround would be not to pass status
to observables different than the one that emitted it.
from rxandroidble.
@dariuszseweryn thanks for the fast response, but I don't follow completely. Here is how I do it now:
//Read uuid that needs bonding
RxBleConnection.readCharacteristic(AUTH_REQ_UUID)...subscribe(..);
User enters correct PIN -> Bonding Successful
I get: BleGattException{status=137, bleGattOperation=BleGattOperation{description='CHARACTERISTIC_READ'}}
And this disconnects the connection. I do a reconnect and this time the read will work.
How can I do this with your suggestion to avoid the disconnect after bonding is successful?
Thanks again.
from rxandroidble.
You would need to make some changes in the RxBleGattCallback
class. The point is not to pass the status
error around via statusBehaviourSubject
.
I don't have any experience with bonded devices. Can you confirm that the RxBleGattCallback.onCharacteristicRead()
is postponed after the user enters pin? Can you share what device are you using (or is it possible to get one to test the library myself)
from rxandroidble.
If I don't pass the status
through statusErrorSubject
the connection stays alive after a successful bond.
Yes, the onCharacteristicRead
is postponed after the user enters pin or the pin entry is cancelled. I'm currently testing on Samsung S7 Edge and Sony Xperia Z4
from rxandroidble.
Could you be so kind and paste these two classes to your project:
public class DeviceBondingResult {
public final BluetoothDevice device;
public final int previousBondState;
public final int currentBondState;
public DeviceBondingResult(BluetoothDevice device, int previousBondState, int currentBondState) {
this.device = device;
this.previousBondState = previousBondState;
this.currentBondState = currentBondState;
}
private String bondStateString(int bondState) {
switch (bondState) {
case 10:
return "BOND_NONE";
case 11:
return "BOND_BONDING";
case 12:
return "BOND_BONDED";
}
return "UNKNOWN";
}
@Override
public String toString() {
return "DeviceBondingResult{" +
"device=" + device +
", previousBondState=" + bondStateString(previousBondState) +
", currentBondState=" + bondStateString(currentBondState) +
'}';
}
}
and an Observable
public class DeviceBondingObservable extends Observable<DeviceBondingResult> {
protected DeviceBondingObservable(Context context) {
super(
new OnSubscribeFromEmitter<>(emitter -> {
final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
final int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
final int previousBondState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, -1);
final DeviceBondingResult result = new DeviceBondingResult(device, previousBondState, bondState);
Log.d("TEST", result.toString());
emitter.onNext(result);
}
};
context.registerReceiver(broadcastReceiver, new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED));
emitter.setCancellation(() -> context.unregisterReceiver(broadcastReceiver));
},
Emitter.BackpressureMode.BUFFER)
);
}
}
Subscribe to DeviceBondingObservable
and paste the logs from a bonding procedure that you execute? I then will have some material to think about how to integrate bonding support into the library.
from rxandroidble.
Finally this should be fixed / available in 1.3.0
somewhere this week. Is available on 1.3.0-SNAPSHOT
now.
from rxandroidble.
Related Issues (20)
- Permission for connection with sample-kotlin HOT 2
- Wrong permission checked in sample-kotlin app
- Strange unresolved methods HOT 1
- Does RxAndroidBle support the use of Bluetooth Gatt's connect method? HOT 4
- Building fork help HOT 6
- It is not possible to disconnect the Bluetooth while it is in the process of connecting. HOT 1
- BleGattCharacteristicException while readCharacteristic HOT 12
- scanResult.bleDevice.name not showing Ble updated name HOT 1
- BLUETOOTH_SCAN set usesPermissionFlags="neverForLocation",Is there a problem? HOT 2
- GenericFailure<CharacteristicValueUpdateError> HOT 11
- Send long bytes twice HOT 2
- Write request is not processed in the random order HOT 2
- Long Bytes Send HOT 8
- Creating a Fork HOT 2
- Set Preferred PHY / Read PHY HOT 2
- RxBleClient mulit connections HOT 4
- Is the library still maintained? HOT 3
- Android 14 breaking change HOT 15
- Google Pixel 5 loses bonding info after BT adapter cycle HOT 4
- Metode readcharacteristic not stream HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxandroidble.