Comments (8)
Hello,
Thank you for your report.
I will check tomorrow this scenario. I think that it may be a bug in the library because it is listening for BluetoothAdapter
's state changes and maybe when the connection is not yet established it's misbehaving.
from rxandroidble.
I see. Also some more information. The weird thing is that in RxBleGattCallback
onConnectionStateChange
gets called but not onServicesDiscovered
. Also another thing. When I debugged with breakpoints on bluetoothGatt.discoverServices()
and onComplete
inside RxBleRadioOperation
getSubscriber
then it worked.
from rxandroidble.
I have tried to reproduce the issue today on Motorola XT1030 but apparently switching off the BluetoothAdapter while establishConnection(_, true)
is making the connection never being established without any exceptions. I have waited for around 10 minutes.
Could you paste the code you are using and which mobile phone model?
Apparently it would be best to make the library fail any connections that are in the process of establishing if the BluetoothAdapter will go off.
from rxandroidble.
I see, but did you try to connect again after turn off/on with device being discoverable? Because my problem is that when Bluetooth turns on I call establishConnection
and then it hangs.
I am using Nexus 6P, Android N Preview 4
device.establishConnection(context, true)
.flatMap(rxBleConnection ->
rxBleConnection.getCharacteristic(CHARACTERISTIC)
.flatMap(characteristic ->
rxBleConnection.writeCharacteristic(setValue(characteristic))
.cache()
.flatMap(characteristic1 -> readData(rxBleConnection))
)
);
This is the code.
from rxandroidble.
I don't see if you're unsubscribing the first connection (started before the off/on switch) and you shouldn't be able to call on the same device .establishConnection()
again anyway because it would emit BleAlreadyConnectedException
.
It would be great to see the logs from the library (use RxBleLog.setLogLevel(RxBleLog.VERBOSE)
)
You could also describe when do you unsubscribe from the first connection.
from rxandroidble.
I am calling unsubscribe but I did not include the whole snippet. I am listening to the adapter on/off and unsubscribing appropriately. Also I unsubscribe when I finish reading from the device.
I am using latest code commited in this repository.
When I was debugging (I included library source into my project) the code worked?!?!?, services got discovered.
I also found a way to simulate this by not turning on/off the adapter:
.subscribe(bluetoothGatt -> {
try {
Method method = bluetoothGatt.getClass().getMethod("refresh");
if (method != null) {
method.setAccessible(true);
boolean result = (boolean) method.invoke(bluetoothGatt);
RxBleLog.d("Refresh result " + result);
}
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
bluetoothGatt.close();
},
throwable -> onError(throwable),
() -> onCompleted()
)
Basically inside RxBleRadioOperationDisconnect
I have added refresh function. This clears discovered services cache from the device (which also happens on adapter off). At least what the Google and internet says.
So at the moment I managed to fix this with the folling code inside RxBleRadioOperationServicesDiscover
.
Handler handler = new Handler(Looper.myLooper());
handler.postDelayed(() -> {
final boolean success = bluetoothGatt.discoverServices();
RxBleLog.d("Discover services " + success);
if (!success) {
subscription.unsubscribe();
subscriber.onError(new BleGattCannotStartException(BleGattOperationType.SERVICE_DISCOVERY));
}
}, 5000);
Maybe there is a better solution to this problem.
I have attached logs.logs.txt
from rxandroidble.
What do you refer to when saying I am using latest code committed in this repository.
? The latest SNAPSHOT or the latest release? Maybe your SNAPSHOT is not up to date. Unfortunately I couldn't reproduce your problem and refreshing the BluetoothGatt is not the best idea to reproduce the behaviour as I think it may not be the cause of the original problem.
from rxandroidble.
Actually last SNAPSHOT was from May since there was a styling issue which prohibited pushing to the maven repo. There is a new SNAPSHOT available since yesterday now.
from rxandroidble.
Related Issues (20)
- 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
- Unable to readCharacteristic after writeCharacteristic HOT 5
- In the case of unsuccessful Bluetooth connection, actively disconnect without executing context. unregisterReceiver (receiver); At this point, there may be multiple Bluetooth broadcast registrarReceivers, which may crash on some Huawei phones due to a broadcast limit of approximately 1000. Suggest fixing this issue. HOT 2
- Can't scan after connect dispose/clear HOT 1
- Add `advertisingSid` property to `ScanResult` and `RxBleInternalScanResult` HOT 3
- BleGattCallbackTimeoutException when writing a characteristic with different data payload many times in a short period of time. HOT 18
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.