Files
AQS-FW/esp_ota.cpp

46 lines
1.4 KiB
C++

#include "esp_ota.h"
void initEspOta(void)
{
Serial.println("ESPOTA: init");
ArduinoOTA
.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("ESPOTA: Start updating " + type);
ProgressbarVisible(true);
ledcWrite(TFT_BL_PWMCHANNEL, 64);
})
.onEnd([]() {
Serial.println("\nESPOTA: End");
})
.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("ESPOTA: Progress: %u%%\r", (progress / (total / 100)));
setOTAProgress((progress / (total / 100)));
})
.onError([](ota_error_t error) {
Serial.printf("ESPOTA: Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("ESPOTA: Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("ESPOTA: Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("ESPOTA: Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("ESPOTA: Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("ESPOTA: End Failed");
});
ArduinoOTA.begin();
Serial.print("ESPOTA: IP address: ");
Serial.println(WiFi.localIP());
Serial.println("ESPOTA: init OK");
}
void handleEspOta(void)
{
ArduinoOTA.handle();
}