안녕하세요 안드로이드 연습 중인 학생입니다.
인터넷 및 안드로이드 API를 읽으면서 구성을 짜놨는데. 아두이노에서 보내는 신호를 안드로이드가
원하는대로 읽히지 않습니다
(아두이노) 123 -> 안드로이드(1), (23) 으로 불러옵니다.
(아두이노 코딩)
if(bluetooth.available())
{
Serial.print((char)bluetooth.read());
}
f(Serial.available())
{
bluetooth.write(Serial.read());
delay(1);
}
(안드로이드 코딩)
public void run() {
Log.e(TAG, "BEGIN mConnectedThread");
int bytes ;
byte[] buffer = new byte[1024];
// Keep listening to the InputStream while connected
while (true) {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer);
Log.e(TAG, "byte 데이터 길이 : => " + bytes);
mHandler.obtainMessage(MainActivity.MESSAGE_READ, bytes, -1, buffer).sendToTarget();
Log.e(TAG, "-------------- obtainMessage clear ---------------: ");;
// Send the obtained bytes to the UI Activity
} catch (IOException e) {
Log.e(TAG, "disconnected", e);
connectionLost();
// Start the service over to restart listening mode
BluetoothChatService.this.start();
break;
}
}
}
핸들러 부분
case MESSAGE_READ:
byte[] readBuf = (byte[]) msg.obj;
String readMessage = new String(readBuf);
Log.e("TAG", "" + readMessage);
mConversationArrayAdapter.add(mConnectedDeviceName+": " + readMessage);
break;
가장 이상적으로 하고 싶은거는 String 형태로 변경된 byte 자료를 인트형으로 변경하여 센서값을 읽어와 안드로이드 내에서 정보를 처리하고 싶은건데 계속 끊어져 들어옵니다.
해결방법 부탁드립니다. ㅠㅠ