1

I looking to pair my android device to an arduino bluetooth shield, I managed to connect to it but it keeps asking me to put in the pincode manualy.

My question is how do i make it so the app does this (fill in the pincode and connect with bluetooth) automatically?

my code

private byte[] convertPinToBytes(String s)
{
    byte[] pin = s.getBytes();
    return pin;
}

byte[] pinBytes = convertPinToBytes("0000");

try 
{
     Log.d(TAG, "Try to set the PIN");
     m = device.getClass().getMethod("setPin", byte[].class);
     m.invoke(device, pinBytes);
     Log.d(TAG, "Success to add the PIN.");
     Toast.makeText(this, "Success to add the PIN", Toast.LENGTH_LONG).show();
} 
catch (Exception e) 
{
     Log.e(TAG, e.getMessage());
     e.printStackTrace();
     Toast.makeText(this, "add pin failed. " + e.getMessage(), Toast.LENGTH_LONG).show();
}

I need this for a project and I'm stuck for 2 days already, if someone could help me with this problem that would be awesome!

Roel B
  • 11
  • 3

1 Answers1

0

I think the easiest way to realize an auto-connect is to look at the firmware documentation of your bluetooth module. In most cases there is a command mode, which you can enter easily (type $$$ for rn-42, or look here for hc-05/06 [tutorial from instructables.com]) and set up the connection mode. There are a lot of options for slave/master mode, storing specific mac-addresses, etc.

user3704293
  • 1,026
  • 2
  • 16
  • 28