0

I have searched this and other sites, have tried many different suggestions, but it seems that I'm stuck now with my try-and-error approach. Here is the simple code with which I have tried the following things on my Android HTC Desire X (Jelly Bean) in order to connect to my OBDII Bluetooth adapter (called "super OBD"):

1) Using the sample from http://developer.android.com/guide/topics/connectivity/bluetooth.html

public class BTConnector {
private final UUID MY_UUID = UUID.randomUUID();  // our applications UUID for BT
    // but recommended by <http://www.socialledge.com/sjsu/index.php?title=F12:_OBD-II_Android_Monitor>
    // UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");  

public void setupBluetoothCommunication() {
   BluetoothAdapter mBluetoothAdapter = null;
   BluetoothDevice mBluetoothDevice = null;

   // Step_1: Get BluetoothAdapter
   mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
   if (mBluetoothAdapter == null) {
     // Device does not support Bluetooth
   }
   // Step_2: Enable Bluetooth
   if (!mBluetoothAdapter.isEnabled()) {
      // Request the default Android Settings dialog to start for enabling BT
      // done manually for now
   }
   // Step_3: Find our to be paired device (e.g. OBDII device)
   Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
   if (pairedDevices.size() > 0) {
      for (BluetoothDevice device : pairedDevices) {
         if (device.getName().compareToIgnoreCase("OBDII") == 0) {
            mBluetoothDevice = device; // Found our device
         }
      }
   }

  // 3b. OPTIONAL: Discover devices
  // Step_4: Connecting to the device
  BluetoothSocket mmSocket = null;
   // 1) Using suggested Bluetooth socket -> is not workin
   // mmSocket = mBluetoothDevice.createRfcommSocketToServiceRecord(MY_UUID);
   // mmSocket.connect();
   // UUID.fromString("00001101-0000-1000-8000-00805F9B34FB") causes IOException: Unable to start Service Discovery
   // UUID.randomUUID() causes IOException: Service discovery failed

   // 2) Using suggestion from <http://stackoverflow.com/questions/12384833/android-bluetooth-software-caused-connection-abort> can possibly connect:
  Method m = null;
  m = mBluetoothDevice.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
  mmSocket = (BluetoothSocket) m.invoke(mBluetoothDevice, 1);

  OutputStream tmpOut = null; 
  // Get the input and output streams, using temp objects because member streams are final
  tmpOut = mmSocket.getOutputStream();
  OutputStream mmOutStream = tmpOut;

  // Write out data      
  String ati_command = "ATZ" + "\r";  // also tried: "ATZ\\r", "ATSP0\r" , "ATI\r", or bytes: speed = "010D\r", temp = "0105\r"
  mmOutStream.write(ati_command.getBytes());  // THROWS IOEXCEPTION "Software Caused Connection Abort"
     ...
  }
  ...
}

I tried different Android software:

Does this information give a hint? I'm really looking forward for some tips.

Thank you very much in advance!

S F
  • 11
  • 1
  • 4
  • Try the following code: UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(uuid); socket.connect(); Also you can get acquainted with my article just about what are you trying to do here: http://blog.lemberg.co.uk/how-guide-obdii-reader-app-development – Ruslan Yanchyshyn Jul 25 '14 at 08:59
  • I also have the same problem. Did you manage to find a solution eventually? – sthor69 Dec 05 '14 at 08:41

0 Answers0