LoRa_APRS_iGate/src/TaskOTA.cpp

62 wiersze
1.8 KiB
C++

#include <esp_task_wdt.h>
2022-11-16 20:41:50 +00:00
#include <logger.h>
2021-01-04 22:10:23 +00:00
#include "Task.h"
#include "TaskOTA.h"
#include "project_configuration.h"
OTATask::OTATask() : Task(TASK_OTA, TaskOta), _beginCalled(false) {
}
OTATask::~OTATask() {
}
2021-05-18 22:44:37 +00:00
bool OTATask::setup(System &system) {
2021-05-21 21:06:13 +00:00
_ota.onStart([&]() {
String type;
2022-03-19 21:29:38 +00:00
if (_ota.getCommand() == U_FLASH) {
type = "sketch";
2022-03-19 21:29:38 +00:00
} else { // U_SPIFFS
type = "filesystem";
2022-03-19 21:29:38 +00:00
}
2022-11-16 22:10:06 +00:00
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Start updating %s. please wait, this process is taking some time!", type.c_str());
})
2022-03-19 21:29:38 +00:00
.onEnd([&]() {
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "OTA End");
})
2022-03-19 21:29:38 +00:00
.onError([&](ota_error_t error) {
String error_str;
if (error == OTA_AUTH_ERROR) {
error_str = "Auth Failed";
} else if (error == OTA_BEGIN_ERROR) {
error_str = "Begin Failed";
} else if (error == OTA_CONNECT_ERROR) {
error_str = "Connect Failed";
} else if (error == OTA_RECEIVE_ERROR) {
error_str = "Receive Failed";
} else if (error == OTA_END_ERROR) {
error_str = "End Failed";
}
2022-03-20 09:56:06 +00:00
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Error[%d]: %s", error, error_str.c_str());
})
2022-11-16 19:22:03 +00:00
.onProgress([&](unsigned int received, unsigned int total_size) {
esp_task_wdt_reset();
});
2021-12-18 21:33:35 +00:00
if (system.getUserConfig()->network.hostname.overwrite) {
_ota.setHostname(system.getUserConfig()->network.hostname.name.c_str());
} else {
_ota.setHostname(system.getUserConfig()->callsign.c_str());
}
_stateInfo = "";
return true;
}
2021-05-18 22:44:37 +00:00
bool OTATask::loop(System &system) {
if (!_beginCalled) {
2021-05-21 21:06:13 +00:00
_ota.begin();
_beginCalled = true;
}
2021-05-21 21:06:13 +00:00
_ota.handle();
return true;
}