Add onCharacteristicWrite callback for BLE write feedback

Implement onCharacteristicWrite in gattCallback to get confirmation
that packets are submitted to the local BLE stack. Logs success/failure
and shows 'Communicatiefout' on write failure. seq++ stays in
sendRelayCommand to ensure unique sequence numbers for rapid ON/OFF.

Reviewed in codereview.md (recommendation #5).
This commit is contained in:
eddy 2026-07-26 16:31:07 +02:00
commit 9b7adabc59

View file

@ -118,6 +118,16 @@ class MainActivity : AppCompatActivity() {
runOnUiThread { statusText.text = "Service not found" } runOnUiThread { statusText.text = "Service not found" }
} }
} }
@SuppressLint("MissingPermission")
override fun onCharacteristicWrite(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) {
if (status == BluetoothGatt.GATT_SUCCESS) {
Log.d(TAG, "Write confirmed by local BLE stack (status=$status)")
} else {
Log.w(TAG, "Write failed (status=$status)")
runOnUiThread { statusText.text = "Communicatiefout" }
}
}
} }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {