首页 文章

无法通过BLE将Android应用程序连接到Raspberry Pi 3

提问于
浏览
1

我使用Raspberry Pi 3型号B作为蓝牙外设 . Pi正在运行GATT服务器并对其进行广告宣传 .

我可以从LightBlue iOS应用程序连接到它,并可以读取和写入值 .

我无法从Android应用程序连接到BLE上的Pi . 我尝试过使用Play商店中的2个应用程序 - BLE Scanner和Bluetooth LE Scanner . 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.

相同的应用程序可以连接到使用LightBlue iOS应用程序或DropBeacon iOS应用程序模拟的虚拟外围设备 .

这让我想到,pi上的一些配置阻止它接受来自Android的连接 .

src代码:https://github.com/googlesamples/android-BluetoothLeGatt

有什么建议使这项工作?谢谢

1 回答

  • 2

    运用

    mBluetoothGatt = device.connectGatt(this, false, mGattCallback,TRANSPORT_LE);
    

    代替

    mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
    

    为我做了诀窍 . API级别23支持具有4个参数的connectGatt函数定义

相关问题