Bluetooth connection error for Android (socket read failure may be closed or timeout)

I want to connect from my application in an Android device to a remote device (paired). The remote device is the HC-05 module.
my code is:

UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); //Standard SerialPortService ID try { mSocket = MyDevice.createRfcommSocketToServiceRecord(uuid); } catch (IOException e) { Toast.makeText(this, "S", Toast.LENGTH_SHORT).show(); } ba.cancelDiscovery(); try { mSocket.connect(); } catch (IOException e){ Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); Log.e("YOUR_APP_LOG_TAG1", "I got an error", e); } try { mOutputStream = mSocket.getOutputStream(); mInputStream = mSocket.getInputStream(); } catch (IOException e) { Toast.makeText(this, "io", Toast.LENGTH_SHORT).show(); } 

But I get an error in the mSocket.connect () line.

Mistake:

reading failed socket can be closed or timeout read ret

Please, help.

+8
android bluetooth arduino
source share
1 answer

This can be caused by many things - in my case, I found three:

  • Power problems - HC-05 was not stable, even through it it did not show with a noticeable blinking LED pattern. Replacing the battery fixed it.

  • Another device was paired with the HC-05 and sometimes โ€œstoleโ€ the connection. Maybe fixed by some settings using AT commands, but I just just didnโ€™t pair everything except one device.

  • The device is off / out of range.

-2
source share

All Articles