【问题标题】:How to connect multiple BLE devices through android application?如何通过android应用连接多个BLE设备?
【发布时间】:2017-11-03 11:13:49
【问题描述】:

我正在研究 android 和 BLE 设备连接。我想同时连接多个 BLE 设备。如何做到这一点?

【问题讨论】:

  • 这是一个有点模糊的问题。一个设备需要是外围设备(广告商),而另一个设备需要是可以连接到外围设备的客户端。到目前为止,您尝试过什么?

标签: android bluetooth-lowenergy gatt rxandroidble bluetooth-gatt


【解决方案1】:

您可以从您的 android 应用程序连接到多个 BLE 设备。

连接:为每个 BLE 设备调用此代码 mBluetoothGatt = device.connectGatt(this, false, mGattCallback); 将所有 mBluetoothGatt 保存到列表中。

阅读:在mGattCallback 方法onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)gatt 参数。 gatt.getDevice().getAddress() 将为您提供接收数据的 BLE 设备的 mac 地址。

写作:使用mBluetoothGatt.getDevice().getAddress(),您始终知道您指向的设备。您可以将命令写入它。在mGattCallback方法onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)中,参数gatt会给你mac地址来确认写命令。

您可以为所有连接使用单个 mGattCallback。如果您要区分并且不想总是比较 mac 地址,请为每个连接进行单个回调。

This 会告诉你你的安卓设备可以支持多少个连接。

如果您仍有疑问,请随时询问。

【讨论】:

  • 好的,我会试试这个..谢谢。如果我发现任何困难,我会告诉你。
  • @j.prashant 这与单 ble 通信非常相似。如果你真的需要一个例子,给我几天时间。我会在github上托管它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多