diff --git a/lib/framework/FSPersistence.h b/lib/framework/FSPersistence.h index fb77e99ad..0b66de2f2 100644 --- a/lib/framework/FSPersistence.h +++ b/lib/framework/FSPersistence.h @@ -41,7 +41,6 @@ class FSPersistence { Serial.println(); #endif #endif - _statefulService->updateWithoutPropagation(jsonObject, _stateUpdater); settingsFile.close(); return; @@ -96,6 +95,7 @@ class FSPersistence { // debug added by Proddy #if defined(EMSESP_DEBUG) #if defined(EMSESP_USE_SERIAL) + Serial.println(); Serial.printf("Writing to file: %s: ", _filePath); serializeJson(jsonDocument, Serial); Serial.println(); diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 5d4d6c690..e1ab03e42 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -192,6 +192,7 @@ void Mqtt::loop() { // print MQTT log and other stuff to console void Mqtt::show_mqtt(uuid::console::Shell & shell) { shell.printfln("MQTT is %s", connected() ? F_(connected) : F_(disconnected)); + shell.printfln("MQTT Entity ID format is %d", entity_format_); shell.printfln("MQTT publish errors: %lu", mqtt_publish_fails_); shell.println(); diff --git a/src/system.cpp b/src/system.cpp index 8dc5341e6..e48ca2618 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -220,7 +220,7 @@ void System::wifi_reconnect() { void System::format(uuid::console::Shell & shell) { auto msg = ("Formatting file system. This will reset all settings to their defaults"); shell.logger().warning(msg); - shell.flush(); + // shell.flush(); EMSuart::stop(); @@ -1015,78 +1015,70 @@ bool System::check_restore() { } // handle upgrades from previous versions +// this function will not be called on a clean install, with no settings files yet created // returns true if we need a reboot bool System::check_upgrade(bool factory_settings) { - std::string settingsVersion{}; + bool missing_version = true; + std::string settingsVersion{EMSESP_APP_VERSION}; // default setting version - // fetch current version from file - EMSESP::webSettingsService.read([&](WebSettings & settings) { settingsVersion = settings.version; }); + if (!factory_settings) { + // fetch current version from settings file + EMSESP::webSettingsService.read([&](WebSettings & settings) { settingsVersion = settings.version.c_str(); }); - if (settingsVersion.empty() || (settingsVersion.length() < 5) || factory_settings) { - LOG_DEBUG("No prior version found, preparing fresh install of v%s", EMSESP_APP_VERSION); - settingsVersion = "0.0.0"; - - // check if its before 3.5.0b12 when we didn't store the version - // by checking ... + // see if we're missing a version, will be < 3.5.0b13 from Dec 23 2022 + missing_version = (settingsVersion.empty() || (settingsVersion.length() < 5)); + if (missing_version) { +#ifdef EMSESP_DEBUG + LOG_DEBUG("No version information found (%s)", settingsVersion.c_str()); +#endif + settingsVersion = "3.4.4"; // this was the last stable version + } } version::Semver200_version settings_version(settingsVersion); -#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 - 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 + if (!missing_version) { + LOG_INFO("Current version from settings is %d.%d.%d-%s", + settings_version.major(), + settings_version.minor(), + settings_version.patch(), + settings_version.prerelease().c_str()); + } - // save the new version to the settings - - // TODO put back in after testing! - /* + // always save the new version to the settings EMSESP::webSettingsService.update( [&](WebSettings & settings) { settings.version = EMSESP_APP_VERSION; return StateUpdateResult::CHANGED; }, "local"); - */ + if (factory_settings) { + return false; // fresh install, do nothing + } + + version::Semver200_version this_version(EMSESP_APP_VERSION); // compare versions 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()); + LOG_NOTICE("Upgrading to version %d.%d.%d-%s", this_version.major(), this_version.minor(), this_version.patch(), this_version.prerelease().c_str()); + + // if we're coming from 3.4.4 or 3.5.0b14 then we need to apply new settings + if (missing_version) { +#ifdef EMSESP_DEBUG + LOG_DEBUG("Setting MQTT ID Entity to v3.4 format"); +#endif + EMSESP::esp8266React.getMqttSettingsService()->update( + [&](MqttSettings & mqttSettings) { + mqttSettings.entity_format = 0; // use old Entity ID format from v3.4 + return StateUpdateResult::CHANGED; + }, + "local"); + } + } 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()); + LOG_NOTICE("Downgrading to version %d.%d.%d-%s", this_version.major(), this_version.minor(), this_version.patch(), this_version.prerelease().c_str()); } else { // same version, do nothing return false; diff --git a/src/system.h b/src/system.h index 8c96e7858..5b98edd1f 100644 --- a/src/system.h +++ b/src/system.h @@ -295,7 +295,7 @@ class System { uint8_t bool_format_; uint8_t enum_format_; bool readonly_mode_; - std::string version_; + String version_; // ethernet uint8_t phy_type_; diff --git a/src/web/WebSettingsService.cpp b/src/web/WebSettingsService.cpp index 5b3bd8c2c..e9c49d434 100644 --- a/src/web/WebSettingsService.cpp +++ b/src/web/WebSettingsService.cpp @@ -83,7 +83,7 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) { 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"] || EMSESP_DEFAULT_VERSION; + settings.version = root["version"] | EMSESP_DEFAULT_VERSION; // load default GPIO configuration based on board profile std::vector data; // // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode diff --git a/src/web/WebSettingsService.h b/src/web/WebSettingsService.h index 2addbb4cb..5a08207bc 100644 --- a/src/web/WebSettingsService.h +++ b/src/web/WebSettingsService.h @@ -29,41 +29,41 @@ namespace emsesp { class WebSettings { public: - std::string version; - String locale; - uint8_t tx_mode; - uint8_t ems_bus_id; - bool shower_timer; - bool shower_alert; - uint8_t shower_alert_trigger; - uint8_t shower_alert_coldshot; - bool syslog_enabled; - int8_t syslog_level; // uuid::log::Level - uint32_t syslog_mark_interval; - String syslog_host; - uint16_t syslog_port; - bool trace_raw; - uint8_t rx_gpio; - uint8_t tx_gpio; - uint8_t dallas_gpio; - bool dallas_parasite; - uint8_t led_gpio; - bool hide_led; - bool low_clock; - bool telnet_enabled; - bool notoken_api; - bool readonly_mode; - bool analog_enabled; - uint8_t pbutton_gpio; - uint8_t solar_maxflow; - String board_profile; - uint8_t bool_format; - uint8_t bool_dashboard; - uint8_t enum_format; - int8_t weblog_level; - uint8_t weblog_buffer; - bool weblog_compact; - bool fahrenheit; + String version; + String locale; + uint8_t tx_mode; + uint8_t ems_bus_id; + bool shower_timer; + bool shower_alert; + uint8_t shower_alert_trigger; + uint8_t shower_alert_coldshot; + bool syslog_enabled; + int8_t syslog_level; // uuid::log::Level + uint32_t syslog_mark_interval; + String syslog_host; + uint16_t syslog_port; + bool trace_raw; + uint8_t rx_gpio; + uint8_t tx_gpio; + uint8_t dallas_gpio; + bool dallas_parasite; + uint8_t led_gpio; + bool hide_led; + bool low_clock; + bool telnet_enabled; + bool notoken_api; + bool readonly_mode; + bool analog_enabled; + uint8_t pbutton_gpio; + uint8_t solar_maxflow; + String board_profile; + uint8_t bool_format; + uint8_t bool_dashboard; + uint8_t enum_format; + int8_t weblog_level; + uint8_t weblog_buffer; + bool weblog_compact; + bool fahrenheit; uint8_t phy_type; int8_t eth_power; // -1 means disabled