I am currently trying to communicate with an ELM327 OBDII bluetooth dongle via the BluetoothChat Sample Application. I am able to connect as I have changed the UUID, however
The fact that the characters are being correctly echo'd back probably indicates that the baud rate is set correctly and the device is seeing the characters you want. It sounds, though, like the device is still not seeing a properly terminated request string (one that ends with a carriage return).
I mention this because you noted appending "/r", which is not the same thing as "\r" (the CR character). For example, in Java:
OutputStream out;
String correct = "ATRV\r";
//This line will correctly write 5 bytes (in hex): 41 54 52 56 0D
out.write(correct.getBytes());
String incorrect = "ATRV/r";
//This line will incorrectly write 6 bytes (in hex): 41 54 52 56 2F 72
out.write(incorrect.getBytes());
The 0x0D character is what the ELM327 is looking for to terminate the AT command and parse it.
Edit:
If you are manually typing the characters "atrv\r" using your keyboard into a sample application, the same problem exists. The text is being interpreted as 6 unique letters (i.e. 'A', 'T', 'R', 'V', '\', and 'r' or hex 41 54 52 56 5C 72
) and the '\r' is not interpreted as a single CR character.
You will likely not be able to do this from your sample code unless you add some special code to parse out combinations with '\' and replace them with their special character values. A better solution would be to modify the sample code to always append the '\r' character (remember...different from simply adding a '\' followed by an 'r') to anything you type when you hit the send button so you only have to type "ATRV" in the text box. Something like this in your OnEditorActionListener
code (again, note the direction of the slash or you'll just add two characters):
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 && event.getAction() == KeyEvent.ACTION_UP) {
//This gets the raw text from the box
String message = view.getText().toString();
//Append a CR to every message sent. The added string is defined as a literal,
// so Java parses is as a single CR character.
sendMessage(message + "\r");
}
if(D) Log.i(TAG, "END onEditorAction");
return true;
}
You could also modify your sample by hard-coding the string command as I have in the example above. Java interprets the String literal value "ATRV\r" correctly, placing that CR character at the end (making this a 5 character string).