2

I am trying to connect to an embedded device and the bluetooth pin is 1234, when I connect to to the embedded board it is asking me to enter 000000 on the embedded board and not asking me to enter the correct pin from my device. I am not sure what I am doing wrong.

public void connectBluetooth() throws IOException{
        device = bluetoothAdapter.getRemoteDevice(MAC);
        try {
            mSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
        } catch (IOException e) {
            Log.e(tag, "+++++Failed to create RFCOMM connection+++++");
        }
        try{
            mSocket.connect();
            Log.e(tag, "+++++connecting+++++");
            manageBluetooth manageThread = new manageBluetooth();
            manageThread.start();
            threadCheck = true;
        }catch(IOException e){
            Log.e(tag, "+++++Failed to connect+++++");
        }
        Log.e(tag, "+++++After catch+++++");
    }
}

I call in and out from the manageThread, I have stated the right MAC address as well. Surely it should be asking me to enter the pin on my phone and not on the embedded board it self.

user1022306
  • 41
  • 1
  • 6

1 Answers1

0

Can you explain which embedded board you are using?

When pairing takes place, the devices indicate to each other what are their input/output possibilities for the desired connection.

The problem is your two devices signal different things. Probably, Android wants to do a SPP with passkey entry, while your embedded device tries a legacy pairing. You need to post more code to get an even clearer response.

Here is my scenario: - Android is the RFCOMM server - The embedded board is the RFCOMM client(initiates the connection) Imagine they are unpaired.

  1. The embedded board browses the Android SDP looking for the RFCOMM socket (channel actually) matching the UUID.
  2. The embedded board tries to connect.
  3. The embedded board receives a request to detail its I/O capability and bonding settings(for bonding). It must respond. Let's say it responds with MITM protection, bonding required and it will also say it has NO I/O capabilities.
  4. The embedded board receives the authentication requirements of Android (MITM protection, bonding required)
  5. Android shows an accept/reject dialog.
  6. Now connection goes through.

Pairing will no longer be necessary for new RFCOMM connections until one of the devices' bluetooth adapter loses its power source, or it deletes its link keys some other way (unpairs). Before connecting, since the Android RFCOMM socket is secure, my embedded board will receive an authentication request. So, for Android RFCOMM, in my project I can make Android respond with "yes/no" only (not a PIN). (limited I/O)

You can also make pairing instant and with no user action, but this is against the Android API and not recommended. Better control of the Android phone's bluetooth chip can be achieved by using the aidl files.

Don't forget to vote up!!

Community
  • 1
  • 1
Radu
  • 2,076
  • 2
  • 20
  • 40