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