From f92db527e1a79a7bb80245ce5df3f8a41e81cce1 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Mon, 13 Nov 2023 01:02:01 +0100 Subject: [PATCH] Add OTA error handling --- src/lib/ota.cpp | 10 +++++++++- src/lib/ota.hpp | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib/ota.cpp b/src/lib/ota.cpp index 7740027..c9d04bc 100644 --- a/src/lib/ota.cpp +++ b/src/lib/ota.cpp @@ -9,7 +9,7 @@ void setupOTA() ArduinoOTA.onStart(onOTAStart); ArduinoOTA.onProgress(onOTAProgress); - + ArduinoOTA.onError(onOTAError); ArduinoOTA.onEnd(onOTAComplete); ArduinoOTA.setHostname(getMyHostname().c_str()); @@ -80,6 +80,14 @@ void downloadUpdate() { } +void onOTAError(ota_error_t error) { + Serial.println("\nOTA update error, restarting"); + Wire.end(); + SPI.end(); + delay(1000); + ESP.restart(); +} + void onOTAComplete() { Serial.println("\nOTA update finished"); diff --git a/src/lib/ota.hpp b/src/lib/ota.hpp index 69b5613..148bd17 100644 --- a/src/lib/ota.hpp +++ b/src/lib/ota.hpp @@ -8,4 +8,5 @@ void onOTAStart(); void handleOTATask(void *parameter); void onOTAProgress(unsigned int progress, unsigned int total); void downloadUpdate(); +void onOTAError(ota_error_t error); void onOTAComplete(); \ No newline at end of file