Add response callback for OTA configuration and update handling; adjust hardware configurations

This commit is contained in:
2025-10-05 20:22:53 +02:00
parent 46cb1a3a20
commit 2171349b7c
4 changed files with 59 additions and 25 deletions
+12 -1
View File
@@ -1,7 +1,18 @@
#include "ota_update.hpp"
OtaUpdate::OtaUpdate()
: _server(80), _httpUpdater(), _configured(false), _startTime(0) {
: _server(80), _httpUpdater(), _configured(false), _startTime(0), m_responseCallback(nullptr) {
}
void OtaUpdate::set(const hardware_SensorOTAEnable& config) {
bool success = configure(config);
if (m_responseCallback) {
IPAddress ip = WiFi.localIP();
if (!config.as_station_mode) {
ip = WiFi.softAPIP();
}
m_responseCallback(success, success ? ip.toString().c_str() : "", success ? "" : "Failed to configure OTA");
}
}
bool OtaUpdate::configure(const hardware_SensorOTAEnable& config) {
+6 -1
View File
@@ -7,15 +7,20 @@
class OtaUpdate {
public:
using ResponseCallback = void (*)(bool success, const char* ip_address, const char* error_message);
OtaUpdate();
bool configure(const hardware_SensorOTAEnable& config);
void set(const hardware_SensorOTAEnable& config);
void setResponseCallback(ResponseCallback callback) { m_responseCallback = callback; }
void update();
void disable();
private:
bool configure(const hardware_SensorOTAEnable& config);
hardware_SensorOTAEnable _config;
ESP8266WebServer _server;
ESP8266HTTPUpdateServer _httpUpdater;
bool _configured;
unsigned long _startTime;
ResponseCallback m_responseCallback;
};