Reputation: 1368
I have a BLE device prototype. I am able to scan the device, connect to it. I am also able to write its password as BLE characteristic . Password is in String. But when I am trying to write other values which are in hex it is giving me write unsuccessful error with status 4 and status 13 at different times ? The same thing is working with nRF application. Where am I going wrong. Below is my code.
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;
}
Upvotes: 0
Views: 2943
Reputation: 963
Let's change charac.setValue(0x01,BluetoothGattCharacteristic.FORMAT_SINT8,0);
into charac.setValue(new byte[]{0x01});
Upvotes: 2