Comments (9)
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.
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.
No, the problem is not fixed AFAIK... but this has been clearly understood on Issue #13
from bluetoothspplibrary.
Thanks!
from bluetoothspplibrary.
I had a fix for this problem. Please read my comment on:
from bluetoothspplibrary.
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.
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.
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.
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)
- 이 블루투스 라이브러리를 사용하려는 한국인들을 위해 HOT 1
- transfer intent
- take multiple masseges on recived data
- Bt
- Context HOT 1
- NullPointerException at app.akexorcist.bluetotohspp.library.BluetoothService$AcceptThread.run (BluetoothService.java:2)
- Not scanning or discoverying nearby bluetooth devices. (startActivityForResult) HOT 2
- Prematurely terminating data packets with byte values of 10 (LF) and 13 (CR) HOT 2
- Can't read data from a BT barcode reader
- Activity crashed A/libc: Fatal signal 11 (SIGSEGV), code 1 HOT 1
- thank u
- getBluetoothService() called with no BluetoothManagerCallback HOT 1
- targetSdkVersion < 4
- the package name is spelled incorrectly...
- ConnectThread NullPointerException when the BT has been manually disabled
- How to make own Reciver
- bt.setupService()
- Fixing send function HOT 1
- How do you solve the issue of broken packets/messages? HOT 1
- Question: Will this library give me serial port in PC when my android device connected to PC using BT?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bluetoothspplibrary.