如何将十六进制值写入 BLE 设备?

How to write hex value to BLE device?

我有一个 BLE 设备原型。我能够扫描设备,连接到它。我也可以将其密码写为 BLE 特性。密码在字符串中。但是,当我尝试写入其他十六进制值时,它让我在不同时间写入状态为 4 和状态 13 的不成功错误?同样的事情也适用于 nRF 应用程序。我哪里错了。下面是我的代码。

  public boolean writeCharacteristic(BluetoothGatt mBluetoothGatt) {

    //check mBluetoothGatt is available
    if (mBluetoothGatt == null) {
        Log.e("++++", "lost connection");
        return false;
    }
    String SERVICE_STRING = "3fc2d576-0249-11e7-93ae-----------";
    UUID SERVICE_UUID = UUID.fromString(SERVICE_STRING);
    BluetoothGattService Service = mBluetoothGatt.getService(SERVICE_UUID);
    if (Service == null) {
        Log.e("++++++", "service not found!");
        return false;
    }

    BluetoothGattCharacteristic charac = Service
            .getCharacteristic(UUID.fromString("3fc2d576-0249-11e7-93ae-------------"));
    if (charac == null) {
        Log.e("+++", "char not found!");
        return false;
    }
    String mValue = "0x01";
    byte[] value = mValue.getBytes();
    //value[0] = (byte) (0x00);
    String pwd = "WWW";
   // byte[] value = mValue.getBytes();
    charac.setValue(0x01,BluetoothGattCharacteristic.FORMAT_SINT8,0);
    boolean status = mBluetoothGatt.writeCharacteristic(charac);
    return status;
}

我们把charac.setValue(0x01,BluetoothGattCharacteristic.FORMAT_SINT‌​8,0);改成charac.setValue(new byte[]{0x01});