Giter VIP home page Giter VIP logo

Comments (9)

naevtamarkus avatar naevtamarkus commented on July 16, 2024

I have just found the cause of my problem: the sender was not finishing the transfer with a CR (newline)... so somehow the local (android's) bluetooth had the info, but did not delivered it to the upper layers.

Do you know where this limitation come from? Is it Android's limitation or is it the BluetoothSPP library? If it's the second, can this be parametrized/tuned? For example, on the Arduino side I look for a 0x00 character, but if it does not arrive it returns whatever is in the buffer after 0.1s without receiving data.

I guess the biggest problem is quite the opposite: what happens if I want to send a \n (CR) in the middle of the message, does it force a split in two different messages?

The second does not probably have a nice solution, but first one does.

Thanks!

from bluetoothspplibrary.

yanjingzhaisun avatar yanjingzhaisun commented on July 16, 2024

Hello naevtamarkus. Have you fixed the problem? Because I happened to meet the same problem with you.... Should I just send CR to the other device?

from bluetoothspplibrary.

naevtamarkus avatar naevtamarkus commented on July 16, 2024

No, the problem is not fixed AFAIK... but this has been clearly understood on Issue #13

from bluetoothspplibrary.

yanjingzhaisun avatar yanjingzhaisun commented on July 16, 2024

Thanks!

from bluetoothspplibrary.

msuzer avatar msuzer commented on July 16, 2024

I had a fix for this problem. Please read my comment on:

#30

from bluetoothspplibrary.

siddhpuraamitr avatar siddhpuraamitr commented on July 16, 2024

hi lazy21r, I have done what you have suggest like below

public void setOnDataReceivedListener (OnDataReceivedListener listener) {
            mDataReceivedListener = listener;
}
modify it:

public void setOnDataReceivedListener (OnDataReceivedListener listener) {
        if (mDataReceivedListener == null)
            mDataReceivedListener = listener;
}

but I am still not getting data, will you please help me what should be problem

I am getting below logs in LOGCAT

05-11 15:53:23.656 1968-1968/app.akexorcist.bluetoothspp D/Bluetooth Service: setState() 1 -> 2
05-11 15:53:23.659 1968-2611/app.akexorcist.bluetoothspp W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
05-11 15:53:23.745 1968-2149/app.akexorcist.bluetoothspp D/OpenGLRenderer: endAllStagingAnimators on 0xb36a9a00 (ListView) with handle 0xaec0fa50
05-11 15:53:24.694 1968-2611/app.akexorcist.bluetoothspp D/Bluetooth Service: setState() 2 -> 3
05-11 15:53:24.801 1968-2149/app.akexorcist.bluetoothspp V/RenderScript: 0xa09fe000 Launching thread(s), CPUs 4

from bluetoothspplibrary.

msuzer avatar msuzer commented on July 16, 2024

hi @siddhpuraamitr, it's been a while so I don't really remember all the project. please refer to my working source files first. If still no success, you could forward me your source files so i can give you a clue.

from bluetoothspplibrary.

vidyajejurkar avatar vidyajejurkar commented on July 16, 2024

lazy21tr:
Hi I am not able to send and recieve using setup().
I read ur comment to modify public void setOnDataReceivedListener (OnDataReceivedListener listener) {
mDataReceivedListener = listener;
}
modify it:

public void setOnDataReceivedListener (OnDataReceivedListener listener) {
if (mDataReceivedListener == null)
mDataReceivedListener = listener;
}
but I m not able to update coz I used library in build.gradle..How should I update it in my code.

from bluetoothspplibrary.

HardikPatelIVision avatar HardikPatelIVision commented on July 16, 2024

This worked for me
In BluetoothService.java
At line 358

Change this

ArrayList arr_byte = new ArrayList();
while (true) {
try {
int data = mmInStream.read();
if(data == 0x0A) {
} else if(data == 0x0D) {
buffer = new byte[arr_byte.size()];
for(int i = 0 ; i < arr_byte.size() ; i++) {
buffer[i] = arr_byte.get(i).byteValue();
}
mHandler.obtainMessage(BluetoothState.MESSAGE_READ, buffer.length, -1, buffer).sendToTarget();
arr_byte = new ArrayList();
} else {
arr_byte.add(data);
}
} catch (IOException e) {
connectionLost();
BluetoothService.this.start(BluetoothService.this.isAndroid);
break;
}
}

To

Log.e(BluetoothService.TAG, "BEGIN mConnectedThread");
byte[] buffer = new byte[1024];

        while (true) {
            int bytes = 0;
            try {
                bytes = this.mmInStream.read(buffer);
                if (bytes > 0) {
                    byte[] buf = new byte[bytes];
                    int i = 0;
                    while (i < bytes) {
                        buf[i] = buffer[i];
                        i++;
                    }
                    BluetoothService.this.mHandler.obtainMessage(2, bytes, -1, buf).sendToTarget();
                }
            } catch (IOException e) {
                Log.e(BluetoothService.TAG, "Error: "+e.getMessage());
                BluetoothService.this.start(BluetoothService.this.isAndroid);
                e.printStackTrace();
            }
        }

from bluetoothspplibrary.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.