安卓蓝牙以编程方式与 PIN 配对,无需用户 PIN 输入



我希望将我的安卓设备与 arduino 蓝牙盾配对,我设法连接到它,但它一直要求我手动输入密码。

我的问题是我如何使应用程序自动执行此操作(填写密码并使用蓝牙连接)?

我的代码

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();
}

我需要一个项目,我已经卡了 2 天,如果有人可以帮助我解决这个问题,那就太棒了!

我认为实现自动连接的最简单方法是查看蓝牙模块的固件文档。在大多数情况下,有一个命令模式,您可以轻松输入(为 rn-42 键入 $$$,或在此处查找 hc-05/06 [instructables.com 教程])并设置连接模式。从/主模式,存储特定的MAC地址等有很多选项。

最新更新