feat: HAL variant system, OTA improvements, NVS migration scaffold
- Add variants/vesper.hpp and variants/agnus.hpp with HAS_SD_CARD, HAS_RTC, HAS_PCF8574, OUTPUT_COUNT_MAX, HW_FAMILY capability flags - Add agnus-v1 and agnus-mini-v1 PlatformIO environments with -include injection - Add src/NvsMigration/ scaffold for future NVS schema versioning - FirmwareHandler: OTA flow improvements and header updates - OTAManager: FastAPI integration, semver handling improvements - ConfigManager: refactoring groundwork for NVS-only variant support - CommunicationRouter: minor fix - provisioning/nvs_lab_device.csv: fix hw_type to VS, update device id fields - docs/dev/ota-telemetry-api.md: update API spec Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -186,13 +186,14 @@ void OTAManager::checkForEmergencyUpdates() {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_INFO(TAG, "Checking for EMERGENCY updates only...");
|
||||
checkForUpdates("stable"); // Check stable channel
|
||||
|
||||
String channel = _configManager.getOtaChannel();
|
||||
LOG_INFO(TAG, "Checking for EMERGENCY updates on channel '%s'...", channel.c_str());
|
||||
checkForUpdates(channel);
|
||||
|
||||
// Only proceed if emergency flag is set
|
||||
if (_updateAvailable && _isEmergency) {
|
||||
LOG_INFO(TAG, "🚨 EMERGENCY update detected during scheduled check - updating immediately");
|
||||
update("stable");
|
||||
update(channel);
|
||||
} else if (_updateAvailable && _isMandatory) {
|
||||
LOG_INFO(TAG, "⚠️ Mandatory update available, but will wait for next boot");
|
||||
} else {
|
||||
@@ -201,8 +202,8 @@ void OTAManager::checkForEmergencyUpdates() {
|
||||
}
|
||||
|
||||
void OTAManager::checkForUpdates() {
|
||||
// Boot-time check: only check stable channel for emergency/mandatory updates
|
||||
checkForUpdates("stable");
|
||||
// Use the device's persisted OTA channel (default "stable")
|
||||
checkForUpdates(_configManager.getOtaChannel());
|
||||
}
|
||||
|
||||
void OTAManager::checkForUpdates(const String& channel) {
|
||||
@@ -232,9 +233,13 @@ void OTAManager::checkForUpdates(const String& channel) {
|
||||
_isMandatory ? "YES" : "NO", _isEmergency ? "YES" : "NO");
|
||||
setStatus(Status::IDLE);
|
||||
|
||||
// Auto-update for emergency or mandatory updates during boot check
|
||||
if (channel == "stable" && (_isEmergency || _isMandatory)) {
|
||||
LOG_INFO(TAG, "Emergency/Mandatory update detected - starting automatic update");
|
||||
// Auto-update for emergency or mandatory updates.
|
||||
// Emergency: apply immediately regardless of channel.
|
||||
// Mandatory: apply on this boot check (any channel).
|
||||
// Optional: do nothing — wait for user/MQTT trigger.
|
||||
if (_isEmergency || _isMandatory) {
|
||||
LOG_INFO(TAG, "OTA: %s update detected on channel '%s' — starting automatic update",
|
||||
_isEmergency ? "Emergency" : "Mandatory", channel.c_str());
|
||||
update(channel);
|
||||
}
|
||||
} else {
|
||||
@@ -350,14 +355,19 @@ bool OTAManager::checkVersion(const String& channel) {
|
||||
|
||||
_availableChecksum = doc["sha256"] | "";
|
||||
_expectedFileSize = doc["size"] | (size_t)0;
|
||||
_isMandatory = doc["mandatory"] | false;
|
||||
_isEmergency = doc["emergency"] | false;
|
||||
_updateChannel = channel; // channel is what we requested — server returns update_type
|
||||
|
||||
// Validate channel matches what server says
|
||||
const char* serverUpdateType = doc["update_type"] | "";
|
||||
if (strlen(serverUpdateType) > 0 && String(serverUpdateType) != channel) {
|
||||
LOG_ERROR(TAG, "OTA: Channel mismatch! Requested: %s, Got: %s", channel.c_str(), serverUpdateType);
|
||||
// update_type: "optional" | "mandatory" | "emergency"
|
||||
// This is the urgency of the release — completely separate from the channel.
|
||||
// The server derives mandatory/emergency booleans from this for us.
|
||||
_isMandatory = doc["mandatory"] | false;
|
||||
_isEmergency = doc["emergency"] | false;
|
||||
_updateChannel = channel; // channel is what we requested
|
||||
|
||||
// Validate the server actually responded for the channel we asked for.
|
||||
// The response includes a "channel" field (e.g. "stable", "beta") — use that.
|
||||
const char* serverChannel = doc["channel"] | "";
|
||||
if (strlen(serverChannel) > 0 && String(serverChannel) != channel) {
|
||||
LOG_ERROR(TAG, "OTA: Channel mismatch! Requested: %s, Got: %s", channel.c_str(), serverChannel);
|
||||
_lastError = ErrorCode::CHANNEL_MISMATCH;
|
||||
continue;
|
||||
}
|
||||
@@ -1073,10 +1083,18 @@ bool OTAManager::performManualUpdate(const String& channel) {
|
||||
LOG_INFO(TAG, "Starting manual OTA update from %s channel (direct-to-flash)...", channel.c_str());
|
||||
setStatus(Status::DOWNLOADING);
|
||||
|
||||
String firmwareUrl = buildFirmwareUrl(channel);
|
||||
std::vector<String> servers = _configManager.getUpdateServers();
|
||||
String hwType = _configManager.getHardwareVariant();
|
||||
String fromVersion = getCurrentVersion().toString();
|
||||
String toVersion = _availableVersion.toString();
|
||||
|
||||
// Download directly to flash
|
||||
return downloadDirectToFlash(firmwareUrl, _expectedFileSize);
|
||||
for (size_t i = 0; i < servers.size(); i++) {
|
||||
String firmwareUrl = buildFirmwareUrl(servers[i], hwType, channel, toVersion);
|
||||
if (downloadDirectToFlash(firmwareUrl, _expectedFileSize, fromVersion, toVersion, channel)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
@@ -1110,7 +1128,8 @@ bool OTAManager::performCustomUpdate(const String& firmwareUrl, const String& ch
|
||||
|
||||
setStatus(Status::DOWNLOADING);
|
||||
|
||||
bool result = downloadDirectToFlash(firmwareUrl, fileSize);
|
||||
String fromVersion = getCurrentVersion().toString();
|
||||
bool result = downloadDirectToFlash(firmwareUrl, fileSize, fromVersion, version, "custom");
|
||||
|
||||
if (result) {
|
||||
LOG_INFO(TAG, "🚀 Custom firmware installed - device will reboot");
|
||||
@@ -1136,7 +1155,8 @@ void OTAManager::setHardwareVariant(const String& variant) {
|
||||
// correct next hop instead of the absolute latest.
|
||||
String OTAManager::buildLatestUrl(const String& baseUrl, const String& hwType, const String& channel) const {
|
||||
String currentVersion = getCurrentVersion().toString();
|
||||
return baseUrl + "/api/firmware/" + hwType + "/" + channel + "/latest?current_version=" + currentVersion;
|
||||
String hwVersion = _configManager.getHwVersion();
|
||||
return baseUrl + "/api/firmware/" + hwType + "/" + channel + "/latest?hw_version=" + hwVersion + "¤t_version=" + currentVersion;
|
||||
}
|
||||
|
||||
// GET /api/firmware/{hw_type}/{channel}/{version}/info
|
||||
|
||||
Reference in New Issue
Block a user