0
votes

Current I am working on OBDII. While in bluetooth discovery to connect obd, How I determine which device is obd and which device is normal bluetooth device.Because I want auto connect my app with obd.

Is there any common characteristic of obd device which help me to determine this is OBD device?

My Code which I am trying for pairing obd device as per name.

//Register receiver for bluetooth discovery
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {

    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
            //discovery starts, we can show progress dialog or perform other tasks
        } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            //discovery finishes, dismiss progress dialog
        } else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            //bluetooth device found for pair
            try {
// Here I want to know device is obd or not?
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                //Make pair of obd device as per name:
                if (device != null && !device.getName().equals("")) {
                    LogUtils.LOGE("NEW DEVICE", device.getName());
                    if (device.getName().equals(OBD_DEVICE_NAME_ONE) ||
                            device.getName().equals(OBD_DEVICE_NAME_TWO) ||
                            device.getName().equals(OBD_DEVICE_NAME_THREE)) {
                        pairDevice(device);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
};

//Send pairing request to OBD Device
private void pairDevice(BluetoothDevice device) {
    try {
        Method method = device.getClass().getMethod("createBond", (Class[]) null);
        method.invoke(device, (Object[]) null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

After Pairing OBD Device with name, It will autoconnect and work fine.

1

1 Answers

0
votes

Only good way to find out, is to connect and to send:

ATI

Which will return a ID, which always contain ELM327.