Android: Bluetooth Serial (Com Port) communication with Android Phone

androidbluetoothserial-port

I am trying to communicate with a Bluetooth programmable Microcontroller. The Bluetooth device on the microcontroller communicates (specifically) on Bluetooth Serial COM Port number 4.

QUESTION: How can I get the Android App to read data from this COM port (number 4)?

I know the UUID is a well known unique ID,that works for this device, but I don't think that it has anything to do with specifying the COM port.

static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
btSocket = btDevice.createRfcommSocketToServiceRecord( myUUID);
btSocket.connect();
valid.append( btDevice.getName() + "\n" + btDevice.getAddress());
north.append("Socket Connected");
InputStream mmInStream = btSocket.getInputStream();
OutputStream mmOutStream = btSocket.getOutputStream();
byte[] buffer = new byte[10];
int bytes;
StringBuffer str = new StringBuffer();
while (true)                            {                               
     try {
    mmOutStream.write("a".getBytes());

        //Reads a # of bytes until the end of stream is reached
        bytes = mmInStream.read(buffer);
        //Transform to string
                str.append(buffer.toString()+"\t");                         //Clear the buffer
        Log.e("DATA", "THE DATA: "+ str.toString());
        south.setText(str.toString());
         str.delete(0,str.length());
       } catch (IOException e) {
        break;
} }}

Best Answer

The COM port is something that exists only on the microcontroller, not the Bluetooth device attached to it. The Bluetooth device does not even know which COM port the microcontroller used to connect to it. The Bluetooth device's connection to the micro is via the TX and RX lines. The fact that they are attached to pins on the micro assigned to a specific COM port is irrelevant and unknown to the Bluetooth device.

Related Topic