0

I am working on an android application which has to connect to OBD II ELM327 device via Bluetooth and has to get data(rpm, speed.. etc) from car.. Able to connect via bluetooth but Not sure how to write a code for communication ... Can anyone help me on this or if have code for this please share ?

user3832506
  • 63
  • 1
  • 4

1 Answers1

0

Bluetooth devices send and receive data as byte arrays. Although Android offers plenty of support for connecting to bluetooth devices and sharing information using BluetoothGatt, you will ultimately have to provide your own algorithm to interpret the byte[] data sent by the device and to construct a byte[] response in a format that the device can understand.

Check to see if the manufacturer of your obdII device provides an existing library for encoding and decoding byte[] data that you can use to communicate with the device. If no library exists, at the very least you will need to figure out how the device interprets information and implement your own encoding and decoding algorithm.

tep
  • 823
  • 7
  • 13
  • Do you have any sample code for communication with OBD2- ELM327? I am not sure how to write algorithm for this. – user3832506 Jul 13 '14 at 03:46
  • Have you seen this [list of ELM327 commands](http://www.elmelectronics.com/ELM327/AT_Commands.pdf)? What you will need to do is initiate a connection with your device using a [BluetoothGattServer] (https://developer.android.com/reference/android/bluetooth/BluetoothGattServer.html), and call it's `[sendResponse()]` (https://developer.android.com/reference/android/bluetooth/BluetoothGattServer.html#sendResponse(android.bluetooth.BluetoothDevice, int, int, int, byte[])) method when you receive a command prompt from your device as described in the documentation. – tep Jul 13 '14 at 14:45
  • You then send your command as a byte[], where each byte represents exactly one ASCII character. If you are unsure of how to do this, check out this thread: http://stackoverflow.com/questions/472906/converting-a-string-to-byte-array?rq=1 – tep Jul 13 '14 at 14:49
  • @tep...started working on this.. If find difficulty, I'll post here for further help..Thanks a lot. – user3832506 Jul 15 '14 at 17:26