mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
test upgrade
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
class DummySettings {
|
class DummySettings {
|
||||||
public:
|
public:
|
||||||
|
std::string version{"poerp"};
|
||||||
String locale = "en";
|
String locale = "en";
|
||||||
uint8_t tx_mode = 1;
|
uint8_t tx_mode = 1;
|
||||||
uint8_t ems_bus_id = 0x0B;
|
uint8_t ems_bus_id = 0x0B;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class FSPersistence {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void readFromFS() {
|
void readFromFS() {
|
||||||
|
Serial.println();
|
||||||
Serial.print("Fake reading file ");
|
Serial.print("Fake reading file ");
|
||||||
Serial.println(_filePath);
|
Serial.println(_filePath);
|
||||||
applyDefaults();
|
applyDefaults();
|
||||||
|
|||||||
@@ -1293,13 +1293,20 @@ void EMSESP::start() {
|
|||||||
|
|
||||||
LOG_INFO("Last system reset reason Core0: %s, Core1: %s", system_.reset_reason(0).c_str(), system_.reset_reason(1).c_str());
|
LOG_INFO("Last system reset reason Core0: %s, Core1: %s", system_.reset_reason(0).c_str(), system_.reset_reason(1).c_str());
|
||||||
|
|
||||||
// do any system upgrades
|
// see if we're restoring a settings file
|
||||||
if (system_.check_upgrade()) {
|
if (system_.check_restore()) {
|
||||||
LOG_INFO("System needs a restart to apply new settings. Please wait.");
|
LOG_WARNING("System needs a restart to apply new settings. Please wait.");
|
||||||
system_.system_restart();
|
system_.system_restart();
|
||||||
};
|
};
|
||||||
|
|
||||||
webSettingsService.begin(); // load EMS-ESP Application settings...
|
webSettingsService.begin(); // load EMS-ESP Application settings...
|
||||||
|
|
||||||
|
// do any system upgrades
|
||||||
|
if (system_.check_upgrade()) {
|
||||||
|
LOG_WARNING("System needs a restart to apply new settings. Please wait.");
|
||||||
|
system_.system_restart();
|
||||||
|
};
|
||||||
|
|
||||||
system_.reload_settings(); // ... and store some of the settings locally
|
system_.reload_settings(); // ... and store some of the settings locally
|
||||||
webCustomizationService.begin(); // load the customizations
|
webCustomizationService.begin(); // load the customizations
|
||||||
|
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ MAKE_PSTR(uom_ua, "µA")
|
|||||||
MAKE_PSTR(uom_lmin, "l/min")
|
MAKE_PSTR(uom_lmin, "l/min")
|
||||||
MAKE_PSTR(uom_kw, "kW")
|
MAKE_PSTR(uom_kw, "kW")
|
||||||
MAKE_PSTR(uom_w, "W")
|
MAKE_PSTR(uom_w, "W")
|
||||||
MAKE_PSTR(uom_kb, "kB")
|
MAKE_PSTR(uom_kb, "KB")
|
||||||
MAKE_PSTR(uom_dbm, "dBm")
|
MAKE_PSTR(uom_dbm, "dBm")
|
||||||
MAKE_PSTR(uom_fahrenheit, "°F")
|
MAKE_PSTR(uom_fahrenheit, "°F")
|
||||||
MAKE_PSTR(uom_mv, "mV")
|
MAKE_PSTR(uom_mv, "mV")
|
||||||
|
|||||||
@@ -290,6 +290,8 @@ void System::syslog_init() {
|
|||||||
// read some specific system settings to store locally for faster access
|
// read some specific system settings to store locally for faster access
|
||||||
void System::reload_settings() {
|
void System::reload_settings() {
|
||||||
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
||||||
|
version_ = settings.version;
|
||||||
|
|
||||||
pbutton_gpio_ = settings.pbutton_gpio;
|
pbutton_gpio_ = settings.pbutton_gpio;
|
||||||
analog_enabled_ = settings.analog_enabled;
|
analog_enabled_ = settings.analog_enabled;
|
||||||
low_clock_ = settings.low_clock;
|
low_clock_ = settings.low_clock;
|
||||||
@@ -969,10 +971,8 @@ void System::show_system(uuid::console::Shell & shell) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle upgrades from previous versions
|
// see if there is a restore of an older settings file that needs to be applied
|
||||||
// or managing an uploaded files to replace settings files
|
bool System::check_restore() {
|
||||||
// returns true if we need a reboot
|
|
||||||
bool System::check_upgrade() {
|
|
||||||
bool reboot_required = false;
|
bool reboot_required = false;
|
||||||
|
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
@@ -1012,6 +1012,50 @@ bool System::check_upgrade() {
|
|||||||
return reboot_required;
|
return reboot_required;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle upgrades from previous versions
|
||||||
|
// returns true if we need a reboot
|
||||||
|
bool System::check_upgrade() {
|
||||||
|
std::string old_version;
|
||||||
|
|
||||||
|
// TODO fix
|
||||||
|
|
||||||
|
if (version_ != EMSESP_APP_VERSION) {
|
||||||
|
if (version_.empty()) {
|
||||||
|
LOG_DEBUG("No version, presuming fresh install. Setting to %s", EMSESP_APP_VERSION);
|
||||||
|
old_version = EMSESP_APP_VERSION;
|
||||||
|
} else {
|
||||||
|
LOG_DEBUG("Going from version %s to %s", version_, EMSESP_APP_VERSION);
|
||||||
|
old_version = version_;
|
||||||
|
}
|
||||||
|
// save the new version
|
||||||
|
version_ = EMSESP_APP_VERSION;
|
||||||
|
EMSESP::webSettingsService.update(
|
||||||
|
[&](WebSettings & settings) {
|
||||||
|
settings.version = EMSESP_APP_VERSION;
|
||||||
|
return StateUpdateResult::CHANGED;
|
||||||
|
},
|
||||||
|
"local");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (old_version == EMSESP_APP_VERSION) {
|
||||||
|
return false; // no upgrades or reboot needed. we're on the latest
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_DEBUG("Doing upgrade..."); // TODO remove
|
||||||
|
|
||||||
|
|
||||||
|
// check variations between versions
|
||||||
|
// get major version
|
||||||
|
|
||||||
|
// get minor version
|
||||||
|
|
||||||
|
// get patch version (ignore alphanumerics)
|
||||||
|
|
||||||
|
bool reboot_required = false;
|
||||||
|
|
||||||
|
return reboot_required;
|
||||||
|
}
|
||||||
|
|
||||||
// list commands
|
// list commands
|
||||||
bool System::command_commands(const char * value, const int8_t id, JsonObject & output) {
|
bool System::command_commands(const char * value, const int8_t id, JsonObject & output) {
|
||||||
return Command::list(EMSdevice::DeviceType::SYSTEM, output);
|
return Command::list(EMSdevice::DeviceType::SYSTEM, output);
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ class System {
|
|||||||
void wifi_tweak();
|
void wifi_tweak();
|
||||||
void syslog_init();
|
void syslog_init();
|
||||||
bool check_upgrade();
|
bool check_upgrade();
|
||||||
|
bool check_restore();
|
||||||
bool heartbeat_json(JsonObject & output);
|
bool heartbeat_json(JsonObject & output);
|
||||||
void send_heartbeat();
|
void send_heartbeat();
|
||||||
void send_info_mqtt(const char * event_str, bool send_ntp = false);
|
void send_info_mqtt(const char * event_str, bool send_ntp = false);
|
||||||
@@ -294,6 +295,7 @@ class System {
|
|||||||
uint8_t bool_format_;
|
uint8_t bool_format_;
|
||||||
uint8_t enum_format_;
|
uint8_t enum_format_;
|
||||||
bool readonly_mode_;
|
bool readonly_mode_;
|
||||||
|
std::string version_;
|
||||||
|
|
||||||
// ethernet
|
// ethernet
|
||||||
uint8_t phy_type_;
|
uint8_t phy_type_;
|
||||||
|
|||||||
@@ -80,6 +80,10 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) {
|
|||||||
|
|
||||||
// call on initialization and also when settings are updated via web or console
|
// call on initialization and also when settings are updated via web or console
|
||||||
StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) {
|
StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) {
|
||||||
|
// load the version of the settings
|
||||||
|
// will be picked up in System::check_upgrade()
|
||||||
|
settings.version = root["version"] || "";
|
||||||
|
|
||||||
// load default GPIO configuration based on board profile
|
// load default GPIO configuration based on board profile
|
||||||
std::vector<int8_t> data; // // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode
|
std::vector<int8_t> data; // // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode
|
||||||
#if CONFIG_IDF_TARGET_ESP32C3
|
#if CONFIG_IDF_TARGET_ESP32C3
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ namespace emsesp {
|
|||||||
|
|
||||||
class WebSettings {
|
class WebSettings {
|
||||||
public:
|
public:
|
||||||
|
std::string version;
|
||||||
String locale;
|
String locale;
|
||||||
uint8_t tx_mode;
|
uint8_t tx_mode;
|
||||||
uint8_t ems_bus_id;
|
uint8_t ems_bus_id;
|
||||||
|
|||||||
Reference in New Issue
Block a user