我有一个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_SINT8,0);
换成charac.setValue(new byte[]{0x01});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句