使用 Android 应用程序从 BLE 温度计读取温度

问题描述 投票:0回答:1

我购买了一个 BLE 温度计并开发了一个 Android 应用程序来读取温度。我安装了 nRF connect,并且能够看到列出的 BLE 设备及其所有服务。温度测量特性标记为“指示”。我似乎没有找到如何在 nRF 中得到这个指示。当我使用 BLE 设备读取温度时没有任何反应。该温度未反映在 nRF 日志中。

我开发了一个 Android 应用程序,能够扫描该 BLE 设备、连接到它并启用指示。但是当我使用 BLE 设备测量温度时,onCharacteristicChanged 永远不会被调用。我的代码如下。

private final UUID temperatureServiceUuid = UUID.fromString("00001809-0000-1000-8000-00805f9b34fb");
private final UUID temperatureMeasureUuid = UUID.fromString("00002A1C-0000-1000-8000-00805f9b34fb");
private final UUID temperatureDescriptorUuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");

public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) {
        mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(temperatureDescriptorUuid);
        mBluetoothGatt.writeDescriptor(descriptor, BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);

    }

android bluetooth-lowenergy nrf-connect
1个回答
0
投票
private final UUID temperatureServiceUuid = UUID.fromString("00001809-0000-1000-8000-00805f9b34fb");
private final UUID temperatureMeasureUuid = UUID.fromString("00002A1C-0000-1000-8000-00805f9b34fb");
private final UUID temperatureDescriptorUuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");

private void setNotificationTemp(BluetoothGatt gatt) {
    BluetoothGattService temperatureService = gatt.getService(temperatureServiceUuid);
    BluetoothGattCharacteristic temperatureChar = temperatureService.getCharacteristic(temperatureMeasureUuid);
    gatt.setCharacteristicNotification(temperatureChar, true)

    BluetoothGattDescriptor temperatureDescriptor = temperatureChar.getDescriptor(temperatureDescriptorUuid);
    gatt.writeDescriptor(temperatureDescriptor, BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
}
© www.soinside.com 2019 - 2024. All rights reserved.