0

我开发了一个 Android 应用程序来将数据发送到 BLE 设备。当我连接到 BLE 设备时,我发现了服务和特性并得到了这个

onGetService() - Device=D8:80:39:F0:03:6E UUID=00001800-0000-1000-8000-00805f9b34fb
onGetService() - Device=D8:80:39:F0:03:6E UUID=0000180a-0000-1000-8000-00805f9b34fb
onGetService() - Device=D8:80:39:F0:03:6E UUID=49535343-fe7d-4ae5-8fa9-9fafd205e455
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a00-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a01-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a04-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a29-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a24-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a25-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a27-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a26-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a28-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a23-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a2a-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-6daa-4d02-abf6-19569aca69fe
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-aca3-481c-91ec-d85e28a60318
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-1e4d-4bd9-ba61-23c647249616
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-8841-43f4-a8d4-ecbe34729bb3
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-026e-3a9b-954c-97daef17e26e
onGetDescriptor() - Device=D8:80:39:F0:03:6E UUID=00002902-0000-1000-8000-00805f9b34fb
onGetDescriptor() - Device=D8:80:39:F0:03:6E UUID=00002902-0000-1000-8000-00805f9b34fb
onGetDescriptor() - Device=D8:80:39:F0:03:6E UUID=00002902-0000-1000-8000-00805f9b34fb
onSearchComplete() = Device=D8:80:39:F0:03:6E Status=0

所以我认为我的设备有 3 个服务和 16 个特征(每个服务都有不同的特征),问题是当我必须发送一个字符时,我使用这个代码

 public void writeCustomCharacteristic(int value) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }
    /*check if the service is available on the device*/
    BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("00001800-0000-1000-8000-00805f9b34fb"));
    if(mCustomService == null){
        Log.w(TAG, "Custom BLE Service not found");
        return;
    }
    /*get the read characteristic from the service*/
    BluetoothGattCharacteristic mWriteCharacteristic = mCustomService.getCharacteristic(UUID.fromString("00002a04-0000-1000-8000-00805f9b34fb"));
    mWriteCharacteristic.setValue(value,android.bluetooth.BluetoothGattCharacteristic.FORMAT_UINT8,0);
    if(mBluetoothGatt.writeCharacteristic(mWriteCharacteristic) == false){
        Log.w(TAG, "Failed to write characteristic");
    }
}

所以问题是,必须使用什么服务和特性?我支持我所发现的。我想向 BLE 设备发送一个简单的字符并从 UART 类型的接口接收。

4

1 回答 1

3

我认为您应该使用该服务:

49535343-fe7d-4ae5-8fa9-9fafd205e455

用于数据交换,具有以下特点:

49535343-8841-43f4-a8d4-ecbe34729bb3

用于写入数据

于 2017-03-13T23:52:42.727 回答