RxBluetooth icon indicating copy to clipboard operation
RxBluetooth copied to clipboard

connect exception

Open xiaolingcong opened this issue 7 years ago • 5 comments

when bluetoothSocket.connect(); log: getBluetoothService() called with no BluetoothManagerCallback java.io.IOException: read failed, socket might closed or timeout, read ret: -1

xiaolingcong avatar Dec 05 '17 02:12 xiaolingcong

Discovering process could be an issue as it is a heavyweight procedure. Make sure you wait until it is over or use BluetoothAdapter.cancelDiscovery().

Discovery is not managed by the Activity, but is run as a system service, so an application should always call {@link BluetoothAdapter#cancelDiscovery()} even if it did not directly request a discovery, just to be sure.

IvBaranov avatar Dec 05 '17 11:12 IvBaranov

Same error as @xiaolingcong

 rxBluetooth.observeConnectDevice(device, UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"))
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribeOn(Schedulers.io())
                    .subscribe(new Consumer<BluetoothSocket>() {
                      @Override
                      public void accept(BluetoothSocket socket) throws Exception {
                        // Connected to the device, do anything with the socket
                        Log.e("B", "Connected");
                      }
                    }, new Consumer<Throwable>() {
                      @Override
                      public void accept(Throwable throwable) throws Exception {
                        // Error occured
                        Log.e("B", "Error:  " + throwable.getLocalizedMessage());
                      }
                    });

E/B: Error: read failed, socket might closed or timeout, read ret: -1

It is only connecting with my macbook and HC-06 Bluetooth Module but not with any other Bluetooth device like Android.

I think the issue is with UUID because supported UUID list doesn't show UUID that I have coded as Base UUID in code. Any suggestions?

Muhammad-Soban avatar Feb 16 '18 11:02 Muhammad-Soban

@Muhammad-Soban try to generate your own unique UUID while connecting two Android devices.

IvBaranov avatar Feb 16 '18 12:02 IvBaranov

If you are connecting to a Bluetooth headset or similar device and if the regular UUIDs don't work , you must first query it for it's supported UUIDs and then use that to connect to it.

Gyurme avatar May 30 '18 07:05 Gyurme

I have same error. I'm use SPP + BluetoothProfile.HEADSET. when call rxBluetooth.connectAsClient(device, UUID_SPP) => getBluetoothService() called with no BluetoothManagerCallback

but add .retryWhen { it.delay(500, TimeUnit.MILLISECONDS) }, always successfully connected after 30 second.

NunciosChums avatar Feb 15 '19 05:02 NunciosChums