OBD ll Elm327

582 views
Skip to first unread message

Влад Киселев

unread,
Mar 10, 2016, 9:49:51 AM3/10/16
to DroidScript
Hello guys. I had the idea to write an application for vehicle diagnostics via bluetooth elm327 adapter. can someone that is thought to get you started? how to teach the application to receive signals on the bluetooth with this adapter? and whether it is generally done? Thank you

Gerard Hernandez

unread,
Mar 10, 2016, 12:25:57 PM3/10/16
to DroidScript
First you need to take a look on the protocol used by the device

Now, you can create a BluettothSerial control using the device name and you will also need to set the break character, that is to determine when the serial port need to report its content back to the app. Thats why you need to take a look into the protocol.

Then youll need to process the actual data, what are headers, what is info, and so on, At whill be handle in the OnDataReceived callback.

Also you need to have some methods to send the commands to the device.

using the BTSerial you wont need to implement the entire BT chat on your own ( thats a lot) and you'll be more interested in the actual data management.

By the way, if you have already working the background service, BT serial can work there, that way your app can still use the BT even if is not in the forefront.

Влад Киселев

unread,
Mar 10, 2016, 1:41:31 PM3/10/16
to DroidScript
OBD 2 protocol as I understand it. and where you can take a look at him?

Влад Киселев

unread,
Mar 10, 2016, 3:27:52 PM3/10/16
to DroidScript
but no, it turns out the protocol ISO 9141-2
generally found something
http://blog.lemberg.co.uk/how-guide-obdii-reader-app-development
Please tell me if this is possible as that implemented in the DS?

Dave Smart

unread,
Mar 11, 2016, 7:03:25 AM3/11/16
to DroidScript
Yes, I think you should be able to develop an app using DroidScript quite easily.  Most of the hard work has been done for you by the DroidScript team, you will just need to find some examples of using the protocol over Bluetooth serial.  

You can also search this forum for other bluetooth serial projects and discussions which will help you get started.  You can change the BT channel if required too.

Влад Киселев

unread,
Mar 11, 2016, 8:15:12 AM3/11/16
to DroidScript
https://github.com/pires/android-obd-reader
help as it is done in DS ?? how to connect OBD Java api?

Gerard Hernandez

unread,
Mar 11, 2016, 3:33:40 PM3/11/16
to DroidScript
The serial port is nothing else but a data stream that works in 2 directions. as Dave said, all hard work is done for you, you you need to Pair the module to your Phone/Tablet/Board first, then connect using the name, also need to define the END character, that will trigger the OnReceive method. after taht you can start sending and receiving RAW data, as in old C, a string is a char array, and arrays are usually used to create BUFFERS.

If you want to implement a Java API youll need to write a Java Plugin by yourself, and Im 100% sure is something that you dont need.

Whatyou can do is to create a Library to do the same thing, keep this in mind, Serial commands are nothing else TEXT, so you can do it in JS with no trouble.

I took a look into the link you send and is quite simple to implement

The first step is very specific to each device ( BT Device Name)
The second is specific for the protocol the ELM uses, I have used some chips where I use "\n".

A code example may be: (This is heavily based in the BT serial sample)

There is a little thing taht concerns me and is that in the JAVA Api they send a command and read the response, in DS you cannot do that (currently) because its a event based api. You need to check if the response is the plain value or if its contained in some wrapper that allows you to determine what the command was.
elm327 = app.CreateBluetoothSerial();
elm327
.SetOnReceive(elm327DataReceived);
elm327
.SetSplitMode("End","\r"); // change the character to match the ELM protocol, example uses "\n"
elm327
.Connect("ELMXXXX"); //This name is not the MAC, but the name you can look in the BT Settings > paired devices

function elm327DataReceived(data) {
// TODO process the info
}

function sendToElm327(data) {

elm327
.Write(formatElmData(data));
}

function formatElmData(data) {
return data + "\r";
}

function SendSpeedCommand(){
sendToElm327
(01 0D);
}

Message has been deleted

Gerard Hernandez

unread,
Mar 11, 2016, 3:41:04 PM3/11/16
to DroidScript
If you feel comfortable with Arduinos, you can take a look in this library and use it a base for your new JS library

Влад Киселев

unread,
Mar 12, 2016, 4:17:33 AM3/12/16
to DroidScript
Thank you very much for your help! please tell me, how did you know that to get the speed you need to send (01 0D) ?? where the list of teams that I could not find it (and again, because there is a need to initialize the adapter. What teams are needed for this?

Влад Киселев

unread,
Mar 12, 2016, 11:21:49 AM3/12/16
to DroidScript
I tried like this, the adapter is connected, but the output does not come (apparently necessary to pass initialization, as stated in that article. Only some of the team Need daughter?

//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
btn2 = app.CreateButton( "подключить" );
btn2.SetOnTouch( conne);
lay.AddChild( btn2 );
//Create a text label and add it to layout.
btn = app.CreateButton( "speed" );
btn.SetOnTouch( SendSpeedCommand );
lay.AddChild( btn );
txxt = app.CreateTextEdit("",0.8,0.1 );
lay.AddChild( txxt );
btn3 = app.CreateButton( "new command" );
btn.SetOnTouch( newcommand );
lay.AddChild( btn3 );

elm327 = app.CreateBluetoothSerial();
elm327.SetOnReceive(elm327DataReceived);
elm327.SetSplitMode("End","\r"); // change the character to match the ELM protocol, example uses "\n"
//This name is not the MAC, but the name you can look in the BT Settings > paired devices
elm327.SetOnConnect( con );
app.AddLayout( lay );
}

function newcommand()
{
sendToElm327(txxt.GetText());
}

function conne()
{
elm327.Connect("OBDII");
}

function con(ok)
{
if(ok)
app.ShowPopup( "connection" );
else
app.ShowPopup( "no connection" );
}

function elm327DataReceived(data) {

app.ShowPopup( data );

Gerard Hernandez

unread,
Mar 12, 2016, 4:01:52 PM3/12/16
to DroidScript
The link you shared  https://github.com/pires/android-obd-reader
list within its Prerequisites this OBD Java Api
I was looking in the first but I couldnt find any command, so I looked into the paths and find that I need to look into that.
Also I took a look into the commands implementation and I found that when you create the command you set a specific set of bytes, that will vary depending on the command. 

I would rather take a deep look into the second link and also the one I shared for arduino. So you can get a more clear idea of what is needed. The original post is more on the idea of an unage of the API rather than the actual implementation.
Reply all
Reply to author
Forward
0 new messages