35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
#include <ArduinoOTA.h>
|
|
#include "debugutil.hpp"
|
|
#include "ota.h"
|
|
|
|
OTAHandler::OTAHandler(std::string_view hostname) {
|
|
ArduinoOTA.setHostname(hostname.data());
|
|
ArduinoOTA.onStart([]() {
|
|
Debug::println("OTA Start");
|
|
});
|
|
ArduinoOTA.onEnd([]() {
|
|
Debug::println("OTA End");
|
|
});
|
|
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
|
Debug::printf("OTA Progress: %u%%\n", (progress / (total / 100)));
|
|
});
|
|
ArduinoOTA.onError([](ota_error_t error) {
|
|
Debug::printf("OTA Error[%u]: ", error);
|
|
if (error == OTA_AUTH_ERROR) {
|
|
Debug::println("Auth Failed");
|
|
} else if (error == OTA_BEGIN_ERROR) {
|
|
Debug::println("Begin Failed");
|
|
} else if (error == OTA_CONNECT_ERROR) {
|
|
Debug::println("Connect Failed");
|
|
} else if (error == OTA_RECEIVE_ERROR) {
|
|
Debug::println("Receive Failed");
|
|
} else if (error == OTA_END_ERROR) {
|
|
Debug::println("End Failed");
|
|
}
|
|
});
|
|
ArduinoOTA.begin();
|
|
}
|
|
|
|
void OTAHandler::poll() {
|
|
ArduinoOTA.handle();
|
|
} |