Git Product home page Git Product logo

androidobd's Introduction

AndroidOBD CI API

Android OBD Library

What is this repository for?

This project offers a developer friendly interface to communicate with ELM 327 OBD devices via BLUETOOTH.

Usage

Add Dependency:

implementation 'com.pnuema.android:obd:1.5.0'

To get started you will need to first send a few commands over bluetooth or usb whatever the input stream is that you negotiate with the ELM-327 device.

Connection and init:

val MODE_AT = "AT"

//set defaults
initPid.mode = MODE_AT
initPid.PID = "D"
var cmd = OBDCommand(initPid).setIgnoreResult(true).run(inputStream, outputStream)
Log.d(TAG, "Set defaults sent (" + initPid.mode + " " + initPid.PID + ") Received: " + cmd.rawResult)

//resets the ELM327
initPid.mode = MODE_AT
initPid.PID = "Z"
cmd = OBDCommand(initPid).setIgnoreResult(true).run(inputStream, outputStream)
Log.d(TAG, "Reset command sent (" + initPid.mode + " " + initPid.PID + ") Received: " + cmd.rawResult)

//extended responses off
initPid.mode = MODE_AT
initPid.PID = "E0"
cmd = OBDCommand(initPid).setIgnoreResult(true).run(inputStream, outputStream)
Log.d(TAG, "Extended Responses Off (" + initPid.mode + " " + initPid.PID + ") Received: " + cmd.rawResult)

//line feeds off
initPid.mode = MODE_AT
initPid.PID = "L0"
cmd = OBDCommand(initPid).setIgnoreResult(true).run(inputStream, outputStream)
Log.d(TAG, "Turn Off Line Feeds (" + initPid.mode + " " + initPid.PID + ") Received: " + cmd.rawResult)

//printing of spaces off
initPid.mode = MODE_AT
initPid.PID = "S0"
cmd = OBDCommand(initPid).setIgnoreResult(true).run(inputStream, outputStream)
Log.d(TAG, "Printing Spaces Off (" + initPid.mode + " " + initPid.PID + ") Received: " + cmd.rawResult)

//headers off
initPid.mode = MODE_AT
initPid.PID = "H0"
cmd = OBDCommand(initPid).setIgnoreResult(true).run(inputStream, outputStream)
Log.d(TAG, "Headers Off (" + initPid.mode + " " + initPid.PID + ") Received: " + cmd.rawResult)

//set protocol
initPid.mode = "$MODE_AT SP"
initPid.PID = ObdProtocols.AUTO.value.toString()
cmd = OBDCommand(initPid).setIgnoreResult(true).run(inputStream, outputStream)
Log.d(TAG, "Select Protocol (" + initPid.mode + " " + initPid.PID + ") Received: " + cmd.rawResult)

//set timeout for response from the ECU
initPid.mode = "$MODE_AT ST"
initPid.PID = Integer.toHexString(0xFF and ECU_RESPONSE_TIMEOUT)
cmd = OBDCommand(initPid).setIgnoreResult(true).run(inputStream, outputStream)

Once a connection has been established and inited you can send commands and get responses as follows:

Code:

//Request MODE 1, PID 0C - RPM
val pid = PIDUtils.getPid(ObdModes.MODE_01, "OC")
val command = OBDCommand(pid)
command.run(bluetoothSocket.inputStream, bluetoothSocket.outputStream)

Log.d("PID", "${pid.description} : ${pid.calculatedResult}")
Log.d("PID Formatted Result", command.formattedResult)
//Clear DTCs - NonPermanent
val pid = PID(ObdModes.MODE_04) //Clear DTCs
val command = OBDCommand(pid)
command.run(bluetoothSocket.inputStream, bluetoothSocket.outputStream)

Note that you do not have to take the raw values and calculate it yourself. The library will run the value through the formula that are specified in the specifications for CAN to get the resulting value. This is available in the calculatedResult and formattedResult fields on the pid after the pid.run(...) command finishes.

Who do I talk to?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.