title: BluetoothChat-to-ELM327 split response message
body: <p>I am attempting to communicate with an ELM327 OBDII Bluetooth dongle using the Android BluetoothChat example. I can connect to the device without any trouble, and messages from BluetoothChat to the ODBII device seem to be transmitted and received by the device correctly.</p>
  
  <p>However, the response messages from the OBDII device are often split into several messages, scrambled, or missing characters.</p>
  
  <p>For example, it takes three tries of the <code>ati</code> command to receive the full expected response:
  <code>
  Me: ati
  OBDII: a
  OBDII: 327
  OBDII: 327
  OBDII: 327 v1.5 &gt;
  Me: ati
  OBDII: 1
  OBDII: 1
  OBDII: 1.5 &gt;v
  OBDII: 1.5 &gt;
  Me: ati
  OBDII: ELM327 v1.5 &gt;
  </code></p>
  
  <p>Similarly, sending <code>010c</code> should trigger a one line response containing three hex pairs. Instead, I usually (but not always) get results like the following:
  <code>
  Me: 010c
  OBDII: 
  OBDII: 4
  OBDII: 3C
  OBDII: 3
  OBDII: 3C C
  OBDII: 3C
  OBDII: 
  OBDII: 
  OBDII: &gt;
  </code></p>
  
  <p>I have tried several different baud rates and different OBDII protocols, but changes from the default settings only seem to make matters worse. <strong>Is there a problem with my response message handling? Why is the response message splitting?</strong> The Bluetooth dongle works properly with available apps such as Torque, so I don't think the device is malfunctioning.</p>
  
  <p>The code that I'm using is almost identical to the BluetoothChat project (source <a href="https://android.googlesource.com/platform/development/+/25b6aed7b2e01ce7bdc0dfa1a79eaf009ad178fe/samples/BluetoothChat/src/com/example/android/BluetoothChat" rel="nofollow noreferrer">here</a>). I have only modified the UUID for my Bluetooth device and added a carriage return to the outgoing message (as per this StackOverflow <a href="https://stackoverflow.com/questions/11400083/using-bluetoothchat-to-communicate-with-elm327?answertab=active#tab-top">question</a>).</p>
  
  <p>Change 1 (in BluetoothChatService.java):</p>
  
  <pre><code>    // Unique UUID for this application
  private static final UUID MY_UUID_SECURE =
      //UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66");
      UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
  private static final UUID MY_UUID_INSECURE =
      //UUID.fromString("8ce255c0-200a-11e0-ac64-0800200c9a66");
      UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
  </code></pre>
  
  <p>Change 2 (in BluetoothChat.java):</p>
  
  <pre><code>    // The action listener for the EditText widget, to listen for the return key
  private TextView.OnEditorActionListener mWriteListener =
      new TextView.OnEditorActionListener() {
      public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
          // If the action is a key-up event on the return key, send the message
          if (actionId == EditorInfo.IME_NULL &amp;&amp; event.getAction() == KeyEvent.ACTION_UP) {
              String message = view.getText().toString();
              //sendMessage(message);
              sendMessage(message + "\r");
          }
          if(D) Log.i(TAG, "END onEditorAction");
          return true;
      }
  };
  </code></pre>
  
  <p><a href="http://elmelectronics.com/DSheets/ELM327DS.pdf" rel="nofollow noreferrer">ELM327 manual for reference</a></p>