2

我在 BLE 4.2 设备上运行具有自定义特征的自定义服务。我正在开发一个 android 应用程序来读取/写入特性等。我尝试的第一件事是读取特性。

我定义了一个 UUID 列表: List chars = new ArrayList<>();

我使用我知道的服务 UUID 创建一个服务: mCustomService = mBluetoothGatt.getService(MY_SERVICE_UUID);

我从我的服务中加载了 4 个已知 UUID 的列表:

chars.clear();
chars.add(UUID1);
chars.add(UUID2);
chars.add(UUID3);
chars.add(UUID4);

I read the first characteristic from the end of my list:
BluetoothGattCharacteristic mReadCharacteristic = mCustomService.getCharacteristic(chars.get(chars.size() - 1));
    if(mReadCharacteristic != null)
         mBluetoothGatt.readCharacteristic(mReadCharacteristic);

mReadCharacteristic 始终返回 null,服务不包含我的特征。

如果我使用 BLE“嗅探器”应用程序,那么我确实看到了所有特征。

谢谢

富有的

PS我无法弄清楚这里的格式!

4

1 回答 1

0

我有一个类似的设置——一个具有自定义服务和特性的设备——尽管该设备是 BLE 4.0。在您的应用程序中,也许您正在执行此操作,但未在问题中提及 - 但您是否在致电

mBluetoothGatt.discoverServices();

然后触发回调onServicesDiscovered。我在onServicesDiscovered处理程序中有与您类似的代码,并且工作正常。

public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { // getService // getCharactistics } // etc. }

于 2017-03-02T11:11:43.030 回答