0

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?

Alex Tbk
  • 2,042
  • 2
  • 20
  • 38

1 Answers1

0

I'm the creator of this library, thanks for using my project!

This is an issue with the ECU, when you change the protocol, the next command will usually fail. What I usually do is sending a dump command that's expected to fail (so you just ignore any raised exception for this command) and then I send the commands I really want to run.

Hope it solves your issue!

Elton Viana
  • 171
  • 1
  • 7
  • Thank you! I will evaluate this. This was failing on a simulated ecu on a pc - I would expect it to response correctly – Alex Tbk Feb 17 '20 at 13:28