EricSmekens / node-bluetooth-obd

Node package for communication with Bluetooth OBD connectors.
Other
262 stars 72 forks source link

Returned data from OBD split up into chunks #16

Closed chris-munn closed 8 years ago

chris-munn commented 8 years ago

Hi Eric,

Amazing library really getting to grips with it, however there is one strange issue I'm having. I have adapted the code to work in a hybrid app but whenever I send a command to the OBD device it returns the data in an inconsistent chunk of results, example:

Me: 010C OBDII: OBDII: 4 OBDII: 3C OBDII: 3 OBDII: 3C C OBDII: 3C OBDII: OBDII: OBDII: >

It is a similar issue to this stackoverflow post: http://stackoverflow.com/questions/25374953/bluetoothchat-to-elm327-split-response-message

Although the solution there appears to be in Java.

I have a work around where I loop over the results adding the relevant parts together then when i receive a ">" command I stop as i know its finished.

Have you ever come across this before?

Thanks again for the library and any help,

Chris

EricSmekens commented 8 years ago

Does this always happen? And what does it return if you send 010C1?

chris-munn commented 8 years ago

Hi Eric,

I had already tried 010C1 one to no avail...

However today I realised that once connected to the OBD device I wasnt sending all of the AT commands as per your obd.js, I now send all of the commands and it now comes back on one line, hey presto!

I had already stopped echos and spaces etc but guess it must have been removing headers? Or one of the other commands I wasnt sending.

Thank you for help, I will monitor the responses to make sure it's not the OBD device just having a funny 5 minutes every so often.

Regards,

Chris

EricSmekens commented 8 years ago

Must have been

        self.write('ATZ');
        //Turns off extra line feed and carriage return

in combination with the headers as you say.

Will close this issue for now then, but feel free to comment/open when you have found something else/more.

chrismunn192 commented 8 years ago

Hi Eric,

I'm not sure what changed but its happening again I have spent a good couple of days trying to work this one out but am banging my head against a brick wall :(

I'm trying to determine whether it is a problem with the cordova plugin I am using and the way they setup the socket, if it is the obd device itself or a problem with my code.

This is the cordova library: https://github.com/MobileChromeApps/cordova-plugin-chrome-apps-bluetoothSocket

and this is the api for chrome sockets: https://developer.chrome.com/apps/bluetoothSocket

As mentioned previously i can connect and get responses back but they are always split up or chunked so my response is something like...

OBDII: 41 OBDII: 0C 0 OBDII: 3 CC

It is always random how it sends it back.

I tried tinkering with the buffer options if i set the SocketProperties buffer size to 2 then they always come back split into two characters e.g. 0C then 00 if i set them to 32 then it is somewhere between 2 and 5 characters per response.

I am trying to speed the whole process up as i can currently only send one command per 600ms otherwise the next command interupts the previous and i get a STOPPED response from the OBD.

I read somewhere that i should be able to make a call every 50ms or thereabouts when i send a "1" after my command, but with the data coming back split up I think this is why I am stuck with 600ms per request.

chrismunn192 commented 8 years ago

Here is a snippett of my code

        chrome.bluetoothSocket.create(function(createInfo) {
          chrome.bluetoothSocket.connect(clientSocketId, $rootScope.btAddress, $rootScope.btTestUuid, function() {                
            chrome.bluetoothSocket.onReceive.addListener(function(info) {
                console.log('onReceive: ', ab2str(info.data));
            });
          });
        });

    chrome.bluetoothSocket.send(createInfoGlobal.socketId, str2ab( "010C1\r" ), function(result) {
      console.log("Sending Command...: ");
    });
EricSmekens commented 8 years ago

Did you test this with an existing OBD-II app, and can you try with a different ELM-OBD module? Just for some more information, so we can exclude some possible scenario's.

chris-munn commented 8 years ago

I have tried with another OBD device and same results I think it is due to the java wrapper which creates the chrome.bluetoothSocket.create for some reason it never returns a full string only chunks.

Unfortunately I'm not very good at Java so i have no idea what to look for within the cordova-plugin-chrome-apps-bluetoothSocket wrapper.

May have to chalk this one down as a no fixer due to it being with the other plugin :(