Inconsistent connection to a device not visible in scan
See original GitHub issueMobile Device Environment
- Device: [Samsung Galaxy A8]
- OS: [Android 9 (Pie)]
Application Environment
- React Native version: [v0.63.3]
- RN Bluetooth Classic version: [v1.60.0-rc.20]
Describe the bug Manually connecting to a specific macAddress seems to be inconsistent. Sometimes when it connects it doesn’t actually pass along any data through the bluetooth connection even though the connect/disconnect/writeToDevice returns true as if it were successful.
The app I’m developing needs to connect to a specific macAddress which is always known beforehand (so I don’t need to scan/startDiscovery). So to connect I just call the RNBluetoothClassic.connect(macAddress)
. However sometimes even when the connection is successful (RNBluetoothClassic.connect(address)
has returned true and when checking RNBluetoothClassic.isDeviceConnected(address)
it also returns true) none of the data transmissions functions (disconnect, writeToDevice) actually transmits any data to the receiver, even though they return true as if they were successfully called.
I have used the xCode bluetooth packet logger to view incoming transmissions from my macBook, which is how I can see that it sometimes doesn’t send anything. What I’ve noticed from the packet logger is that it sends a “Connection Request” but as soon as it has successfully connected it sends a “Disconnection Request” and then another “Connection Request”, I’m not sure if it could be that it has a reference to the closed socket (just guessing here, I have no idea how the BT works behind the scenes).
Whats interesting is that it sometimes work. For example if I reinstall the app and connect and send messages I can see that everything works and is transmitted correctly. But if I disconnect and reconnect it will never work to writeToDevice. None of the methods throws any errors and they all return true as if they were successfully accomplished which is why I’m so confused.
Worth noting is that the device I’m connecting to is not displayed in the discovered devices whenever I call a startDiscovery. However the device is in the pairedDevice’s list and it successfully works to connect it.
To Reproduce
- Manually connect to a computer(macBook/macMini) by its macAddress.
- Try to send a message to the device (sometimes works)
- Disconnect
- Reconnect
- Send another message to the device (never works)
Expected behavior It shouldn’t say that the connection and writeMessage are successful when nothing is sent.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
With regard to your other question, I would use a more standard method of communication. A regular socket using normal communication over a network. Or use BLE instead of RFCOMM.
Yes. It will definitely be hit or miss while attempting to connect from React Native (this library) to a Mac/IOS device. This is solely MFi related. I’m going to close this off since it’s working as designed as per the documentation and the limitations of MFi.