fix: OTA wait for 0xFF confirm before reboot, version bump to 15, improved logging

This commit is contained in:
eddy 2026-08-02 00:48:28 +02:00
commit 516a938c7b
6 changed files with 87 additions and 28 deletions

View file

@ -373,7 +373,8 @@ class BleRelayManager(
((value[3].toInt() and 0xFF) shl 8) or
(value[4].toInt() and 0xFF)
} else 0
Log.d(TAG, "OTA notify: status=$status seq=$seq")
val statusName = when (status) { 0x00 -> "ACK"; 0x01 -> "NAK"; 0x10 -> "COMPLETE"; 0x11 -> "ERROR"; else -> "UNKNOWN(0x${status.toString(16)})" }
Log.d(TAG, "OTA notify: status=$statusName seq=$seq raw=${value.joinToString("") { "%02X".format(it) }}")
handler.post { otaNotifyCallback?.onOtaNotify(status, seq) }
}
}

View file

@ -65,6 +65,7 @@ class OtaManager(
val notifyCallback = object : BleRelayManager.OtaNotifyCallback {
override fun onOtaNotify(status: Int, seq: Int) {
Log.d(TAG, "OTA notify received: status=0x${status.toString(16)} seq=$seq (0x00=ACK, 0x01=NAK, 0x10=COMPLETE, 0x11=ERROR)")
when (status) {
0x00 -> chunkAckReceived = true
0x01 -> chunkNakReceived = true
@ -163,7 +164,9 @@ class OtaManager(
withContext(Dispatchers.Main) { callback.onProgress(99, "Hash verifiëren...") }
finalStatusReceived = false
relayManager.sendOtaData(sha256)
Log.d(TAG, "Sending SHA256 hash (${sha256.size} bytes) to ESP")
val shaSent = relayManager.sendOtaData(sha256)
Log.d(TAG, "SHA256 write result: $shaSent")
try {
withTimeout(OTA_FINAL_TIMEOUT_MS) {
@ -173,14 +176,17 @@ class OtaManager(
}
}
} catch (_: kotlinx.coroutines.TimeoutCancellationException) {
Log.w(TAG, "Timeout waiting for final OTA status")
Log.w(TAG, "Timeout waiting for final OTA status after SHA256")
}
Log.d(TAG, "Final status: received=$finalStatusReceived status=$finalStatus (0x10=COMPLETE, 0x11=ERROR)")
relayManager.setOtaNotifyCallback(null)
if (finalStatus == 0x10) {
relayManager.sendOtaData(byteArrayOf(0xFF.toByte()))
Log.d(TAG, "Sent 0xFF reboot confirmation to ESP")
Log.d(TAG, "ESP confirmed SHA256 OK, sending 0xFF reboot confirmation")
val confirmSent = relayManager.sendOtaData(byteArrayOf(0xFF.toByte()))
Log.d(TAG, "0xFF write result: $confirmSent")
withContext(Dispatchers.Main) {
callback.onProgress(100, "Herstart...")
callback.onComplete()