Fixed MQTT and WS Routing - w/o SSL
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
* This class manages over-the-air firmware updates with safe, reliable
|
||||
* update mechanisms, version checking, and comprehensive error handling.
|
||||
*
|
||||
* 📋 VERSION: 2.0 (Enhanced OTA management)
|
||||
* 📋 VERSION: 2.1 (Enhanced with scheduled checks and full validation)
|
||||
* 📅 DATE: 2025
|
||||
* 👨💻 AUTHOR: Advanced Bell Systems
|
||||
* ═══════════════════════════════════════════════════════════════════════════════════
|
||||
@@ -24,9 +24,11 @@
|
||||
#include <mbedtls/md.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <functional>
|
||||
#include <time.h>
|
||||
#include "../FileManager/FileManager.hpp"
|
||||
|
||||
class ConfigManager; // Forward declaration
|
||||
class Player; // Forward declaration for idle check
|
||||
|
||||
class OTAManager {
|
||||
public:
|
||||
@@ -48,7 +50,11 @@ public:
|
||||
WRITE_FAILED,
|
||||
VERIFICATION_FAILED,
|
||||
CHECKSUM_MISMATCH,
|
||||
METADATA_PARSE_FAILED
|
||||
METADATA_PARSE_FAILED,
|
||||
SIZE_MISMATCH,
|
||||
VERSION_TOO_LOW,
|
||||
CHANNEL_MISMATCH,
|
||||
PLAYER_ACTIVE
|
||||
};
|
||||
|
||||
// Callback types
|
||||
@@ -56,11 +62,16 @@ public:
|
||||
using StatusCallback = std::function<void(Status status, ErrorCode error)>;
|
||||
|
||||
explicit OTAManager(ConfigManager& configManager);
|
||||
~OTAManager();
|
||||
|
||||
void begin();
|
||||
void setFileManager(FileManager* fm);
|
||||
void setPlayer(Player* player); // NEW: Set player reference for idle check
|
||||
|
||||
void checkForUpdates();
|
||||
void checkForUpdates(const String& channel); // Check specific channel
|
||||
void checkForEmergencyUpdates(); // NEW: Scheduled emergency-only check
|
||||
|
||||
void update();
|
||||
void update(const String& channel); // Update from specific channel
|
||||
void checkFirmwareUpdateFromSD(); // Check SD for firmware update
|
||||
@@ -92,9 +103,12 @@ public:
|
||||
private:
|
||||
ConfigManager& _configManager;
|
||||
FileManager* _fileManager;
|
||||
Player* _player; // NEW: Player reference for idle check
|
||||
Status _status;
|
||||
ErrorCode _lastError;
|
||||
float _availableVersion;
|
||||
float _minVersion; // NEW: Minimum required version
|
||||
size_t _expectedFileSize; // NEW: Expected firmware file size
|
||||
bool _updateAvailable;
|
||||
String _availableChecksum;
|
||||
String _updateChannel;
|
||||
@@ -104,6 +118,10 @@ private:
|
||||
ProgressCallback _progressCallback;
|
||||
StatusCallback _statusCallback;
|
||||
|
||||
// NEW: Scheduled check timer
|
||||
TimerHandle_t _scheduledCheckTimer;
|
||||
static void scheduledCheckCallback(TimerHandle_t xTimer);
|
||||
|
||||
void setStatus(Status status, ErrorCode error = ErrorCode::NONE);
|
||||
void notifyProgress(size_t current, size_t total);
|
||||
bool checkVersion();
|
||||
@@ -111,11 +129,15 @@ private:
|
||||
bool checkChannelsMetadata();
|
||||
bool downloadAndInstall();
|
||||
bool downloadAndInstall(const String& channel);
|
||||
bool downloadToSD(const String& url, const String& expectedChecksum);
|
||||
bool downloadToSD(const String& url, const String& expectedChecksum, size_t expectedSize); // NEW: Added size param
|
||||
bool verifyChecksum(const String& filePath, const String& expectedChecksum);
|
||||
String calculateSHA256(const String& filePath);
|
||||
bool installFromSD(const String& filePath);
|
||||
String buildChannelUrl(const String& channel) const;
|
||||
String buildMetadataUrl(const String& channel) const;
|
||||
String buildFirmwareUrl(const String& channel) const;
|
||||
|
||||
// NEW: Helper methods
|
||||
bool isPlayerActive() const;
|
||||
bool checkAvailableSpace(size_t requiredBytes) const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user