kai-morich / SimpleBluetoothTerminal

Android terminal app for Bluetooth classic devices using SPP profile
MIT License
447 stars 166 forks source link

Read Failed #10

Closed anupamjuit closed 4 years ago

anupamjuit commented 4 years ago

simple_bluetooth_terminal D/BluetoothSocket: close() this: android.bluetooth.BluetoothSocket@f5058ae, channel: 1, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@4cef64f, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@b4521dcmSocket: android.net.LocalSocket@8e8a2e5 impl:android.net.LocalSocketImpl@c2ea86b fd:java.io.FileDescriptor@4f07fc8, mSocketState: INIT

I am getting this error. And in the mobile window, I am getting: connecting....connection failed: read failed, socket might closed or timeout, read ret: -1

Help please

kai-morich commented 4 years ago

bluetooth communication sometimes fails with strange errors. No additional details are reported by Android libraries, so I also do not know the root cause. Typically it works when you try again, pair again, reboot devices, ...

anupamjuit commented 4 years ago

Thank you for your responce.

anupamjuit commented 4 years ago

Hi! I found something like this: When I try to connect with Developer Sample Bluetooth Cat Application it's only connecting with an insecure socket, and by changing the UUID for insecure one it works. look in this matter.

kai-morich commented 4 years ago

are you talking about bluetooth classic (this repo) or bluetooth LE (my SimpleBluetoothLETerminal repo)? UUID looks more like Bluetooth LE

anupamjuit commented 4 years ago

I am working with classici one. private static final UUID BLUETOOTH_SPP = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

BlutoothSampleChatService using this: // Unique UUID for this application private static final UUID MY_UUID_SECURE = UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66"); private static final UUID MY_UUID_INSECURE = UUID.fromString("8ce255c0-200a-11e0-ac64-0800200c9a66");

try { if (secure) { tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE); } else { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord( NAME_INSECURE, MY_UUID_INSECURE); } }

In this sample (https://github.com/android/connectivity-samples/tree/master/BluetoothChat/#readme) I am able to connect. But only with Connect a device-Insecure mode.

kai-morich commented 4 years ago

this app uses the Bluetooth Serial Port Profile where createRfcommSocketToServiceRecord is the right method. As you are using different UUID you might also have to use different methods.