Sub*_*hee 1 android bluetooth bluetooth-lowenergy android-ble raspberry-pi3
我使用 Raspberry Pi 3 B 型作为蓝牙外设。Pi 正在运行 GATT 服务器并对其进行广告。
我可以从 LightBlue iOS 应用程序连接到它,并且可以读取和写入值。
我在通过 BLE 从 Android 应用程序连接到 Pi 时遇到问题。我尝试使用 Play 商店中的 2 个应用程序 - BLE 扫描仪和蓝牙 LE 扫描仪。BluetoothLeGatt 是我尝试使用的另一个应用程序。它可作为 Android Studio 上的示例 BLE 项目使用。pi 出现在扫描结果中,一旦我按下连接,应用程序就会尝试连接,但可能会被 pi 拒绝连接。程序控制转到 GattCallback 函数,状态更改为“断开连接”,并且服务发现永远不会发生。日志如下所示:
D/BluetoothGatt: connect() - device: B8:27:EB:A4:E7:75, auto: false
D/BluetoothGatt: registerApp()
D/BluetoothGatt: registerApp() - UUID=0c46767a-1ddc-4d91-83fe-490f9d3a5ad7
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
D/BluetoothLeService: Trying to create a new connection.
D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=6 device=B8:27:EB:A4:E7:75
I/BluetoothLeService: Disconnected from GATT server.
Run Code Online (Sandbox Code Playgroud)
同一应用程序能够连接到使用 LightBlue iOS 应用程序或 DropBeacon iOS 应用程序模拟的虚拟外围设备。
这让我想到,pi 上的某些配置阻止它接受来自 Android 的连接。
源代码:https: //github.com/googlesamples/android-BluetoothLeGatt
有什么建议可以让这项工作成功吗?谢谢
使用
mBluetoothGatt = device.connectGatt(this, false, mGattCallback,TRANSPORT_LE);
Run Code Online (Sandbox Code Playgroud)
代替
mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
Run Code Online (Sandbox Code Playgroud)
为我成功了。API 级别 23 支持带有 4 个参数的 connectGatt 函数定义
| 归档时间: |
|
| 查看次数: |
1049 次 |
| 最近记录: |