2
votes

I have a Bluetooth OBDII dongle for my car (the brand is Veepeak), and I'm trying to write a Windows app that can communicate with it. So far it seems that I'm able to connect to the device from my laptop, send commands, and receive some sort of response, but the responses I receive are not what I expect. I am using the 32feet communication library to handle the Bluetooth stuff.

Here is the code I am using to connect and also the functions I am using to send messages:

BluetoothClient client;
Stream stream;
client = new BluetoothClient();
Guid uuid = new Guid("00001101-0000-1000-8000-00805f9b34fb");
client.BeginConnect(SelectedDevice.DeviceAddress, uuid, bluetoothClientConnectCallback, client);

private void bluetoothClientConnectCallback(IAsyncResult result)
{
        client = (BluetoothClient)result.AsyncState;
        client.EndConnect(result);
        clientConnected = true;
        stream = client.GetStream();
        UIWriteLine("Client connected");
}

private string sendMessage(string message)
{
        byte[] encodedMessage = Encoding.ASCII.GetBytes(message);
        stream.Write(encodedMessage, 0, encodedMessage.Length);
        Thread.Sleep(100);
        int count = 0;
        byte[] buffer = new byte[1024];
        string retVal = string.Empty;
        count = stream.Read(buffer, 0, buffer.Length);
        retVal += Encoding.ASCII.GetString(buffer, 0, count);
        return retVal.Replace("\n", "");
}

private string getValue(string pid)
{
        byte[] encodedMessage = Encoding.ASCII.GetBytes(pid + "\r");
        stream.Write(encodedMessage, 0, encodedMessage.Length);
        Thread.Sleep(100);
        bool cont = true;
        int count = 0;
        byte[] buffer = new byte[1024];
        string retVal = string.Empty;
        while (cont)
        {
            count = stream.Read(buffer, 0, buffer.Length);
            retVal += Encoding.ASCII.GetString(buffer, 0, count);
            if (retVal.Contains(">"))
            {
                cont = false;
            }
        }
        return retVal.Replace("\n", "");
}

I use the sendMessage method to send AT commands, and the getValue method to get a specific PID (these methods are borrowing code from an OBDII library I found here).

When I send AT commands, I seem to only get an echo of whatever I send, and when I send PIDs, I get a response of a single question mark, which to my understanding means the command is invalid.

Is it possible that my dongle does not have an ELM327? Am I doing something wrong with my Bluetooth communication or is my UUID wrong? Thanks.

1
I'd recommend you use a tool like realterm (or any other com port terminal) on your PC to first validate that the device acting properly. And verify that what you're device is. There are elm327 commands to query the device description AT@1Jon
Thanks, I've now used a com terminal to determine that what I have is an ELM327v1.5 and it seems to be working properly. Can I send messages through the Bluetooth stream directly or do I have to open a serial port to communicate?Connor Szczepaniak

1 Answers

0
votes

I also have a Veepeak. It comes quite highly recommended in the relevant reviews and works very well with the available trial apps and my android phone. I'm struggling with initialization in my own python app, however.

On the python based application that I'm developing on the raspi, I have to open a 'virtual' serial port that is mapped to the previously paired device by it's mac address. The pairing and noting of the mac address is done at the operating system level with generic bluetooth tools.