아두이노에서 문자열을 수신하려는데 전송만 되고 수신은 안되네요ㅠㅠ 뭐가 문제인지 아무리 생각해도 알 수없어 도움 요청합니다.. 다른 블루투스 채팅앱과는 잘 주고 받는걸 봐서 코드가 문제인것같습니다ㅠㅠ!!
예제를 참고할래도 에러메세지가 떠서 참고할 수 없는 상황이라 도움 주셨으면 합니다ㅠㅠㅠ
void connectToSelectedDevice(String selectedDeviceName) {
mRemoteDevie = getDeviceFromBondedList(selectedDeviceName);
UUID uuid = java.util.UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
try {
mSocket = mRemoteDevie.createRfcommSocketToServiceRecord(uuid);
mSocket.connect();
mOutputStream = mSocket.getOutputStream();
mInputStream = mSocket.getInputStream();
beginListenForData();
}catch(Exception e) {
finish();
}
}
void beginListenForData() {
final Handler handler = new Handler();
readBufferPosition = 0;
readBuffer = new byte[1024];
mWorkerThread = new Thread(new Runnable()
{
@Override
public void run() {
while(!Thread.currentThread().isInterrupted()) {
try {
int byteAvailable = mInputStream.available();
if(byteAvailable > 0) {
byte[] packetBytes = new byte[byteAvailable];
mInputStream.read(packetBytes);
for(int i=0; i<byteAvailable; i++) {
byte b = packetBytes[i];
if(b == mCharDelimiter) {
byte[] encodedBytes = new byte[readBufferPosition];
System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length);
final String data = new String(encodedBytes, "US-ASCII");
readBufferPosition = 0;
handler.post(new Runnable(){
@Override
public void run() {
guideText.setText(data);
}
});
}
else {
readBuffer[readBufferPosition++] = b;
}
}
}
} catch (Exception e) {
finish();
}
}
}
});
mWorkerThread.start();
}
}