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:
parent
596a9d54d4
commit
9b7adabc59
1 changed files with 10 additions and 0 deletions
|
|
@ -118,6 +118,16 @@ class MainActivity : AppCompatActivity() {
|
|||
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?) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue