I resolved the previous using but unfortunetly now , When I am writing the end byte doing this :
case "OTAEND":
Log.d("OTAEND", "Called");
handler.postDelayed(new Runnable() {
@Override
public void run() {
writeOtaControl((byte) 0x03);
}
},500);
break;
Using this method :
/**WRITES BYTE TO OTA CONTROL CHARACTERISTIC*****************************************/
public boolean writeOtaControl(byte ctrl) {
Log.d("writeOtaControl", "Called");
if (bluetoothGatt.getService(ota_service)!=null){
BluetoothGattCharacteristic charac = bluetoothGatt.getService(ota_service).getCharacteristic(ota_control);
if (charac != null) {
Log.d("Instance ID", "" + charac.getInstanceId());
charac.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
Log.d("charac_properties", "" + charac.getProperties());
byte[] control = new byte[1];
control[0] = ctrl;
charac.setValue(control);
bluetoothGatt.writeCharacteristic(charac);
return true;
} else {
Log.d("characteristic", "null");
}
} else {
Log.d("service", "null");
}
return false;
}
Inside this callback I got status with error code 129 which is not even in documentation on BLE.
@Override //CALLBACK ON CHARACTERISTIC WRITE (PROPERTY: WHITE)
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
if (status != 0){ // Error Handling
Log.d("onCharWrite", "status: " + Integer.toHexString(status));
final int error = status;
runOnUiThread(new Runnable() { //Display error on Toast
@Override
public void run() {
Toast.makeText(getBaseContext(), charErrorHandling(error), Toast.LENGTH_LONG).show();
}
});
Here is my HCl log :