1

I'm struggling with the problem with Bluetooth. I wrote an App that received data from ELM 327 Bluetooth Interface, and when I use Bluetooth Terminal App I received "clean" data like

127 00 00 00 00 00 00 0D

But when I'm using my app then I received something like this. enter image description here

I don't know how to get rid of this question marks and what the heck is this? Also the message contains something like

{ When=0 what=0 obj=n}

Also how to get rid of this?

Bellow is my code and I will be very very great full for your help..

 private class MyHandler extends Handler {

    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
         Intent sendIntent = new Intent();

        if (msg.what == handlerState) {



            recDataString.append(msg);

            Log.d("tablica", String.valueOf(recDataString));

            int startOf = recDataString.indexOf("176");
            int endOf = recDataString.indexOf("<");

            if (recDataString.length() > 23) {

                String stringMessage = String.valueOf(recDataString);

                if (stringMessage.contains(" ")) {

                    stringMessage = stringMessage.replace(" ", "");

                    //Log.d("spacje", stringMessage);
                    int lengthOfString = stringMessage.length();
                        if(stringMessage.contains("176")) {


                            stringMessage = stringMessage.substring(startOf-3, startOf+17);
                                Log.d("spacje", stringMessage);

                        }
              }


            }

            recDataString.delete(0, recDataString.length());


        }

    }
}

And this is run method

@Override
    public void run() {
        super.run();

        byte[] mmBuffer = new byte[1024];

        int mmBytes = 0;
        int begin = 0;

        while (true) {

            try {

                mmBytes += mmInStream.read(mmBuffer, mmBytes, mmBuffer.length - mmBytes);


                for (int i = begin; i < mmBytes; i++) {



                    if ( mmBytes > 13 ) {

                        mmBuffer[i] += ">".getBytes()[0];

                        String wiadomosc = new String(mmBuffer);


                        Message msg = new Message();

                        msg.obj = wiadomosc;

                        h.sendMessage(msg);

                        if (i == mmBytes - 1) {
                            mmBytes = 0;
                            begin = 0;


                        }

                        mmBytes = 0;
                    }
                }

            } catch (IOException e) {

                e.printStackTrace();
                Toast.makeText(getBaseContext(), "Input stream was disconnected", Toast.LENGTH_LONG).show();
                break;

            }



        }

}

I'm struggling with this problem couple of days and I have no idea how to solve this. Also this methods are inside the Service. Thant you for your help

Matt199
  • 264
  • 2
  • 18

0 Answers0