android - 将 Android 与 Arduino (HC-05) 配对,无需手动输入密码
问题描述
我正在将一些字符串数据从 android 发送到 HC-05 的 arduino。
目前我可以成功地将数据从android发送到hc-05(有或没有配对),我已经使用这种方法来创建套接字
private BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOException {
try {
final Method m = device.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] { UUID.class });
return (BluetoothSocket) m.invoke(device, MY_UUID);
} catch (Exception e) {
Log.e(TAG, "Could not create Insecure RFComm Connection",e);
}
return device.createRfcommSocketToServiceRecord(MY_UUID);
}
如您所见。它首先尝试创建InsecureRfcommSocket
. 它使用不安全的连接来连接。AFAIK 它可能会导致中间人攻击,所以我想使用安全通信createRfcommSocketToServiceRecord
。但我也不希望用户在配对时输入密码(如果没有密码交换,安全通信插座就不可能吗?:如果我错了,请纠正我)。所以
我的问题是:
- 如何配对 hc-05 而无需用户干预引脚输入?(我尝试过使用意图过滤器和广播接收器,但它不起作用(系统总是优先于我的接收器))
- 有没有办法在不配对的情况下创建安全的通信频道?因为我只想要安全的通道和数据交换。
- 如果我想以编程方式输入 pin,我可以使用
device.setpin()
还是应该为此触发 AT-Command?
解决方案
推荐阅读
- html - 范围到 HTML 删除部分字符串
- reactjs - 如果在 console.log 中成功获取数据,如何显示成功消息?
- javascript - 通过 JavaScript matchMedia 切换 HTML 视频源
- mysql - 表中是否可以有一个切换唯一索引?
- python - 502错误的网关。在“digitalocean”上实施应用程序后
- javascript - JavaScript 给出错误的输出
- sim900 - 使用 sim800C 发送多个 post 请求
- apache-kafka - Avro Schema Registry 的价值是什么?
- r - 如何将数据读入R中的列联表
- angular - 为什么 RxJS 过滤方法对我不起作用