mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
check for fresh install
This commit is contained in:
@@ -1297,6 +1297,21 @@ void EMSESP::start() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// do a quick scan of the filesystem to see if we have a /config folder
|
||||||
|
// so we know if this is a new install or not
|
||||||
|
#ifndef EMSESP_STANDALONE
|
||||||
|
File root = LittleFS.open("/config");
|
||||||
|
bool factory_settings = !root;
|
||||||
|
if (!root) {
|
||||||
|
#ifdef EMSESP_DEBUG
|
||||||
|
Serial.println("No config found, assuming factory settings");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
root.close();
|
||||||
|
#else
|
||||||
|
bool factory_settings = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
esp8266React.begin(); // loads core system services settings (network, mqtt, ap, ntp etc)
|
esp8266React.begin(); // loads core system services settings (network, mqtt, ap, ntp etc)
|
||||||
webLogService.begin(); // start web log service. now we can start capturing logs to the web log
|
webLogService.begin(); // start web log service. now we can start capturing logs to the web log
|
||||||
|
|
||||||
@@ -1315,12 +1330,13 @@ void EMSESP::start() {
|
|||||||
webSettingsService.begin(); // load EMS-ESP Application settings...
|
webSettingsService.begin(); // load EMS-ESP Application settings...
|
||||||
|
|
||||||
// do any system upgrades
|
// do any system upgrades
|
||||||
if (system_.check_upgrade()) {
|
if (system_.check_upgrade(factory_settings)) {
|
||||||
LOG_WARNING("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();
|
||||||
};
|
};
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
// start telnet service if it's enabled
|
// start telnet service if it's enabled
|
||||||
|
|||||||
122
src/system.cpp
122
src/system.cpp
@@ -19,6 +19,8 @@
|
|||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "emsesp.h" // for send_raw_telegram() command
|
#include "emsesp.h" // for send_raw_telegram() command
|
||||||
|
|
||||||
|
#include <semver200.h>
|
||||||
|
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_DEBUG)
|
||||||
#include "test/test.h"
|
#include "test/test.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -1014,44 +1016,81 @@ bool System::check_restore() {
|
|||||||
|
|
||||||
// handle upgrades from previous versions
|
// handle upgrades from previous versions
|
||||||
// returns true if we need a reboot
|
// returns true if we need a reboot
|
||||||
bool System::check_upgrade() {
|
bool System::check_upgrade(bool factory_settings) {
|
||||||
std::string old_version;
|
std::string settingsVersion{};
|
||||||
|
|
||||||
// TODO fix
|
// fetch current version from file
|
||||||
|
EMSESP::webSettingsService.read([&](WebSettings & settings) { settingsVersion = settings.version; });
|
||||||
|
|
||||||
if (version_ != EMSESP_APP_VERSION) {
|
if (settingsVersion.empty() || (settingsVersion.length() < 5) || factory_settings) {
|
||||||
if (version_.empty()) {
|
LOG_DEBUG("No prior version found, preparing fresh install of v%s", EMSESP_APP_VERSION);
|
||||||
LOG_DEBUG("No version, presuming fresh install. Setting to %s", EMSESP_APP_VERSION);
|
settingsVersion = "0.0.0";
|
||||||
old_version = EMSESP_APP_VERSION;
|
|
||||||
} else {
|
// check if its before 3.5.0b12 when we didn't store the version
|
||||||
LOG_DEBUG("Going from version %s to %s", version_, EMSESP_APP_VERSION);
|
// by checking ...
|
||||||
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) {
|
version::Semver200_version settings_version(settingsVersion);
|
||||||
return false; // no upgrades or reboot needed. we're on the latest
|
#ifdef EMSESP_DEBUG
|
||||||
}
|
LOG_NOTICE("Settings version: string %s, major %d, minor %d, patch %d, pre-release %s, build %s",
|
||||||
|
settingsVersion.c_str(),
|
||||||
|
settings_version.major(),
|
||||||
|
settings_version.minor(),
|
||||||
|
settings_version.patch(),
|
||||||
|
settings_version.build().c_str(),
|
||||||
|
settings_version.prerelease().c_str());
|
||||||
|
#endif
|
||||||
|
|
||||||
LOG_DEBUG("Doing upgrade..."); // TODO remove
|
version::Semver200_version this_version(EMSESP_APP_VERSION);
|
||||||
|
#ifdef EMSESP_DEBUG
|
||||||
|
LOG_NOTICE("This version: string %s, major %d, minor %d, patch %d, pre-release %s, build %s",
|
||||||
|
EMSESP_APP_VERSION,
|
||||||
|
this_version.major(),
|
||||||
|
this_version.minor(),
|
||||||
|
this_version.patch(),
|
||||||
|
this_version.prerelease().c_str(),
|
||||||
|
this_version.build().c_str());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// save the new version to the settings
|
||||||
|
|
||||||
|
// TODO put back in after testing!
|
||||||
|
/*
|
||||||
|
EMSESP::webSettingsService.update(
|
||||||
|
[&](WebSettings & settings) {
|
||||||
|
settings.version = EMSESP_APP_VERSION;
|
||||||
|
return StateUpdateResult::CHANGED;
|
||||||
|
},
|
||||||
|
"local");
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
// check variations between versions
|
// compare versions
|
||||||
// get major version
|
|
||||||
|
|
||||||
// get minor version
|
|
||||||
|
|
||||||
// get patch version (ignore alphanumerics)
|
|
||||||
|
|
||||||
bool reboot_required = false;
|
bool reboot_required = false;
|
||||||
|
if (this_version > settings_version) {
|
||||||
|
LOG_NOTICE("Upgrading from version %d.%d.%d-%s to version %d.%d.%d-%s",
|
||||||
|
settings_version.major(),
|
||||||
|
settings_version.minor(),
|
||||||
|
settings_version.patch(),
|
||||||
|
settings_version.prerelease().c_str(),
|
||||||
|
this_version.major(),
|
||||||
|
this_version.minor(),
|
||||||
|
this_version.patch(),
|
||||||
|
this_version.prerelease().c_str());
|
||||||
|
} else if (this_version < settings_version) {
|
||||||
|
LOG_NOTICE("Downgrading from version %d.%d.%d-%s to version %d.%d.%d-%s",
|
||||||
|
settings_version.major(),
|
||||||
|
settings_version.minor(),
|
||||||
|
settings_version.patch(),
|
||||||
|
settings_version.prerelease().c_str(),
|
||||||
|
this_version.major(),
|
||||||
|
this_version.minor(),
|
||||||
|
this_version.patch(),
|
||||||
|
this_version.prerelease().c_str());
|
||||||
|
} else {
|
||||||
|
// same version, do nothing
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return reboot_required;
|
return reboot_required;
|
||||||
}
|
}
|
||||||
@@ -1299,18 +1338,17 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
|
|||||||
node["pbutton gpio"] = settings.pbutton_gpio;
|
node["pbutton gpio"] = settings.pbutton_gpio;
|
||||||
node["led gpio"] = settings.led_gpio;
|
node["led gpio"] = settings.led_gpio;
|
||||||
}
|
}
|
||||||
node["hide led"] = settings.hide_led;
|
node["hide led"] = settings.hide_led;
|
||||||
node["notoken api"] = settings.notoken_api;
|
node["notoken api"] = settings.notoken_api;
|
||||||
node["readonly mode"] = settings.readonly_mode;
|
node["readonly mode"] = settings.readonly_mode;
|
||||||
node["fahrenheit"] = settings.fahrenheit;
|
node["fahrenheit"] = settings.fahrenheit;
|
||||||
node["dallas parasite"] = settings.dallas_parasite;
|
node["dallas parasite"] = settings.dallas_parasite;
|
||||||
node["bool format"] = settings.bool_format;
|
node["bool format"] = settings.bool_format;
|
||||||
node["bool dashboard"] = settings.bool_dashboard;
|
node["bool dashboard"] = settings.bool_dashboard;
|
||||||
node["enum format"] = settings.enum_format;
|
node["enum format"] = settings.enum_format;
|
||||||
node["analog enabled"] = settings.analog_enabled;
|
node["analog enabled"] = settings.analog_enabled;
|
||||||
node["telnet enabled"] = settings.telnet_enabled;
|
node["telnet enabled"] = settings.telnet_enabled;
|
||||||
node["max web log buffer"] = settings.weblog_buffer;
|
node["web log buffer"] = settings.weblog_buffer;
|
||||||
node["web log buffered"] = EMSESP::webLogService.num_log_messages();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Devices - show EMS devices if we have any
|
// Devices - show EMS devices if we have any
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class System {
|
|||||||
void reload_settings();
|
void reload_settings();
|
||||||
void wifi_tweak();
|
void wifi_tweak();
|
||||||
void syslog_init();
|
void syslog_init();
|
||||||
bool check_upgrade();
|
bool check_upgrade(bool factory_settings);
|
||||||
bool check_restore();
|
bool check_restore();
|
||||||
bool heartbeat_json(JsonObject & output);
|
bool heartbeat_json(JsonObject & output);
|
||||||
void send_heartbeat();
|
void send_heartbeat();
|
||||||
@@ -273,7 +273,7 @@ class System {
|
|||||||
|
|
||||||
// EMS-ESP settings
|
// EMS-ESP settings
|
||||||
// copies from WebSettings class in WebSettingsService.h and loaded with reload_settings()
|
// copies from WebSettings class in WebSettingsService.h and loaded with reload_settings()
|
||||||
std::string hostname_ = FACTORY_WIFI_HOSTNAME;
|
std::string hostname_;
|
||||||
String locale_;
|
String locale_;
|
||||||
bool hide_led_;
|
bool hide_led_;
|
||||||
uint8_t led_gpio_;
|
uint8_t led_gpio_;
|
||||||
|
|||||||
Reference in New Issue
Block a user