I am trying to connect to a ELM327 device via bluetooth. The library I am using:
https://github.com/eltonvs/java-obd-api
Establishing a bluetooth connection works fine and I can reset the device:
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(deviceAddress);
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
final BluetoothSocket socket;
try {
socket = device.createInsecureRfcommSocketToServiceRecord(uuid);
socket.connect();
Log.d("xx", "1. Reset");
ObdResetCommand obdResetCommand = new ObdResetCommand();
obdResetCommand.run(socket.getInputStream(), socket.getOutputStream());
System.out.println(obdResetCommand.getFormattedResult());
Log.d("xx", "2. Echo Off");
EchoOffCommand echoOffCommand = new EchoOffCommand();
echoOffCommand.run(socket.getInputStream(), socket.getOutputStream());
System.out.println(echoOffCommand.getFormattedResult());
Log.d("xx", "3. LineFeed Off");
LineFeedOffCommand lineFeedOffCommand = new LineFeedOffCommand();
lineFeedOffCommand.run(socket.getInputStream(), socket.getOutputStream());
System.out.println(lineFeedOffCommand.getFormattedResult());
}
Output:
D/xx: 1. Reset
I/System.out: ELM327v1.5
D/xx: 2. Echo Off
I/System.out: OK
D/xx: 3. LineFeed Off I/System.out: OK
The part that is not working is to select the protocol and read a voltage value:
SelectProtocolCommand selectProtocolCommand = new SelectProtocolCommand(ObdProtocols.AUTO);
try {
selectProtocolCommand.run(socket.getInputStream(), socket.getOutputStream());
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
ModuleVoltageCommand moduleVoltageCommand = new ModuleVoltageCommand();
try {
moduleVoltageCommand.run(socket.getInputStream(), socket.getOutputStream());
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
What I observe is that the protocol selection is finished very quickly without any output. When I compare the protocol selection part to other apps like "torque lite", this takes much longer and I see flashing lights on my ELM327 device, which is not the case when running my code.
The ModuleVoltageCommand crashes then with:
br.ufrn.imd.obd.exceptions.UnableToConnectException: Error running Control Module Power Supply [01 42], response: ...UNABLETOCONNECT
I verified the dongle is working with other apps, so this must be an issue with my code.
What am I doing wrong?