add install date to firmware versions

This commit is contained in:
proddy
2025-12-24 11:18:22 +01:00
parent 1a3f7fbbee
commit 0557def0b6
6 changed files with 192 additions and 72 deletions

View File

@@ -301,10 +301,11 @@ void System::get_partition_info() {
#ifdef EMSESP_STANDALONE
// dummy data for standalone mode
partition_info_["app0"] = {EMSESP_APP_VERSION, 0};
partition_info_["app1"] = {"", 0};
partition_info_["factory"] = {"", 0};
partition_info_["boot"] = {"", 0};
// version, size, install_date
partition_info_["app0"] = {EMSESP_APP_VERSION, 0, ""};
partition_info_["app1"] = {"", 0, ""};
partition_info_["factory"] = {"", 0, ""};
partition_info_["boot"] = {"", 0, ""};
#else
auto current_partition = (const char *)esp_ota_get_running_partition()->label;
@@ -337,14 +338,27 @@ void System::get_partition_info() {
// get the version from the NVS store, and add to map
if (is_valid) {
PartitionInfo info;
info.size = part->size / 1024; // in KB
PartitionInfo p_info;
p_info.size = part->size / 1024; // set size in KB
// get version from NVS, if not found, use empty string
if (EMSESP::nvs_.isKey(part->label)) {
info.version = EMSESP::nvs_.getString(part->label).c_str();
p_info.version = EMSESP::nvs_.getString(part->label).c_str();
} else {
info.version = ""; // no version, empty string
p_info.version = "";
}
partition_info_[part->label] = info;
// get install date from NTP if active and add
if (ntp_connected_) {
char time_string[25];
time_t now = time(nullptr) - uuid::get_uptime_sec();
strftime(time_string, sizeof(time_string), "%FT%T%z", localtime(&now));
p_info.install_date = time_string;
} else {
p_info.install_date = "";
}
partition_info_[part->label] = p_info;
}
it = esp_partition_next(it);

View File

@@ -77,6 +77,7 @@ enum FUSE_VALUE : uint8_t { ALL = 0, MFG = 1, MODEL = 2, BOARD = 3, REV = 4, BAT
struct PartitionInfo {
std::string version;
size_t size;
std::string install_date; // optional, only available if NTP is connected
};
class System {
@@ -370,9 +371,10 @@ class System {
static void remove_gpio(uint8_t pin, bool also_system = false); // remove a gpio from both valid (optional) and used lists
// Partition info map: partition name -> {version, size}
// Partition info map: partition name -> {version, size, install_date}
std::map<std::string, PartitionInfo, std::less<>, AllocatorPSRAM<std::pair<const std::string, PartitionInfo>>> partition_info_;
static bool set_partition(const char * partitionname);
static bool set_partition(const char * partitionname);
private:
static uuid::log::Logger logger_;

View File

@@ -154,10 +154,11 @@ void WebStatusService::systemStatus(AsyncWebServerRequest * request) {
if (partition.first == (const char *)esp_ota_get_running_partition()->label || partition.second.version.empty() || partition.second.size == 0) {
continue;
}
JsonObject part = partitions.add<JsonObject>();
part["partition"] = partition.first;
part["version"] = partition.second.version;
part["size"] = partition.second.size;
JsonObject part = partitions.add<JsonObject>();
part["partition"] = partition.first;
part["version"] = partition.second.version;
part["size"] = partition.second.size;
part["install_date"] = partition.second.install_date;
}
root["developer_mode"] = EMSESP::system_.developer_mode();