Added MQTT Logs, and improved OTA and NTP to Async
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include <nvs_flash.h>
|
||||
#include <nvs.h>
|
||||
|
||||
OTAManager::OTAManager(ConfigManager& configManager)
|
||||
OTAManager::OTAManager(ConfigManager& configManager)
|
||||
: _configManager(configManager)
|
||||
, _fileManager(nullptr)
|
||||
, _player(nullptr)
|
||||
@@ -21,7 +21,8 @@ OTAManager::OTAManager(ConfigManager& configManager)
|
||||
, _isEmergency(false)
|
||||
, _progressCallback(nullptr)
|
||||
, _statusCallback(nullptr)
|
||||
, _scheduledCheckTimer(NULL) {
|
||||
, _scheduledCheckTimer(NULL)
|
||||
, _initialCheckTimer(NULL) {
|
||||
}
|
||||
|
||||
OTAManager::~OTAManager() {
|
||||
@@ -30,12 +31,17 @@ OTAManager::~OTAManager() {
|
||||
xTimerDelete(_scheduledCheckTimer, portMAX_DELAY);
|
||||
_scheduledCheckTimer = NULL;
|
||||
}
|
||||
if (_initialCheckTimer != NULL) {
|
||||
xTimerStop(_initialCheckTimer, 0);
|
||||
xTimerDelete(_initialCheckTimer, portMAX_DELAY);
|
||||
_initialCheckTimer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void OTAManager::begin() {
|
||||
LOG_INFO("OTA Manager initialized");
|
||||
setStatus(Status::IDLE);
|
||||
|
||||
|
||||
// Create timer for scheduled checks (checks every minute if it's 3:00 AM)
|
||||
_scheduledCheckTimer = xTimerCreate(
|
||||
"OTA_Schedule",
|
||||
@@ -44,13 +50,30 @@ void OTAManager::begin() {
|
||||
this, // Timer ID (pass OTAManager instance)
|
||||
scheduledCheckCallback
|
||||
);
|
||||
|
||||
|
||||
if (_scheduledCheckTimer != NULL) {
|
||||
xTimerStart(_scheduledCheckTimer, 0);
|
||||
LOG_INFO("OTA scheduled check timer started (will check at 3:00 AM)");
|
||||
} else {
|
||||
LOG_ERROR("Failed to create OTA scheduled check timer!");
|
||||
}
|
||||
|
||||
// 🔥 NEW: Create one-shot timer for initial boot check (5 seconds after boot)
|
||||
// This prevents blocking during critical connection phase
|
||||
_initialCheckTimer = xTimerCreate(
|
||||
"OTA_InitCheck",
|
||||
pdMS_TO_TICKS(5000), // 5 seconds delay
|
||||
pdFALSE, // One-shot timer
|
||||
this, // Timer ID (pass OTAManager instance)
|
||||
initialCheckCallback
|
||||
);
|
||||
|
||||
if (_initialCheckTimer != NULL) {
|
||||
xTimerStart(_initialCheckTimer, 0);
|
||||
LOG_INFO("OTA initial check scheduled for 5 seconds after boot (non-blocking)");
|
||||
} else {
|
||||
LOG_ERROR("Failed to create OTA initial check timer!");
|
||||
}
|
||||
}
|
||||
|
||||
void OTAManager::setFileManager(FileManager* fm) {
|
||||
@@ -61,18 +84,33 @@ void OTAManager::setPlayer(Player* player) {
|
||||
_player = player;
|
||||
}
|
||||
|
||||
// ✅ NEW: Static timer callback for initial boot check
|
||||
void OTAManager::initialCheckCallback(TimerHandle_t xTimer) {
|
||||
OTAManager* ota = static_cast<OTAManager*>(pvTimerGetTimerID(xTimer));
|
||||
if (ota) {
|
||||
LOG_INFO("🚀 Running initial OTA check (non-blocking, async)");
|
||||
ota->performInitialCheck();
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ NEW: Perform initial OTA check (async, non-blocking)
|
||||
void OTAManager::performInitialCheck() {
|
||||
// This runs asynchronously, won't block WebSocket/UDP/MQTT
|
||||
checkForUpdates();
|
||||
}
|
||||
|
||||
// ✅ NEW: Static timer callback for scheduled checks
|
||||
void OTAManager::scheduledCheckCallback(TimerHandle_t xTimer) {
|
||||
OTAManager* ota = static_cast<OTAManager*>(pvTimerGetTimerID(xTimer));
|
||||
|
||||
|
||||
// Get current time
|
||||
time_t now = time(nullptr);
|
||||
struct tm* timeinfo = localtime(&now);
|
||||
|
||||
|
||||
// Only proceed if it's exactly 3:00 AM
|
||||
if (timeinfo->tm_hour == 3 && timeinfo->tm_min == 0) {
|
||||
LOG_INFO("🕒 3:00 AM - Running scheduled OTA check");
|
||||
|
||||
|
||||
// Check if player is idle before proceeding
|
||||
if (!ota->isPlayerActive()) {
|
||||
LOG_INFO("✅ Player is idle - checking for emergency updates");
|
||||
|
||||
Reference in New Issue
Block a user