Device is not connected
See original GitHub issueVersion
Tell us which versions you are using:
- react-native-ble-manager v.6.5.6
- react-native v.0.57.8
- Android v.27.0.3
Expected behavior
When trying to connect to VEEPEAK OBD 2 dongle and call retrieveServices method it should give all the services PIDs and characteristics.
Actual behavior
When I am trying to connect my react native app to the VEEPEAK OBD2 dongle it gets connected but within a second it gets disconnected. Before connecting I am also creating a bond with the device. The bond created successfully but still after getting connected it gets disconnected. Previously I was using the v.6.5.4 of the library that time also it is giving the same behavior and after upgrading to the latest v.6.5.6 still the things are same for me. The device I am trying to connect is a Veepeak OBDCheck BLE OBD2 Bluetooth Scanner which works on Bluetooth 4.0, link for this device is: https://www.amazon.com/Veepeak-OBDCheck-Bluetooth-Diagnostic-Compatible-x/dp/B073XKQQQW
Also please check the code below:
BleManager.createBond(peripheral.id).then(() => { console.log('createBond success or there is already an existing one'); BleManager.connect(peripheral.id).then(() => { let peripherals = this.state.peripherals; let p = peripherals.get(peripheral.id); if (p) { p.connected = true; peripherals.set(peripheral.id, p); this.setState({ peripherals }); } console.log('Connected to ' + peripheral.id); setTimeout(() => { BleManager.retrieveServices(peripheral.id).then((peripheralData) => { console.log('Retrieved peripheral services', peripheralData); setTimeout(() => { BleManager.read(peripheral.id, serviceUUID, characteristicUUID).then((readData) => { console.log('Read: ' + readData); }).catch((error) => { console.log(error); }); }); }).catch((error) => { console.log('Error: ' + error); }); }); }).catch((error) => { console.log(error); }); }).catch(() => { console.log('fail to bond'); })
Steps to reproduce
- Scan for peripherals
- List all peripherals
- Create a bond with the peripheral
- Connect to the peripheral
- Retrieve services of the peripheral
Stack trace and console log
Create bond success or there is already an existing one Connected to 8C:XX:XX:XX:XX:CD Disconnected to to 8C:XX:XX:XX:XX:CD Error: Device is not connected
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (4 by maintainers)
Top GitHub Comments
I have the same problem. It starts at random after some app runs. I suspect it has something to do with the underlying Bluetooth layer of Android. It gets really weird when I completely disable Bluetooth from the phone settings, the connection still exists and I can still operate my peripheral. Even after killing my app I can still connect to it while Bluetooth is turned off. I suspect this connection keeps existing even after the app is restarted. Only rebooting my phone (Samsung Galaxy S20+) solves this.
I got it all working now, the library works fine. When React Native hot reloads the app the connection persists so then it gets confused. Solved by disabling Bluetooth from the phone settings menu (not from the quick pull system down menu, that button is pure evil on Samsung devices) to disconnect the device.
If you device reports isConnectable false then there may already be a current connection or maybe something is wrong in the firmware.