This commit is contained in:
2025-10-06 18:27:50 +02:00
commit 3e191a4f60
213 changed files with 22261 additions and 0 deletions
+94
View File
@@ -0,0 +1,94 @@
#include "ota_manager.hpp"
OTAManager::OTAManager() : enabled(false), status("Disabled") {}
OTAManager::~OTAManager() {}
void OTAManager::begin() {
ArduinoOTA.setHostname("RFID-Master-Client");
ArduinoOTA.onStart([this]() {
this->onStart();
});
ArduinoOTA.onEnd([this]() {
this->onEnd();
});
ArduinoOTA.onProgress([this](unsigned int progress, unsigned int total) {
this->onProgress(progress, total);
});
ArduinoOTA.onError([this](ota_error_t error) {
this->onError(error);
});
LOG_INFO("OTA Manager initialized");
}
void OTAManager::enable() {
if (!enabled) {
ArduinoOTA.begin();
enabled = true;
status = "Enabled";
LOG_INFO("OTA enabled");
}
}
void OTAManager::disable() {
if (enabled) {
ArduinoOTA.end();
enabled = false;
status = "Disabled";
LOG_INFO("OTA disabled");
}
}
bool OTAManager::isEnabled() const {
return enabled;
}
String OTAManager::getStatus() const {
return status;
}
void OTAManager::onStart() {
status = "Starting OTA update...";
LOG_INFO("OTA update started");
}
void OTAManager::onEnd() {
status = "OTA update completed";
LOG_INFO("OTA update completed");
}
void OTAManager::onProgress(unsigned int progress, unsigned int total) {
status = "OTA progress: " + String(progress / (total / 100)) + "%";
LOG_DEBUG("OTA progress: %u/%u", progress, total);
}
void OTAManager::onError(ota_error_t error) {
String errorMsg;
switch (error) {
case OTA_AUTH_ERROR:
errorMsg = "Auth Failed";
break;
case OTA_BEGIN_ERROR:
errorMsg = "Begin Failed";
break;
case OTA_CONNECT_ERROR:
errorMsg = "Connect Failed";
break;
case OTA_RECEIVE_ERROR:
errorMsg = "Receive Failed";
break;
case OTA_END_ERROR:
errorMsg = "End Failed";
break;
default:
errorMsg = "Unknown Error";
break;
}
status = "OTA Error: " + errorMsg;
LOG_ERROR("OTA error: %s", errorMsg.c_str());
}
+26
View File
@@ -0,0 +1,26 @@
#pragma once
#include <ArduinoOTA.h>
#include <WiFi.h>
#include <logger.hpp>
class OTAManager {
public:
OTAManager();
~OTAManager();
void begin();
void enable();
void disable();
bool isEnabled() const;
String getStatus() const;
private:
bool enabled;
String status;
void onStart();
void onEnd();
void onProgress(unsigned int progress, unsigned int total);
void onError(ota_error_t error);
};