Hi, I'm trying to send data from an android phone to an arduino via an hc-05 when I make the first send after restarting the arduino the transmission works correctly but the following transmissions generate the following log:
02-12 20: 03: 56.676 8370-8915 / com.oscar.mandocanarval W / BluetoothAdapter: getBluetoothService () called with no BluetoothManagerCallback 02-12 20: 04: 01.839 8370-8915 / com.oscar.mandocanarval W / System.err: java.io.IOException: read failed, socket might closed or timeout, read ret: -1 02-12 20: 04: 01.845 8370-8915 / com.oscar.mandocanarval W / System.err: at android.bluetooth.BluetoothSocket.readAll (BluetoothSocket.java:741) 02-12 20: 04: 01.845 8370-8915 / com.oscar.mandocanarval W / System.err: at android.bluetooth.BluetoothSocket.readInt (BluetoothSocket.java:753) 02-12 20: 04: 01.846 8370-8915 / com.oscar.mandocanarval W / System.err: at android.bluetooth.BluetoothSocket.connect (BluetoothSocket.java:375) 02-12 20: 04: 01.847 8370-8915 / com.oscar.mandocanarval W / System.err: at com.oscar.mandocanarval.HiloConexionCliente.run (HiloConexionCliente.java:47) 02-12 20: 04: 20,764 8370-9328 / com.oscar.mandocanarval W / BluetoothAdapter: getBluetoothService () called with no BluetoothManagerCallback
My shipping code is as follows:
public class HiloConexionCliente extends Thread {
UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
String mensaje;
public final BluetoothDevice dispositivo;
public BluetoothSocket socket;
private OutputStream conexionSalida;
public HiloConexionCliente(String direccion, String mensaje){
this.mensaje=mensaje;
BluetoothDevice tmpDevice;
BluetoothSocket tmpSocket=null;
BluetoothAdapter adaptador = BluetoothAdapter.getDefaultAdapter();
adaptador.cancelDiscovery();
tmpDevice = adaptador.getRemoteDevice(direccion);
dispositivo = tmpDevice;
try {
tmpSocket= dispositivo.createRfcommSocketToServiceRecord(MY_UUID);
socket=tmpSocket;
socket=tmpSocket;
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void run() {
try {
if(socket!=null){
socket.connect();
conexionSalida=socket.getOutputStream();
conexionSalida.write(mensaje.getBytes());
close();
}
} catch (IOException e) {
close();
e.printStackTrace();
}
super.run();
}
public void close(){
try {
if(socket!=null){
socket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
And the arduino code only reads a virtual serial port and shows it through the serial monitor