diff --git a/docs/source/Config/Config.rst b/docs/source/Config/Config.rst index 6eba783081..eca0117a31 100644 --- a/docs/source/Config/Config.rst +++ b/docs/source/Config/Config.rst @@ -298,3 +298,15 @@ N.B. the maximum possible duration depends on the used core library version and Sleep on connection failure --------------------------- +CDN (Content delivery network) +------------------------------ + +The **Custom CDN URL** can be set to a server url (https preferred, they are downloaded by the browser, **not** by the ESPEasy unit) that hosts *all* files as listed on :ref:`ExternalHostedStaticFiles` (System variables can be used to customize the URL). + +To reduce the build size where possible, some builds fetch the javascript (.js) and .css UI files from an external server, as this is used in the browser only. The default location for this data is the Content Delivery Network (CDN) of ``jsdelivr.net``, where these file are uploaded for specific releases. + +For users that want to host these files in their local network, or if the files on jsdeliver.net have expired, an alternative location for these .js and .css file can be configured. + +Setting this location will **override** the default CDN url, except for your Custom build that may already *have* the CDN url set, then this setting won't be available! + +**Warning**: If an invalid location is set, the UI will be distorted, though should still be usable. diff --git a/docs/source/Reference/ExternalHostedStaticFiles.rst b/docs/source/Reference/ExternalHostedStaticFiles.rst index 4c85451b5f..01b38cb9d2 100644 --- a/docs/source/Reference/ExternalHostedStaticFiles.rst +++ b/docs/source/Reference/ExternalHostedStaticFiles.rst @@ -1,3 +1,5 @@ +.. _ExternalHostedStaticFiles: + External Hosted Static Files **************************** diff --git a/docs/source/Tools/Tools.rst b/docs/source/Tools/Tools.rst index f934c154f9..5fd13ec11e 100644 --- a/docs/source/Tools/Tools.rst +++ b/docs/source/Tools/Tools.rst @@ -1043,20 +1043,73 @@ See the ``Custom-sample.h`` file for some examples. Allow Fetch by Command ---------------------- -This checkbox allows provisioning via commands. -These commands are not restricted, so they can also be given via HTTP or MQTT. +This list of checkboxes per file allows provisioning via commands. +These ``Provision*`` commands are not restricted, so they can also be given via HTTP or MQTT. However, they can only be executed when: -* Allow Fetch by Command is enabled -* the file to download is checked +* the file at Allow Fetch by Command is checked +* the file at Files to Download is *also* checked * URL (+ optional credentials) is stored The commands are: +Changed: 2023-11-18: Single-word commands split into 2 words: ``Provision,[,]`` + +* ``Provision,Config`` Fetch ``config.dat`` +* ``Provision,Security`` Fetch ``security.dat`` +* ``Provision,Notification`` Fetch ``notification.dat`` +* ``Provision,Provision`` Fetch ``provisioning.dat`` +* ``Provision,Rules,1`` Fetch ``rules1.txt`` +* ``Provision,CustomCdnUrl`` Fetch ``customcdnurl.dat`` (When the Custom CDN Url feature is included in the build.) + +* ``Provision,Firmware,`` Fetch and install ``FirmwareBinary.bin`` on the unit + +Once the Firmware download & install is finished the outcome is completed by a generated event (gets the download filename as an argument): + +* ``ProvisionFirmware#Success=`` When download and install where succesfull +* ``ProvisionFirmware#Failed=`` When something went wrong during download or install + +These events can be handled in rules, an provisioning support script could look like this: + +.. code-block:: none + + On updateSettings Do + provision,provision + provision,config + Endon + + On updateCredentials Do + provision,security + Endon + + On updateRules Do + provision,rules,1 + provision,rules,2 + provision,rules,3 + Endon + + On updateRulesSettings Do + AsyncEvent,updateSettings + AsyncEvent,updateRules + Reboot + Endon + + // e.g. + // event,PerformFirmwareUpdate=firmware_max_ESP32_16M8M_LittleFS.bin + On PerformFirmwareUpdate=* Do + pwm,2,100,0,8 + provision,firmware,%eventvalue1% + Endon + + On provisionfirmware#success=* Do + gpio,2,0 + Reboot + Endon + + On provisionfirmware#failure Do + gpio,2,0 + Reboot + Endon + -* ``ProvisionConfig`` Fetch ``config.dat`` -* ``ProvisionSecurity`` Fetch ``security.dat`` -* ``ProvisionNotification`` Fetch ``notification.dat`` -* ``ProvisionProvision`` Fetch ``provisioning.dat`` -* ``ProvisionRules,1`` Fetch ``rules1.txt`` diff --git a/docs/source/Tools/images/SettingsArchive_download1.png b/docs/source/Tools/images/SettingsArchive_download1.png index 0e53d4ac63..e47932e286 100644 Binary files a/docs/source/Tools/images/SettingsArchive_download1.png and b/docs/source/Tools/images/SettingsArchive_download1.png differ diff --git a/docs/source/Tools/images/SettingsArchive_provisioning.png b/docs/source/Tools/images/SettingsArchive_provisioning.png index 662be22a9e..28c5c3ac2f 100644 Binary files a/docs/source/Tools/images/SettingsArchive_provisioning.png and b/docs/source/Tools/images/SettingsArchive_provisioning.png differ diff --git a/src/Custom-sample.h b/src/Custom-sample.h index f6ff28e00a..4ce203b8c2 100644 --- a/src/Custom-sample.h +++ b/src/Custom-sample.h @@ -151,6 +151,8 @@ #define DEFAULT_LONGITUDE 0.0f // Default Longitude #define DEFAULT_SYSLOG_IP "" // Syslog IP Address +#define DEFAULT_SYSLOG_PORT 0 // Standard syslog port: 514 +#define DEFAULT_SYSLOG_FACILITY 0 // kern #define DEFAULT_SYSLOG_LEVEL 0 // Syslog Log Level #define DEFAULT_SERIAL_LOG_LEVEL LOG_LEVEL_INFO // Serial Log Level #define DEFAULT_WEB_LOG_LEVEL LOG_LEVEL_INFO // Web Log Level @@ -159,13 +161,16 @@ #define DEFAULT_USE_SERIAL true // (true|false) Enable Logging to the Serial Port #define DEFAULT_SERIAL_BAUD 115200 // Serial Port Baud Rate -#define DEFAULT_SYSLOG_FACILITY 0 // kern #define DEFAULT_SYNC_UDP_PORT 8266 // Used for ESPEasy p2p. (IANA registered port: 8266) #define BUILD_NO_DEBUG +// Custom built-in url for hosting JavaScript and CSS files. +#define CUSTOM_BUILD_CDN_URL "https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega/static/" + + // Special SSID/key setup only to be used in custom builds. diff --git a/src/src/Commands/InternalCommands.cpp b/src/src/Commands/InternalCommands.cpp index 79a647ba54..9b32c341cd 100644 --- a/src/src/Commands/InternalCommands.cpp +++ b/src/src/Commands/InternalCommands.cpp @@ -414,14 +414,17 @@ bool executeInternalCommand(command_case_data & data) COMMAND_CASE_A("posttohttp", Command_HTTP_PostToHTTP, -1); // HTTP.h #endif // if FEATURE_POST_TO_HTTP #if FEATURE_CUSTOM_PROVISIONING - COMMAND_CASE_A( "provisionconfig", Command_Provisioning_Config, 0); // Provisioning.h - COMMAND_CASE_A( "provisionsecurity", Command_Provisioning_Security, 0); // Provisioning.h + COMMAND_CASE_A( "provision", Command_Provisioning_Dispatcher, -1); // Provisioning.h + #ifdef PLUGIN_BUILD_MAX_ESP32 // FIXME DEPRECATED: Fallback for temporary backward compatibility + COMMAND_CASE_A( "provisionconfig", Command_Provisioning_ConfigFallback, 0); // Provisioning.h + COMMAND_CASE_A( "provisionsecurity", Command_Provisioning_SecurityFallback, 0); // Provisioning.h #if FEATURE_NOTIFIER - COMMAND_CASE_A( "provisionnotification", Command_Provisioning_Notification, 0); // Provisioning.h + COMMAND_CASE_A( "provisionnotification", Command_Provisioning_NotificationFallback, 0); // Provisioning.h #endif - COMMAND_CASE_A( "provisionprovision", Command_Provisioning_Provision, 0); // Provisioning.h - COMMAND_CASE_A( "provisionrules", Command_Provisioning_Rules, 1); // Provisioning.h - COMMAND_CASE_A( "provisionfirmware", Command_Provisioning_Firmware, 1); // Provisioning.h + COMMAND_CASE_A( "provisionprovision", Command_Provisioning_ProvisionFallback, 0); // Provisioning.h + COMMAND_CASE_A( "provisionrules", Command_Provisioning_RulesFallback, 1); // Provisioning.h + COMMAND_CASE_A( "provisionfirmware", Command_Provisioning_FirmwareFallback, 1); // Provisioning.h + #endif // ifdef PLUGIN_BUILD_MAX_ESP32 #endif COMMAND_CASE_A( "pulse", Command_GPIO_Pulse, 3); // GPIO.h #if FEATURE_MQTT diff --git a/src/src/Commands/Provisioning.cpp b/src/src/Commands/Provisioning.cpp index 8d0506a6d7..ce7ba429ad 100644 --- a/src/src/Commands/Provisioning.cpp +++ b/src/src/Commands/Provisioning.cpp @@ -9,46 +9,129 @@ # include "../Helpers/Networking.h" # include "../Helpers/StringConverter.h" -String Command_Provisioning_Config(struct EventStruct *event, const char *Line) +String Command_Provisioning_Dispatcher(struct EventStruct *event, + const char *Line) +{ + const String cmd = parseString(Line, 2); + + if (equals(cmd, F("config"))) { + return Command_Provisioning_Config(); + } else + if (equals(cmd, F("firmware"))) { + return Command_Provisioning_Firmware(event, Line); + } else + # if FEATURE_NOTIFIER + if (equals(cmd, F("notification"))) { + return Command_Provisioning_Notification(); + } else + # endif // if FEATURE_NOTIFIER + if (equals(cmd, F("provision"))) { + return Command_Provisioning_Provision(); + } else + if (equals(cmd, F("rules"))) { + return Command_Provisioning_Rules(event); + } else + if (equals(cmd, F("security"))) { + return Command_Provisioning_Security(); + } + return return_command_failed_flashstr(); +} + +String Command_Provisioning_Config() { return downloadFileType(FileType::CONFIG_DAT); } -String Command_Provisioning_Security(struct EventStruct *event, const char *Line) +String Command_Provisioning_Security() { return downloadFileType(FileType::SECURITY_DAT); } -#if FEATURE_NOTIFIER -String Command_Provisioning_Notification(struct EventStruct *event, const char *Line) +# if FEATURE_NOTIFIER +String Command_Provisioning_Notification() { return downloadFileType(FileType::NOTIFICATION_DAT); } -#endif -String Command_Provisioning_Provision(struct EventStruct *event, const char *Line) +# endif // if FEATURE_NOTIFIER + +String Command_Provisioning_Provision() { return downloadFileType(FileType::PROVISIONING_DAT); } -String Command_Provisioning_Rules(struct EventStruct *event, const char *Line) +String Command_Provisioning_Rules(struct EventStruct *event) +{ + if ((event->Par2 <= 0) || (event->Par2 > 4)) { + return F("Provision,Rules: rules index out of range"); + } + return downloadFileType(FileType::RULES_TXT, event->Par2 - 1); +} + +String Command_Provisioning_Firmware(struct EventStruct *event, const char *Line) +{ + // FIXME TD-er: Must only allow to use set prefix in the provisioning settings + const String url = parseStringToEndKeepCase(Line, 3); + String error; + + downloadFirmware(url, error); // Events are sent from download handler + return error; +} + +# ifdef PLUGIN_BUILD_MAX_ESP32 +void Command_Provisioning_DeprecatedMessage(const String& param) { + addLog(LOG_LEVEL_ERROR, strformat(F("WARNING: 'Provision%s' is deprecated, change to 'Provision,%s'"), param.c_str(), param.c_str())); +} + +String Command_Provisioning_ConfigFallback(struct EventStruct *event, const char *Line) +{ + Command_Provisioning_DeprecatedMessage(F("Config")); + return Command_Provisioning_Config(); +} + +String Command_Provisioning_SecurityFallback(struct EventStruct *event, const char *Line) +{ + Command_Provisioning_DeprecatedMessage(F("Security")); + return Command_Provisioning_Security(); +} + +# if FEATURE_NOTIFIER +String Command_Provisioning_NotificationFallback(struct EventStruct *event, const char *Line) +{ + Command_Provisioning_DeprecatedMessage(F("Notification")); + return Command_Provisioning_Notification(); +} + +String Command_Provisioning_ProvisionFallback(struct EventStruct *event, const char *Line) { + Command_Provisioning_DeprecatedMessage(F("Provision")); + return Command_Provisioning_Provision(); +} + +String Command_Provisioning_RulesFallback(struct EventStruct *event, const char *Line) +{ + Command_Provisioning_DeprecatedMessage(F("Rules,")); + if ((event->Par1 <= 0) || (event->Par1 > 4)) { return F("ProvisionRules: rules index out of range"); } return downloadFileType(FileType::RULES_TXT, event->Par1 - 1); } -String Command_Provisioning_Firmware(struct EventStruct *event, const char *Line) +String Command_Provisioning_FirmwareFallback(struct EventStruct *event, const char *Line) { + Command_Provisioning_DeprecatedMessage(F("Firmware,")); + // FIXME TD-er: Must only allow to use set prefix in the provisioning settings const String url = parseStringToEndKeepCase(Line, 2); String error; - if (downloadFirmware(url, error)) { - // TODO TD-er: send events - } + + downloadFirmware(url, error); return error; } +# endif // if FEATURE_NOTIFIER + +# endif // ifdef PLUGIN_BUILD_MAX_ESP32 #endif // if FEATURE_CUSTOM_PROVISIONING diff --git a/src/src/Commands/Provisioning.h b/src/src/Commands/Provisioning.h index bc7316d8c8..99b504c1f8 100644 --- a/src/src/Commands/Provisioning.h +++ b/src/src/Commands/Provisioning.h @@ -7,22 +7,39 @@ class String; -String Command_Provisioning_Config(struct EventStruct *event, - const char *Line); -String Command_Provisioning_Security(struct EventStruct *event, - const char *Line); -#if FEATURE_NOTIFIER -String Command_Provisioning_Notification(struct EventStruct *event, - const char *Line); -#endif -String Command_Provisioning_Provision(struct EventStruct *event, - const char *Line); -String Command_Provisioning_Rules(struct EventStruct *event, - const char *Line); +String Command_Provisioning_Dispatcher(struct EventStruct *event, + const char *Line); +String Command_Provisioning_Config(); +String Command_Provisioning_Security(); +# if FEATURE_NOTIFIER +String Command_Provisioning_Notification(); +# endif // if FEATURE_NOTIFIER +String Command_Provisioning_Provision(); + +String Command_Provisioning_Rules(struct EventStruct *event); String Command_Provisioning_Firmware(struct EventStruct *event, const char *Line); +// FIXME DEPRECATED! +# ifdef PLUGIN_BUILD_MAX_ESP32 +String Command_Provisioning_ConfigFallback(struct EventStruct *event, + const char *Line); +String Command_Provisioning_SecurityFallback(struct EventStruct *event, + const char *Line); +# if FEATURE_NOTIFIER +String Command_Provisioning_NotificationFallback(struct EventStruct *event, + const char *Line); +# endif // if FEATURE_NOTIFIER +String Command_Provisioning_ProvisionFallback(struct EventStruct *event, + const char *Line); +String Command_Provisioning_RulesFallback(struct EventStruct *event, + const char *Line); + +String Command_Provisioning_FirmwareFallback(struct EventStruct *event, + const char *Line); +# endif // ifdef PLUGIN_BUILD_MAX_ESP32 + #endif // if FEATURE_CUSTOM_PROVISIONING #endif // ifndef COMMANDS_PROVISIONING_H diff --git a/src/src/CustomBuild/CompiletimeDefines.cpp b/src/src/CustomBuild/CompiletimeDefines.cpp index 506c30912f..775ef5fb48 100644 --- a/src/src/CustomBuild/CompiletimeDefines.cpp +++ b/src/src/CustomBuild/CompiletimeDefines.cpp @@ -112,8 +112,8 @@ const __FlashStringHelper * get_CDN_url_prefix() { #else // Some fallback tag // FIXME TD-er: Not sure which is better, serving the latest (which will have caching issues) or a tag which will become outdated - return F("https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega-20220809/static/"); - //return F("https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy/static/"); + return F("https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega/static/"); + //return F("https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega-20231013/static/"); #endif } diff --git a/src/src/CustomBuild/ESPEasyDefaults.h b/src/src/CustomBuild/ESPEasyDefaults.h index 08f1c005e0..d4eba68df9 100644 --- a/src/src/CustomBuild/ESPEasyDefaults.h +++ b/src/src/CustomBuild/ESPEasyDefaults.h @@ -366,6 +366,9 @@ #ifndef DEFAULT_SYSLOG_FACILITY #define DEFAULT_SYSLOG_FACILITY 0 // kern #endif +#ifndef DEFAULT_SYSLOG_PORT +#define DEFAULT_SYSLOG_PORT 0 +#endif #ifndef DEFAULT_SYNC_UDP_PORT #define DEFAULT_SYNC_UDP_PORT 8266 // Used for ESPEasy p2p. (IANA registered port: 8266) diff --git a/src/src/CustomBuild/StorageLayout.h b/src/src/CustomBuild/StorageLayout.h index 4e1d4d90ef..c9903597b5 100644 --- a/src/src/CustomBuild/StorageLayout.h +++ b/src/src/CustomBuild/StorageLayout.h @@ -55,7 +55,18 @@ */ #ifndef DAT_BASIC_SETTINGS_SIZE -# define DAT_BASIC_SETTINGS_SIZE 4096 +// For size of SettingsStruct stored at this area in config.dat +// See: run_compiletime_checks() +#ifdef ESP8266 +# if FEATURE_NON_STANDARD_24_TASKS +# define DAT_BASIC_SETTINGS_SIZE 4096 // Current Settings Struct size is ~2.3k, leave some room to extend +#else +# define DAT_BASIC_SETTINGS_SIZE 3072 // Current Settings Struct size is ~1.3k, leave some room to extend +#endif +#endif +#ifdef ESP32 +# define DAT_BASIC_SETTINGS_SIZE 6144 // Current Settings Struct size is ~3k, leave some room to extend +#endif #endif // ifndef DAT_BASIC_SETTINGS_SIZE @@ -95,6 +106,11 @@ # define DAT_EXTDCONTR_CRED_SIZE 1024 #endif // ifndef DAT_EXTDCONTR_CRED_SIZE +#ifndef DAT_CDN_SIZE +# define DAT_CDN_SIZE 1024 +#endif + + /* @@ -123,11 +139,15 @@ # define DAT_OFFSET_TASKS 4096 // 0x1000 each task = 2k, (1024 basic + 1024 bytes custom) # endif // ifndef DAT_OFFSET_TASKS # ifndef DAT_OFFSET_CONTROLLER - # define DAT_OFFSET_CONTROLLER (DAT_OFFSET_TASKS + (DAT_TASKS_DISTANCE * TASKS_MAX)) // each controller = 1k, 4 max + # define DAT_OFFSET_CONTROLLER (DAT_OFFSET_TASKS + (DAT_TASKS_DISTANCE * TASKS_MAX)) // each controller = 1k, 3 max, DAT_OFFSET_CDN is at position of any 4th controller. # endif // ifndef DAT_OFFSET_CONTROLLER # ifndef DAT_OFFSET_CUSTOM_CONTROLLER - # define DAT_OFFSET_CUSTOM_CONTROLLER (DAT_OFFSET_CONTROLLER + (DAT_CONTROLLER_SIZE * CONTROLLER_MAX)) // each custom controller config = 1k, 4 max + # define DAT_OFFSET_CUSTOM_CONTROLLER (DAT_OFFSET_CONTROLLER + (DAT_CONTROLLER_SIZE * CONTROLLER_MAX)) // each custom controller config = 1k, 3 max # endif // ifndef DAT_OFFSET_CUSTOM_CONTROLLER + # ifndef DAT_OFFSET_CDN + # define DAT_OFFSET_CDN (DAT_OFFSET_CUSTOM_CONTROLLER - DAT_CDN_SIZE) // single CDN settings block of 1k + # endif + # ifndef CONFIG_FILE_SIZE # define CONFIG_FILE_SIZE 65536 # endif // ifndef CONFIG_FILE_SIZE @@ -143,6 +163,9 @@ # ifndef DAT_OFFSET_CUSTOM_CONTROLLER # define DAT_OFFSET_CUSTOM_CONTROLLER 32768 // each custom controller config = 1k, 4 max. # endif // ifndef DAT_OFFSET_CUSTOM_CONTROLLER + # ifndef DAT_OFFSET_CDN + # define DAT_OFFSET_CDN (DAT_OFFSET_TASKS - DAT_CDN_SIZE) // single CDN settings block of 1k + # endif # ifdef LIMIT_BUILD_SIZE // Limit the config size for 1M builds, since their file system is also quite small # ifndef CONFIG_FILE_SIZE @@ -166,6 +189,9 @@ # ifndef DAT_OFFSET_CUSTOM_CONTROLLER # define DAT_OFFSET_CUSTOM_CONTROLLER 12288 // each custom controller config = 1k, 4 max. # endif // ifndef DAT_OFFSET_CUSTOM_CONTROLLER + # ifndef DAT_OFFSET_CDN + # define DAT_OFFSET_CDN (DAT_OFFSET_CONTROLLER - DAT_CDN_SIZE) // single CDN settings block of 1k + # endif # ifndef CONFIG_FILE_SIZE # define CONFIG_FILE_SIZE 131072 # endif // ifndef CONFIG_FILE_SIZE diff --git a/src/src/CustomBuild/define_plugin_sets.h b/src/src/CustomBuild/define_plugin_sets.h index 8e5333fec7..0a9a043bb5 100644 --- a/src/src/CustomBuild/define_plugin_sets.h +++ b/src/src/CustomBuild/define_plugin_sets.h @@ -2942,8 +2942,22 @@ To create/register a plugin, you have to : #endif #ifndef FEATURE_SETTINGS_ARCHIVE +#ifdef ESP32 +#define FEATURE_SETTINGS_ARCHIVE 1 +#else #define FEATURE_SETTINGS_ARCHIVE 0 #endif +#endif + + +#if FEATURE_SETTINGS_ARCHIVE +#if defined(FEATURE_DOWNLOAD) && !FEATURE_DOWNLOAD +#undef FEATURE_DOWNLOAD +#endif +#ifndef FEATURE_DOWNLOAD +#define FEATURE_DOWNLOAD 1 +#endif +#endif #ifndef FEATURE_SSDP #define FEATURE_SSDP 0 @@ -3167,18 +3181,39 @@ To create/register a plugin, you have to : #ifndef FEATURE_CHART_STORAGE_LAYOUT #ifdef ESP32 - #define FEATURE_CHART_SETTINGS_FILE_LAYOUT 1 + #define FEATURE_CHART_STORAGE_LAYOUT 1 #endif #ifdef ESP8266 #ifndef LIMIT_BUILD_SIZE - #define FEATURE_CHART_SETTINGS_FILE_LAYOUT 1 + #define FEATURE_CHART_STORAGE_LAYOUT 1 #else - #define FEATURE_CHART_SETTINGS_FILE_LAYOUT 0 + #define FEATURE_CHART_STORAGE_LAYOUT 0 #endif #endif #endif - +#if !defined(CUSTOM_BUILD_CDN_URL) && !defined(FEATURE_ALTERNATIVE_CDN_URL) + #if defined(WEBSERVER_EMBED_CUSTOM_CSS) || defined(EMBED_ESPEASY_DEFAULT_MIN_CSS) || defined(EMBED_ESPEASY_DEFAULT_MIN_CSS_USE_GZ) + #define FEATURE_ALTERNATIVE_CDN_URL 0 // No need to configure custom CDN url when all content is included in build + #else + #define FEATURE_ALTERNATIVE_CDN_URL 1 + #endif +#endif // if !defined(CUSTOM_BUILD_CDN_URL) +#if defined(FEATURE_ALTERNATIVE_CDN_URL) && FEATURE_ALTERNATIVE_CDN_URL && defined(PLUGIN_BUILD_MINIMAL_OTA) + #undef FEATURE_ALTERNATIVE_CDN_URL + #define FEATURE_ALTERNATIVE_CDN_URL 0 +#endif + + + +// TODO TD-er: Test feature, must remove +/* +#ifdef FEATURE_ALTERNATIVE_CDN_URL +#undef FEATURE_ALTERNATIVE_CDN_URL +#endif +#define FEATURE_ALTERNATIVE_CDN_URL 1 +*/ + #endif // CUSTOMBUILD_DEFINE_PLUGIN_SETS_H diff --git a/src/src/DataStructs/FactoryDefaultPref.cpp b/src/src/DataStructs/FactoryDefaultPref.cpp index ba9401b42e..58023c5e9e 100644 --- a/src/src/DataStructs/FactoryDefaultPref.cpp +++ b/src/src/DataStructs/FactoryDefaultPref.cpp @@ -1,133 +1,167 @@ #include "../DataStructs/FactoryDefaultPref.h" #include "../../ESPEasy_common.h" -/* + ResetFactoryDefaultPreference_struct::ResetFactoryDefaultPreference_struct(uint32_t preference) : _preference(preference) {} -DeviceModel ResetFactoryDefaultPreference_struct::getDeviceModel() const { - return static_cast(_preference & 0xFF); +void ResetFactoryDefaultPreference_struct::set(uint32_t preference) +{ + _preference = preference; } -void ResetFactoryDefaultPreference_struct::setDeviceModel(DeviceModel model) { - _preference &= ~(0xFF); // set DeviceModel bits to 0 - _preference |= static_cast(model); -} +#ifdef ESP32 -bool ResetFactoryDefaultPreference_struct::keepWiFi() const { - return bitRead(_preference, 9); -} +// Max. 15 char keys for ESPEasy Factory Default marked keys +# define FACTORY_DEFAULT_NVS_PREF_KEY "FacDefPref" -void ResetFactoryDefaultPreference_struct::keepWiFi(bool keep) { - bitWrite(_preference, 9, keep); -} +bool ResetFactoryDefaultPreference_struct::init() +{ + ESPEasy_NVS_Helper nvs_helper; -bool ResetFactoryDefaultPreference_struct::keepNTP() const { - return bitRead(_preference, 10); + if (nvs_helper.begin(F(FACTORY_DEFAULT_NVS_NAMESPACE))) { + return from_NVS(nvs_helper); + } + return false; } -void ResetFactoryDefaultPreference_struct::keepNTP(bool keep) { - bitWrite(_preference, 10, keep); +bool ResetFactoryDefaultPreference_struct::from_NVS(ESPEasy_NVS_Helper& preferences) +{ + return preferences.getPreference(F(FACTORY_DEFAULT_NVS_PREF_KEY), _preference); } -bool ResetFactoryDefaultPreference_struct::keepNetwork() const { - return bitRead(_preference, 11); +void ResetFactoryDefaultPreference_struct::to_NVS(ESPEasy_NVS_Helper& preferences) const +{ + preferences.setPreference(F(FACTORY_DEFAULT_NVS_PREF_KEY), _preference); } -void ResetFactoryDefaultPreference_struct::keepNetwork(bool keep) { - bitWrite(_preference, 11, keep); -} +#endif // ifdef ESP32 -bool ResetFactoryDefaultPreference_struct::keepLogSettings() const { - return bitRead(_preference, 12); -} -void ResetFactoryDefaultPreference_struct::keepLogSettings(bool keep) { - bitWrite(_preference, 12, keep); -} +/* + DeviceModel ResetFactoryDefaultPreference_struct::getDeviceModel() const { + return static_cast(_preference & 0xFF); + } + + void ResetFactoryDefaultPreference_struct::setDeviceModel(DeviceModel model) { + _preference &= ~(0xFF); // set DeviceModel bits to 0 + _preference |= static_cast(model); + } + + bool ResetFactoryDefaultPreference_struct::keepWiFi() const { + return bitRead(_preference, 9); + } + + void ResetFactoryDefaultPreference_struct::keepWiFi(bool keep) { + bitWrite(_preference, 9, keep); + } + + bool ResetFactoryDefaultPreference_struct::keepNTP() const { + return bitRead(_preference, 10); + } + + void ResetFactoryDefaultPreference_struct::keepNTP(bool keep) { + bitWrite(_preference, 10, keep); + } -bool ResetFactoryDefaultPreference_struct::keepUnitName() const { - return bitRead(_preference, 13); -} + bool ResetFactoryDefaultPreference_struct::keepNetwork() const { + return bitRead(_preference, 11); + } -void ResetFactoryDefaultPreference_struct::keepUnitName(bool keep) { - bitWrite(_preference, 13, keep); -} + void ResetFactoryDefaultPreference_struct::keepNetwork(bool keep) { + bitWrite(_preference, 11, keep); + } -// filenr = 0...3 for files rules1.txt ... rules4.txt -bool ResetFactoryDefaultPreference_struct::fetchRulesTXT(int filenr) const { - return bitRead(_preference, 14 + filenr); -} + bool ResetFactoryDefaultPreference_struct::keepLogConsoleSettings() const { + return bitRead(_preference, 12); + } -void ResetFactoryDefaultPreference_struct::fetchRulesTXT(int filenr, bool fetch) { - bitWrite(_preference, 14 + filenr, fetch); -} + void ResetFactoryDefaultPreference_struct::keepLogConsoleSettings(bool keep) { + bitWrite(_preference, 12, keep); + } -bool ResetFactoryDefaultPreference_struct::fetchNotificationDat() const { - return bitRead(_preference, 18); -} + bool ResetFactoryDefaultPreference_struct::keepUnitName() const { + return bitRead(_preference, 13); + } -void ResetFactoryDefaultPreference_struct::fetchNotificationDat(bool fetch) { - bitWrite(_preference, 18, fetch); -} + void ResetFactoryDefaultPreference_struct::keepUnitName(bool keep) { + bitWrite(_preference, 13, keep); + } -bool ResetFactoryDefaultPreference_struct::fetchSecurityDat() const { - return bitRead(_preference, 19); -} + // filenr = 0...3 for files rules1.txt ... rules4.txt + bool ResetFactoryDefaultPreference_struct::fetchRulesTXT(int filenr) const { + return bitRead(_preference, 14 + filenr); + } -void ResetFactoryDefaultPreference_struct::fetchSecurityDat(bool fetch) { - bitWrite(_preference, 19, fetch); -} + void ResetFactoryDefaultPreference_struct::fetchRulesTXT(int filenr, bool fetch) { + bitWrite(_preference, 14 + filenr, fetch); + } -bool ResetFactoryDefaultPreference_struct::fetchConfigDat() const { - return bitRead(_preference, 20); -} + bool ResetFactoryDefaultPreference_struct::fetchNotificationDat() const { + return bitRead(_preference, 18); + } -void ResetFactoryDefaultPreference_struct::fetchConfigDat(bool fetch) { - bitWrite(_preference, 20, fetch); -} + void ResetFactoryDefaultPreference_struct::fetchNotificationDat(bool fetch) { + bitWrite(_preference, 18, fetch); + } -bool ResetFactoryDefaultPreference_struct::deleteFirst() const { - return bitRead(_preference, 21); -} + bool ResetFactoryDefaultPreference_struct::fetchSecurityDat() const { + return bitRead(_preference, 19); + } -void ResetFactoryDefaultPreference_struct::deleteFirst(bool checked) { - bitWrite(_preference, 21, checked); -} + void ResetFactoryDefaultPreference_struct::fetchSecurityDat(bool fetch) { + bitWrite(_preference, 19, fetch); + } -bool ResetFactoryDefaultPreference_struct::delete_Bak_Files() const { - return bitRead(_preference, 23); -} + bool ResetFactoryDefaultPreference_struct::fetchConfigDat() const { + return bitRead(_preference, 20); + } -void ResetFactoryDefaultPreference_struct::delete_Bak_Files(bool checked) { - bitWrite(_preference, 23, checked); -} + void ResetFactoryDefaultPreference_struct::fetchConfigDat(bool fetch) { + bitWrite(_preference, 20, fetch); + } -bool ResetFactoryDefaultPreference_struct::saveURL() const { - return bitRead(_preference, 22); -} + bool ResetFactoryDefaultPreference_struct::deleteFirst() const { + return bitRead(_preference, 21); + } -void ResetFactoryDefaultPreference_struct::saveURL(bool checked) { - bitWrite(_preference, 22, checked); -} + void ResetFactoryDefaultPreference_struct::deleteFirst(bool checked) { + bitWrite(_preference, 21, checked); + } -bool ResetFactoryDefaultPreference_struct::storeCredentials() const { - return bitRead(_preference, 24); -} + bool ResetFactoryDefaultPreference_struct::delete_Bak_Files() const { + return bitRead(_preference, 23); + } -void ResetFactoryDefaultPreference_struct::storeCredentials(bool checked) { - bitWrite(_preference, 24, checked); -} + void ResetFactoryDefaultPreference_struct::delete_Bak_Files(bool checked) { + bitWrite(_preference, 23, checked); + } -bool ResetFactoryDefaultPreference_struct::fetchProvisioningDat() const { - return bitRead(_preference, 25); -} + bool ResetFactoryDefaultPreference_struct::saveURL() const { + return bitRead(_preference, 22); + } -void ResetFactoryDefaultPreference_struct::fetchProvisioningDat(bool checked) { - bitWrite(_preference, 25, checked); -} + void ResetFactoryDefaultPreference_struct::saveURL(bool checked) { + bitWrite(_preference, 22, checked); + } + bool ResetFactoryDefaultPreference_struct::storeCredentials() const { + return bitRead(_preference, 24); + } -uint32_t ResetFactoryDefaultPreference_struct::getPreference() { - return _preference; -} -*/ \ No newline at end of file + void ResetFactoryDefaultPreference_struct::storeCredentials(bool checked) { + bitWrite(_preference, 24, checked); + } + + bool ResetFactoryDefaultPreference_struct::fetchProvisioningDat() const { + return bitRead(_preference, 25); + } + + void ResetFactoryDefaultPreference_struct::fetchProvisioningDat(bool checked) { + bitWrite(_preference, 25, checked); + } + + + uint32_t ResetFactoryDefaultPreference_struct::getPreference() { + return _preference; + } + */ diff --git a/src/src/DataStructs/FactoryDefaultPref.h b/src/src/DataStructs/FactoryDefaultPref.h index 68c1ffe9bd..57b23d10a3 100644 --- a/src/src/DataStructs/FactoryDefaultPref.h +++ b/src/src/DataStructs/FactoryDefaultPref.h @@ -7,31 +7,45 @@ #include "../../ESPEasy_common.h" +#ifdef ESP32 +# include "../Helpers/ESPEasy_NVS_Helper.h" +#endif // ifdef ESP32 + struct ResetFactoryDefaultPreference_struct { - ResetFactoryDefaultPreference_struct(uint32_t preference = 0) : _preference(preference) {} + ResetFactoryDefaultPreference_struct(uint32_t preference = 0); + + void set(uint32_t preference); + +#ifdef ESP32 + bool init(); + bool from_NVS(ESPEasy_NVS_Helper& preferences); + + void to_NVS(ESPEasy_NVS_Helper& preferences) const; +#endif // ifdef ESP32 private: union { struct { - uint32_t deviceModel : 8; - uint32_t unused_bit8 : 1; - uint32_t keepWiFi : 1; - uint32_t keepNTP : 1; - uint32_t keepNetwork : 1; - uint32_t keepLogSettings : 1; - uint32_t keepUnitName : 1; - uint32_t fetchRulesFile : 4; - uint32_t fetchNotificationDat : 1; - uint32_t fetchSecurityDat : 1; - uint32_t fetchConfigDat : 1; - uint32_t deleteFirst : 1; - uint32_t saveURL : 1; - uint32_t delete_Bak_Files : 1; - uint32_t storeCredentials : 1; - uint32_t fetchProvisioningDat : 1; - - uint32_t unused : 6; + uint32_t deviceModel : 8; + uint32_t unused_bit8 : 1; + uint32_t keepWiFi : 1; + uint32_t keepNTP : 1; + uint32_t keepNetwork : 1; + uint32_t keepLogConsoleSettings : 1; + uint32_t keepUnitName : 1; + uint32_t fetchRulesFile : 4; + uint32_t fetchNotificationDat : 1; + uint32_t fetchSecurityDat : 1; + uint32_t fetchConfigDat : 1; + uint32_t deleteFirst : 1; + uint32_t saveURL : 1; + uint32_t delete_Bak_Files : 1; + uint32_t storeCredentials : 1; + uint32_t fetchProvisioningDat : 1; + uint32_t keepCustomCdnUrl : 1; + + uint32_t unused : 5; } bits; uint32_t _preference{}; }; @@ -70,12 +84,12 @@ struct ResetFactoryDefaultPreference_struct { bits.keepNetwork = keep; } - bool keepLogSettings() const { - return bits.keepLogSettings; + bool keepLogConsoleSettings() const { + return bits.keepLogConsoleSettings; } - void keepLogSettings(bool keep) { - bits.keepLogSettings = keep; + void keepLogConsoleSettings(bool keep) { + bits.keepLogConsoleSettings = keep; } bool keepUnitName() const { @@ -86,12 +100,20 @@ struct ResetFactoryDefaultPreference_struct { bits.keepUnitName = keep; } + bool keepCustomCdnUrl() const { + return bits.keepCustomCdnUrl; + } + + void keepCustomCdnUrl(bool keep) { + bits.keepCustomCdnUrl = keep; + } + // filenr = 0...3 for files rules1.txt ... rules4.txt bool fetchRulesTXT(int filenr) const { return bitRead(bits.fetchRulesFile, filenr); } - void fetchRulesTXT(int filenr, bool fetch) { + void fetchRulesTXT(int filenr, bool fetch) { bitWrite(bits.fetchRulesFile, filenr, fetch); } @@ -159,7 +181,7 @@ struct ResetFactoryDefaultPreference_struct { bits.storeCredentials = checked; } - uint32_t getPreference() { + uint32_t getPreference() const { return _preference; } diff --git a/src/src/DataStructs/FactoryDefault_CDN_customurl_NVS.cpp b/src/src/DataStructs/FactoryDefault_CDN_customurl_NVS.cpp new file mode 100644 index 0000000000..69b10f41d8 --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_CDN_customurl_NVS.cpp @@ -0,0 +1,32 @@ +#include "../DataStructs/FactoryDefault_CDN_customurl_NVS.h" + +#ifdef ESP32 + +# if FEATURE_ALTERNATIVE_CDN_URL +# include "../Helpers/ESPEasy_Storage.h" + +# define FACTORY_DEFAULT_NVS_CDN_CUSTOMURL_KEY "CDN_customurl" + +bool FactoryDefault_CDN_customurl_NVS::applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences) +{ + String _url; + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_CDN_CUSTOMURL_KEY), _url)) { + set_CDN_url_custom(_url); + return true; + } + return false; +} + +void FactoryDefault_CDN_customurl_NVS::fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences) +{ + preferences.setPreference(F(FACTORY_DEFAULT_NVS_CDN_CUSTOMURL_KEY), get_CDN_url_custom()); +} + +void FactoryDefault_CDN_customurl_NVS::clear_from_NVS(ESPEasy_NVS_Helper& preferences) +{ + preferences.remove(F(FACTORY_DEFAULT_NVS_CDN_CUSTOMURL_KEY)); +} + +# endif // if FEATURE_ALTERNATIVE_CDN_URL +#endif // ifdef ESP32 diff --git a/src/src/DataStructs/FactoryDefault_CDN_customurl_NVS.h b/src/src/DataStructs/FactoryDefault_CDN_customurl_NVS.h new file mode 100644 index 0000000000..550340d46f --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_CDN_customurl_NVS.h @@ -0,0 +1,25 @@ +#ifndef DATASTRUCTS_FACTORYDEFAULT_CDN_CUSTOMURL_NVS_H +#define DATASTRUCTS_FACTORYDEFAULT_CDN_CUSTOMURL_NVS_H + + +#include "../../ESPEasy_common.h" + +#ifdef ESP32 +# if FEATURE_ALTERNATIVE_CDN_URL + +# include "../Helpers/ESPEasy_NVS_Helper.h" + +class FactoryDefault_CDN_customurl_NVS { +public: + + static bool applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences); + + static void fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences); + + static void clear_from_NVS(ESPEasy_NVS_Helper& preferences); +}; + +# endif // if FEATURE_ALTERNATIVE_CDN_URL +#endif // ifdef ESP32 + +#endif // ifndef DATASTRUCTS_FACTORYDEFAULT_CDN_CUSTOMURL_NVS_H diff --git a/src/src/DataStructs/FactoryDefault_LogConsoleSettings_NVS.cpp b/src/src/DataStructs/FactoryDefault_LogConsoleSettings_NVS.cpp new file mode 100644 index 0000000000..fe94739da2 --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_LogConsoleSettings_NVS.cpp @@ -0,0 +1,77 @@ +#include "../DataStructs/FactoryDefault_LogConsoleSettings_NVS.h" + + +#ifdef ESP32 + +# include "../Globals/Settings.h" +# include "../Helpers/StringConverter.h" + +// Max. 15 char keys for ESPEasy Factory Default marked keys +# define FACTORY_DEFAULT_NVS_LOG_SETTINGS_KEY "Log" +# define FACTORY_DEFAULT_NVS_CONSOLE_SETTINGS_KEY "Console" + + +bool FactoryDefault_LogConsoleSettings_NVS::applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences) +{ + bool updated = false; + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_LOG_SETTINGS_KEY), LogSettings)) { + updated = true; + Settings.SyslogLevel = LogSettings_bits.SyslogLevel; + Settings.SerialLogLevel = LogSettings_bits.SerialLogLevel; + Settings.WebLogLevel = LogSettings_bits.WebLogLevel; + Settings.SDLogLevel = LogSettings_bits.SDLogLevel; + Settings.SyslogFacility = LogSettings_bits.SyslogFacility; + Settings.SyslogPort = LogSettings_bits.SyslogPort; + + for (size_t i = 0; i < 4; ++i) { + Settings.Syslog_IP[i] = LogSettings_bits.Syslog_IP[i]; + } + } + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_CONSOLE_SETTINGS_KEY), ConsoleSettings)) { + updated = true; + Settings.console_serial_port = ConsoleSettings_bits.console_serial_port; + Settings.UseSerial = ConsoleSettings_bits.UseSerial; + Settings.console_serial_rxpin = ConsoleSettings_bits.console_serial_rxpin; + Settings.console_serial_txpin = ConsoleSettings_bits.console_serial_txpin; + Settings.console_serial0_fallback = ConsoleSettings_bits.console_serial0_fallback; + Settings.BaudRate = ConsoleSettings_bits.BaudRate; + } + return updated; +} + +void FactoryDefault_LogConsoleSettings_NVS::fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences) +{ + { + LogSettings_bits.SyslogLevel = Settings.SyslogLevel; + LogSettings_bits.SerialLogLevel = Settings.SerialLogLevel; + LogSettings_bits.WebLogLevel = Settings.WebLogLevel; + LogSettings_bits.SDLogLevel = Settings.SDLogLevel; + LogSettings_bits.SyslogFacility = Settings.SyslogFacility; + LogSettings_bits.SyslogPort = Settings.SyslogPort; + + for (size_t i = 0; i < 4; ++i) { + LogSettings_bits.Syslog_IP[i] = Settings.Syslog_IP[i]; + } + preferences.setPreference(F(FACTORY_DEFAULT_NVS_LOG_SETTINGS_KEY), LogSettings); + } + { + ConsoleSettings_bits.console_serial_port = Settings.console_serial_port; + ConsoleSettings_bits.UseSerial = Settings.UseSerial; + ConsoleSettings_bits.console_serial_rxpin = Settings.console_serial_rxpin; + ConsoleSettings_bits.console_serial_txpin = Settings.console_serial_txpin; + ConsoleSettings_bits.console_serial0_fallback = Settings.console_serial0_fallback; + ConsoleSettings_bits.BaudRate = Settings.BaudRate; + + preferences.setPreference(F(FACTORY_DEFAULT_NVS_CONSOLE_SETTINGS_KEY), ConsoleSettings); + } +} + +void FactoryDefault_LogConsoleSettings_NVS::clear_from_NVS(ESPEasy_NVS_Helper& preferences) +{ + preferences.remove(F(FACTORY_DEFAULT_NVS_LOG_SETTINGS_KEY)); + preferences.remove(F(FACTORY_DEFAULT_NVS_CONSOLE_SETTINGS_KEY)); +} + +#endif // ifdef ESP32 diff --git a/src/src/DataStructs/FactoryDefault_LogConsoleSettings_NVS.h b/src/src/DataStructs/FactoryDefault_LogConsoleSettings_NVS.h new file mode 100644 index 0000000000..d43c4529de --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_LogConsoleSettings_NVS.h @@ -0,0 +1,50 @@ +#ifndef DATASTRUCTS_FACTORYDEFAULT_LOG_CONSOLE_SETTINGS_NVS_H +#define DATASTRUCTS_FACTORYDEFAULT_LOG_CONSOLE_SETTINGS_NVS_H + +#include "../../ESPEasy_common.h" + +#ifdef ESP32 + +# include "../Helpers/ESPEasy_NVS_Helper.h" + +class FactoryDefault_LogConsoleSettings_NVS { +public: + + bool applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences); + + void fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences); + + void clear_from_NVS(ESPEasy_NVS_Helper& preferences); + +private: + + union { + struct { + uint64_t SyslogLevel : 3; + uint64_t SerialLogLevel : 3; + uint64_t WebLogLevel : 3; + uint64_t SDLogLevel : 3; + uint64_t SyslogFacility : 4; + uint64_t SyslogPort : 16; + uint8_t Syslog_IP[4]; + } LogSettings_bits; + + uint64_t LogSettings{}; + }; + + union { + struct { + uint8_t console_serial_port : 7; + uint8_t UseSerial : 1; + int8_t console_serial_rxpin; + int8_t console_serial_txpin; + uint8_t console_serial0_fallback; + uint32_t BaudRate; + } ConsoleSettings_bits; + + uint64_t ConsoleSettings{}; + }; +}; + +#endif // ifdef ESP32 +#endif // ifndef DATASTRUCTS_FACTORYDEFAULT_LOG_CONSOLE_SETTINGS_NVS_H diff --git a/src/src/DataStructs/FactoryDefault_Network_NVS.cpp b/src/src/DataStructs/FactoryDefault_Network_NVS.cpp new file mode 100644 index 0000000000..97a65c4437 --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_Network_NVS.cpp @@ -0,0 +1,87 @@ +#include "../DataStructs/FactoryDefault_Network_NVS.h" + +#ifdef ESP32 + +# include "../Globals/Settings.h" +# include "../Helpers/StringConverter.h" + +// Max. 15 char keys for ESPEasy Factory Default marked keys +# define FACTORY_DEFAULT_NVS_WIFI_IP_KEY "WiFI_IP" +# ifdef FEATURE_ETHERNET +# define FACTORY_DEFAULT_NVS_ETH_IP_KEY "ETH_IP" +# define FACTORY_DEFAULT_NVS_ETH_HW_CONF_KEY "ETH_HW_CONF" +# endif // ifdef FEATURE_ETHERNET + +bool FactoryDefault_Network_NVS::applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences) +{ + bool res = false; + + uint8_t *write = reinterpret_cast(&Settings); + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_WIFI_IP_KEY), IP_data, sizeof(IP_data))) { + // TD-er: This data is stored in sequence, so we can do a single memcpy call + constexpr unsigned int offset = offsetof(SettingsStruct, IP); + memcpy(write + offset, IP_data, sizeof(IP_data)); + res = true; + } +# ifdef FEATURE_ETHERNET + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_ETH_IP_KEY), IP_data, sizeof(IP_data))) { + constexpr unsigned int offset = offsetof(SettingsStruct, ETH_IP); + + memcpy(write + offset, IP_data, sizeof(IP_data)); + res = true; + } + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_ETH_HW_CONF_KEY), ETH_HW_conf)) { + Settings.ETH_Phy_Addr = bits.ETH_Phy_Addr; + Settings.ETH_Pin_mdc = bits.ETH_Pin_mdc; + Settings.ETH_Pin_mdio = bits.ETH_Pin_mdio; + Settings.ETH_Pin_power = bits.ETH_Pin_power; + Settings.ETH_Phy_Type = static_cast(bits.ETH_Phy_Type); + Settings.ETH_Clock_Mode = static_cast(bits.ETH_Clock_Mode); + Settings.NetworkMedium = static_cast(bits.NetworkMedium); + res = true; + } +# endif // ifdef FEATURE_ETHERNET + return res; +} + +void FactoryDefault_Network_NVS::fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences) +{ + const uint8_t *read = reinterpret_cast(&Settings); + + { + constexpr unsigned int offset = offsetof(SettingsStruct, IP); + memcpy(IP_data, read + offset, sizeof(IP_data)); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_WIFI_IP_KEY), IP_data, sizeof(IP_data)); + } +# ifdef FEATURE_ETHERNET + { + constexpr unsigned int offset = offsetof(SettingsStruct, ETH_IP); + memcpy(IP_data, read + offset, sizeof(IP_data)); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_ETH_IP_KEY), IP_data, sizeof(IP_data)); + } + { + bits.ETH_Phy_Addr = Settings.ETH_Phy_Addr; + bits.ETH_Pin_mdc = Settings.ETH_Pin_mdc; + bits.ETH_Pin_mdio = Settings.ETH_Pin_mdio; + bits.ETH_Pin_power = Settings.ETH_Pin_power; + bits.ETH_Phy_Type = static_cast(Settings.ETH_Phy_Type); + bits.ETH_Clock_Mode = static_cast(Settings.ETH_Clock_Mode); + bits.NetworkMedium = static_cast(Settings.NetworkMedium); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_ETH_HW_CONF_KEY), ETH_HW_conf); + } +# endif // ifdef FEATURE_ETHERNET +} + +void FactoryDefault_Network_NVS::clear_from_NVS(ESPEasy_NVS_Helper& preferences) +{ + preferences.remove(F(FACTORY_DEFAULT_NVS_WIFI_IP_KEY)); +# ifdef FEATURE_ETHERNET + preferences.remove(F(FACTORY_DEFAULT_NVS_ETH_IP_KEY)); + preferences.remove(F(FACTORY_DEFAULT_NVS_ETH_IP_KEY)); +# endif // ifdef FEATURE_ETHERNET +} + +#endif // ifdef ESP32 diff --git a/src/src/DataStructs/FactoryDefault_Network_NVS.h b/src/src/DataStructs/FactoryDefault_Network_NVS.h new file mode 100644 index 0000000000..7ed42dc243 --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_Network_NVS.h @@ -0,0 +1,49 @@ +#ifndef DATASTRUCTS_FACTORYDEFAULT_NETWORK_NVS_H +#define DATASTRUCTS_FACTORYDEFAULT_NETWORK_NVS_H + +#include "../../ESPEasy_common.h" + +#ifdef ESP32 + +# include "../Helpers/ESPEasy_NVS_Helper.h" + +class FactoryDefault_Network_NVS { +public: + + bool applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences); + + void fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences); + + void clear_from_NVS(ESPEasy_NVS_Helper& preferences); + +private: + + // IP + // GW + // SN + // DNS + uint8_t IP_data[16]{}; + +# ifdef FEATURE_ETHERNET + + union { + struct { + int8_t ETH_Phy_Addr; + int8_t ETH_Pin_mdc; + int8_t ETH_Pin_mdio; + int8_t ETH_Pin_power; + uint8_t ETH_Phy_Type; + uint8_t ETH_Clock_Mode; + uint8_t NetworkMedium; + uint8_t unused; + } bits; + + uint64_t ETH_HW_conf{}; + }; + + +# endif // ifdef FEATURE_ETHERNET +}; + +#endif // ifdef ESP32 +#endif // ifndef DATASTRUCTS_FACTORYDEFAULT_NETWORK_NVS_H diff --git a/src/src/DataStructs/FactoryDefault_UnitName_NVS.cpp b/src/src/DataStructs/FactoryDefault_UnitName_NVS.cpp new file mode 100644 index 0000000000..08c67b7f94 --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_UnitName_NVS.cpp @@ -0,0 +1,41 @@ +#include "../DataStructs/FactoryDefault_UnitName_NVS.h" + +#ifdef ESP32 + +# include "../Globals/Settings.h" +# include "../Helpers/StringConverter.h" + +// Max. 15 char keys for ESPEasy Factory Default marked keys +# define FACTORY_DEFAULT_NVS_UNIT_NAME_KEY "UnitName" + + +void FactoryDefault_UnitName_NVS::fromSettings() { + bitWrite(data[1], 0, Settings.appendUnitToHostname()); + data[0] = Settings.Unit; + memcpy((char *)(data + 2), Settings.Name, sizeof(Settings.Name)); +} + +void FactoryDefault_UnitName_NVS::applyToSettings() const { + Settings.appendUnitToHostname(bitRead(data[1], 0)); + Settings.Unit = data[0]; + memcpy(Settings.Name, (char *)(data + 2), sizeof(Settings.Name)); +} + +bool FactoryDefault_UnitName_NVS::applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences) { + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_UNIT_NAME_KEY), data, sizeof(data))) { + applyToSettings(); + return true; + } + return false; +} + +void FactoryDefault_UnitName_NVS::fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences) { + fromSettings(); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_UNIT_NAME_KEY), data, sizeof(data)); +} + +void FactoryDefault_UnitName_NVS::clear_from_NVS(ESPEasy_NVS_Helper& preferences) { + preferences.remove(F(FACTORY_DEFAULT_NVS_UNIT_NAME_KEY)); +} + +#endif // ifdef ESP32 diff --git a/src/src/DataStructs/FactoryDefault_UnitName_NVS.h b/src/src/DataStructs/FactoryDefault_UnitName_NVS.h new file mode 100644 index 0000000000..32fd261b6f --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_UnitName_NVS.h @@ -0,0 +1,39 @@ +#ifndef DATASTRUCTS_FACTORYDEFAULT_UNITNAME_NVS_H +#define DATASTRUCTS_FACTORYDEFAULT_UNITNAME_NVS_H + +#include "../../ESPEasy_common.h" + +#ifdef ESP32 + +# include "../Helpers/ESPEasy_NVS_Helper.h" + + +class FactoryDefault_UnitName_NVS { +private: + + void fromSettings(); + + void applyToSettings() const; + +public: + + bool applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences); + + void fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences); + + void clear_from_NVS(ESPEasy_NVS_Helper& preferences); + +private: + + // Used data: + // byte 0: Unitnr + // byte 1: flags + // byte 2 ... 28 hostname + uint8_t data[32]{}; +}; + + +#endif // ifdef ESP32 + + +#endif // ifndef DATASTRUCTS_FACTORYDEFAULT_UNITNAME_NVS_H diff --git a/src/src/DataStructs/FactoryDefault_WiFi_NVS.cpp b/src/src/DataStructs/FactoryDefault_WiFi_NVS.cpp new file mode 100644 index 0000000000..cbe4a72bea --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_WiFi_NVS.cpp @@ -0,0 +1,103 @@ +#include "../DataStructs/FactoryDefault_WiFi_NVS.h" + +#ifdef ESP32 + +# include "../Globals/Settings.h" +# include "../Globals/SecuritySettings.h" +# include "../Helpers/StringConverter.h" + +// Max. 15 char keys for ESPEasy Factory Default marked keys +# define FACTORY_DEFAULT_NVS_SSID1_KEY "WIFI_SSID1" +# define FACTORY_DEFAULT_NVS_WPA_PASS1_KEY "WIFI_PASS1" +# define FACTORY_DEFAULT_NVS_SSID2_KEY "WIFI_SSID2" +# define FACTORY_DEFAULT_NVS_WPA_PASS2_KEY "WIFI_PASS2" +# define FACTORY_DEFAULT_NVS_AP_PASS_KEY "WIFI_AP_PASS" +# define FACTORY_DEFAULT_NVS_WIFI_FLAGS_KEY "WIFI_Flags" + + +void FactoryDefault_WiFi_NVS::fromSettings() { + bits.IncludeHiddenSSID = Settings.IncludeHiddenSSID(); + bits.ApDontForceSetup = Settings.ApDontForceSetup(); + bits.DoNotStartAP = Settings.DoNotStartAP(); + bits.ForceWiFi_bg_mode = Settings.ForceWiFi_bg_mode(); + bits.WiFiRestart_connection_lost = Settings.WiFiRestart_connection_lost(); + bits.WifiNoneSleep = Settings.WifiNoneSleep(); + bits.gratuitousARP = Settings.gratuitousARP(); + bits.UseMaxTXpowerForSending = Settings.UseMaxTXpowerForSending(); + bits.UseLastWiFiFromRTC = Settings.UseLastWiFiFromRTC(); + bits.WaitWiFiConnect = Settings.WaitWiFiConnect(); + bits.SDK_WiFi_autoreconnect = Settings.SDK_WiFi_autoreconnect(); + + // bits.hiddenSSIDslowConnect = Settings. +} + +void FactoryDefault_WiFi_NVS::applyToSettings() const { + Settings.IncludeHiddenSSID(bits.IncludeHiddenSSID); + Settings.ApDontForceSetup(bits.ApDontForceSetup); + Settings.DoNotStartAP(bits.DoNotStartAP); + Settings.ForceWiFi_bg_mode(bits.ForceWiFi_bg_mode); + Settings.WiFiRestart_connection_lost(bits.WiFiRestart_connection_lost); + Settings.WifiNoneSleep(bits.WifiNoneSleep); + Settings.gratuitousARP(bits.gratuitousARP); + Settings.UseMaxTXpowerForSending(bits.UseMaxTXpowerForSending); + Settings.UseLastWiFiFromRTC(bits.UseLastWiFiFromRTC); + Settings.WaitWiFiConnect(bits.WaitWiFiConnect); + Settings.SDK_WiFi_autoreconnect(bits.SDK_WiFi_autoreconnect); + + // Settings. (bits.hiddenSSIDslowConnect); +} + +bool FactoryDefault_WiFi_NVS::applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences) { + String tmp; + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_SSID1_KEY), tmp)) { + safe_strncpy(SecuritySettings.WifiSSID, tmp, sizeof(SecuritySettings.WifiSSID)); + } + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_WPA_PASS1_KEY), tmp)) { + safe_strncpy(SecuritySettings.WifiKey, tmp, sizeof(SecuritySettings.WifiKey)); + } + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_SSID2_KEY), tmp)) { + safe_strncpy(SecuritySettings.WifiSSID2, tmp, sizeof(SecuritySettings.WifiSSID2)); + } + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_WPA_PASS2_KEY), tmp)) { + safe_strncpy(SecuritySettings.WifiKey2, tmp, sizeof(SecuritySettings.WifiKey2)); + } + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_AP_PASS_KEY), tmp)) { + safe_strncpy(SecuritySettings.WifiAPKey, tmp, sizeof(SecuritySettings.WifiAPKey)); + } + + + if (!preferences.getPreference(F(FACTORY_DEFAULT_NVS_WIFI_FLAGS_KEY), data)) { + return false; + } + + applyToSettings(); + return true; +} + +void FactoryDefault_WiFi_NVS::fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences) { + fromSettings(); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_WIFI_FLAGS_KEY), data); + + // Store WiFi credentials + preferences.setPreference(F(FACTORY_DEFAULT_NVS_SSID1_KEY), String(SecuritySettings.WifiSSID)); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_WPA_PASS1_KEY), String(SecuritySettings.WifiKey)); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_SSID2_KEY), String(SecuritySettings.WifiSSID2)); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_WPA_PASS2_KEY), String(SecuritySettings.WifiKey2)); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_AP_PASS_KEY), String(SecuritySettings.WifiAPKey)); +} + +void FactoryDefault_WiFi_NVS::clear_from_NVS(ESPEasy_NVS_Helper& preferences) { + preferences.remove(F(FACTORY_DEFAULT_NVS_SSID1_KEY)); + preferences.remove(F(FACTORY_DEFAULT_NVS_WPA_PASS1_KEY)); + preferences.remove(F(FACTORY_DEFAULT_NVS_SSID2_KEY)); + preferences.remove(F(FACTORY_DEFAULT_NVS_WPA_PASS2_KEY)); + preferences.remove(F(FACTORY_DEFAULT_NVS_AP_PASS_KEY)); + preferences.remove(F(FACTORY_DEFAULT_NVS_WIFI_FLAGS_KEY)); +} + +#endif // ifdef ESP32 diff --git a/src/src/DataStructs/FactoryDefault_WiFi_NVS.h b/src/src/DataStructs/FactoryDefault_WiFi_NVS.h new file mode 100644 index 0000000000..1d321e9529 --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_WiFi_NVS.h @@ -0,0 +1,55 @@ +#ifndef DATASTRUCTS_FACTORYDEFAULT_WIFI_NVS_H +#define DATASTRUCTS_FACTORYDEFAULT_WIFI_NVS_H + + +#include "../../ESPEasy_common.h" + +#ifdef ESP32 + +# include "../Helpers/ESPEasy_NVS_Helper.h" + + +class FactoryDefault_WiFi_NVS { +private: + + void fromSettings(); + + void applyToSettings() const; + +public: + + bool applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences); + + void fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences); + + void clear_from_NVS(ESPEasy_NVS_Helper& preferences); + +private: + + union { + struct { + uint64_t IncludeHiddenSSID : 1; + uint64_t ApDontForceSetup : 1; + uint64_t DoNotStartAP : 1; + uint64_t ForceWiFi_bg_mode : 1; + uint64_t WiFiRestart_connection_lost : 1; + uint64_t WifiNoneSleep : 1; + uint64_t gratuitousARP : 1; + uint64_t UseMaxTXpowerForSending : 1; + uint64_t UseLastWiFiFromRTC : 1; + uint64_t WaitWiFiConnect : 1; + uint64_t SDK_WiFi_autoreconnect : 1; + uint64_t hiddenSSIDslowConnect : 1; + + uint64_t unused : 52; + } bits; + + uint64_t data{}; + }; +}; + + +#endif // ifdef ESP32 + + +#endif // ifndef DATASTRUCTS_FACTORYDEFAULT_WIFI_NVS_H diff --git a/src/src/DataStructs/SettingsStruct.h b/src/src/DataStructs/SettingsStruct.h index 8c56888ca7..166ada37e8 100644 --- a/src/src/DataStructs/SettingsStruct.h +++ b/src/src/DataStructs/SettingsStruct.h @@ -300,6 +300,8 @@ class SettingsStruct_tmpl pluginID_t getPluginID_for_task(taskIndex_t taskIndex) const; + void forceSave() { memset(md5, 0, 16); } + unsigned long PID = 0; int Version = 0; @@ -433,7 +435,7 @@ class SettingsStruct_tmpl uint32_t ResetFactoryDefaultPreference = 0; // Do not clear this one in the clearAll() uint32_t I2C_clockSpeed = 400000; uint16_t WebserverPort = 80; - uint16_t SyslogPort = 0; + uint16_t SyslogPort = DEFAULT_SYSLOG_PORT; int8_t ETH_Phy_Addr = -1; int8_t ETH_Pin_mdc = -1; diff --git a/src/src/DataTypes/SettingsType.cpp b/src/src/DataTypes/SettingsType.cpp index f2985f4a94..322a500f18 100644 --- a/src/src/DataTypes/SettingsType.cpp +++ b/src/src/DataTypes/SettingsType.cpp @@ -23,6 +23,9 @@ const __FlashStringHelper * SettingsType::getSettingsTypeString(Enum settingsTyp #endif case Enum::SecuritySettings_Type: return F("SecuritySettings"); case Enum::ExtdControllerCredentials_Type: return F("ExtendedControllerCredentials"); + #if FEATURE_ALTERNATIVE_CDN_URL + case Enum::CdnSettings_Type: return F("CDN_url"); + #endif case Enum::SettingsType_MAX: break; } @@ -109,6 +112,19 @@ bool SettingsType::getSettingsParameters(Enum settingsType, int index, int& max_ struct_size = 0; break; } +#if FEATURE_ALTERNATIVE_CDN_URL + case Enum::CdnSettings_Type: + { + max_index = 1; + offset = DAT_OFFSET_CDN; + max_size = DAT_CDN_SIZE; + + // struct_size may differ. + struct_size = 0; + } + break; +#endif + case Enum::SettingsType_MAX: { max_index = -1; @@ -177,6 +193,10 @@ unsigned int SettingsType::getSVGcolor(Enum settingsType) { return 0xff00a2; case Enum::ExtdControllerCredentials_Type: return 0xc300ff; +#if FEATURE_ALTERNATIVE_CDN_URL + case Enum::CdnSettings_Type: + return 0xff6600; +#endif case Enum::SettingsType_MAX: break; } @@ -193,6 +213,9 @@ SettingsType::SettingsFileEnum SettingsType::getSettingsFile(Enum settingsType) case Enum::CustomTaskSettings_Type: case Enum::ControllerSettings_Type: case Enum::CustomControllerSettings_Type: +#if FEATURE_ALTERNATIVE_CDN_URL + case Enum::CdnSettings_Type: +#endif return SettingsFileEnum::FILE_CONFIG_type; case Enum::NotificationSettings_Type: return SettingsFileEnum::FILE_NOTIFICATION_type; diff --git a/src/src/DataTypes/SettingsType.h b/src/src/DataTypes/SettingsType.h index a9f2477ee3..11c18ad761 100644 --- a/src/src/DataTypes/SettingsType.h +++ b/src/src/DataTypes/SettingsType.h @@ -16,6 +16,9 @@ class SettingsType { NotificationSettings_Type, SecuritySettings_Type, ExtdControllerCredentials_Type, +#if FEATURE_ALTERNATIVE_CDN_URL + CdnSettings_Type, +#endif SettingsType_MAX }; diff --git a/src/src/ESPEasyCore/ESPEasy_setup.cpp b/src/src/ESPEasyCore/ESPEasy_setup.cpp index e36d6f75b4..f0c71a0561 100644 --- a/src/src/ESPEasyCore/ESPEasy_setup.cpp +++ b/src/src/ESPEasyCore/ESPEasy_setup.cpp @@ -147,6 +147,11 @@ void ESPEasy_setup() lowestRAM = FreeMem(); #endif // ifndef BUILD_NO_RAM_TRACKER +#ifdef ESP32 + ResetFactoryDefaultPreference.init(); +#endif + + PluginSetup(); CPluginSetup(); diff --git a/src/src/Helpers/ESPEasy_FactoryDefault.cpp b/src/src/Helpers/ESPEasy_FactoryDefault.cpp index 5203499511..efb7ced24a 100644 --- a/src/src/Helpers/ESPEasy_FactoryDefault.cpp +++ b/src/src/Helpers/ESPEasy_FactoryDefault.cpp @@ -25,12 +25,40 @@ #include "../Helpers/Hardware.h" #include "../Helpers/Misc.h" +#ifdef ESP32 + +// Store in NVS partition +#include "../Helpers/ESPEasy_NVS_Helper.h" + + +// Max. 15 char namespace for ESPEasy Factory Default settings +# define FACTORY_DEFAULT_NVS_NAMESPACE "ESPEasyFacDef" + +# include "../Helpers/StringConverter.h" +#include "../DataStructs/FactoryDefaultPref.h" +#include "../DataStructs/FactoryDefault_UnitName_NVS.h" +#include "../DataStructs/FactoryDefault_WiFi_NVS.h" +#include "../DataStructs/FactoryDefault_Network_NVS.h" +#include "../DataStructs/FactoryDefault_LogConsoleSettings_NVS.h" +# if FEATURE_ALTERNATIVE_CDN_URL +#include "../DataStructs/FactoryDefault_CDN_customurl_NVS.h" +#endif + + +#endif // ifdef ESP32 + + /********************************************************************************************\ Reset all settings to factory defaults \*********************************************************************************************/ void ResetFactory(bool formatFS) { + #ifdef ESP32 + ResetFactoryDefaultPreference.init(); + #endif + #if FEATURE_CUSTOM_PROVISIONING + if (ResetFactoryDefaultPreference.getPreference() == 0) { ResetFactoryDefaultPreference.setDeviceModel(static_cast(DEFAULT_FACTORY_DEFAULT_DEVICE_MODEL)); @@ -45,13 +73,13 @@ void ResetFactory(bool formatFS) ResetFactoryDefaultPreference.saveURL(DEFAULT_PROVISIONING_SAVE_URL); ResetFactoryDefaultPreference.storeCredentials(DEFAULT_PROVISIONING_SAVE_CREDENTIALS); } - #endif + #endif // if FEATURE_CUSTOM_PROVISIONING const GpioFactorySettingsStruct gpio_settings(ResetFactoryDefaultPreference.getDeviceModel()); #ifndef BUILD_NO_RAM_TRACKER checkRAM(F("ResetFactory")); - #endif + #endif // ifndef BUILD_NO_RAM_TRACKER // Direct Serial is allowed here, since this is only an emergency task. serialPrint(F("RESET: Resetting factory defaults... using ")); @@ -102,6 +130,7 @@ void ResetFactory(bool formatFS) #if FEATURE_CUSTOM_PROVISIONING { MakeProvisioningSettings(ProvisioningSettings); + if (ProvisioningSettings.get()) { ProvisioningSettings->setUser(F(DEFAULT_PROVISIONING_USER)); ProvisioningSettings->setPass(F(DEFAULT_PROVISIONING_PASS)); @@ -110,7 +139,7 @@ void ResetFactory(bool formatFS) saveProvisioningSettings(*ProvisioningSettings); } } -#endif +#endif // if FEATURE_CUSTOM_PROVISIONING // pad files with extra zeros for future extensions InitFile(SettingsType::SettingsFileEnum::FILE_CONFIG_type); @@ -152,7 +181,7 @@ void ResetFactory(bool formatFS) Settings.clearControllers(); Settings.clearTasks(); - if (!ResetFactoryDefaultPreference.keepLogSettings()) { + if (!ResetFactoryDefaultPreference.keepLogConsoleSettings()) { Settings.clearLogSettings(); str2ip((char *)DEFAULT_SYSLOG_IP, Settings.Syslog_IP); @@ -161,8 +190,17 @@ void ResetFactory(bool formatFS) setLogLevelFor(LOG_TO_WEBLOG, DEFAULT_WEB_LOG_LEVEL); setLogLevelFor(LOG_TO_SDCARD, DEFAULT_SD_LOG_LEVEL); Settings.SyslogFacility = DEFAULT_SYSLOG_FACILITY; + Settings.SyslogPort = DEFAULT_SYSLOG_PORT; Settings.UseValueLogger = DEFAULT_USE_SD_LOG; - } + + // FIXME TD-er: Must also keep console settings. + Settings.console_serial_port = DEFAULT_CONSOLE_PORT; + Settings.console_serial_rxpin = DEFAULT_CONSOLE_PORT_RXPIN; + Settings.console_serial_txpin = DEFAULT_CONSOLE_PORT_TXPIN; + Settings.console_serial0_fallback = DEFAULT_CONSOLE_SER0_FALLBACK; + Settings.UseSerial = DEFAULT_USE_SERIAL; + Settings.BaudRate = DEFAULT_SERIAL_BAUD; +} if (!ResetFactoryDefaultPreference.keepUnitName()) { Settings.clearUnitNameSettings(); @@ -190,20 +228,22 @@ void ResetFactory(bool formatFS) Settings.Build = get_build_nr(); // Settings.IP_Octet = DEFAULT_IP_OCTET; -// Settings.Delay = DEFAULT_DELAY; - Settings.Pin_i2c_sda = gpio_settings.i2c_sda; - Settings.Pin_i2c_scl = gpio_settings.i2c_scl; - Settings.Pin_status_led = gpio_settings.status_led; -// Settings.Pin_status_led_Inversed = DEFAULT_PIN_STATUS_LED_INVERSED; - Settings.Pin_sd_cs = -1; - Settings.Pin_Reset = DEFAULT_PIN_RESET_BUTTON; - Settings.Protocol[0] = DEFAULT_PROTOCOL; -// Settings.deepSleep_wakeTime = 0; // Sleep disabled -// Settings.CustomCSS = false; -// Settings.InitSPI = DEFAULT_SPI; + // Settings.Delay = DEFAULT_DELAY; + Settings.Pin_i2c_sda = gpio_settings.i2c_sda; + Settings.Pin_i2c_scl = gpio_settings.i2c_scl; + Settings.Pin_status_led = gpio_settings.status_led; + + // Settings.Pin_status_led_Inversed = DEFAULT_PIN_STATUS_LED_INVERSED; + Settings.Pin_sd_cs = -1; + Settings.Pin_Reset = DEFAULT_PIN_RESET_BUTTON; + Settings.Protocol[0] = DEFAULT_PROTOCOL; + + // Settings.deepSleep_wakeTime = 0; // Sleep disabled + // Settings.CustomCSS = false; + // Settings.InitSPI = DEFAULT_SPI; // advanced Settings -// Settings.UseRules = DEFAULT_USE_RULES; + // Settings.UseRules = DEFAULT_USE_RULES; Settings.ControllerEnabled[0] = DEFAULT_CONTROLLER_ENABLED; Settings.MQTTRetainFlag_unused = DEFAULT_MQTT_RETAIN; Settings.MessageDelay_unused = DEFAULT_MQTT_DELAY; @@ -217,10 +257,8 @@ void ResetFactory(bool formatFS) Settings.Longitude = DEFAULT_LONGITUDE; #endif // ifdef DEFAULT_LONGITUDE -// Settings.UseSerial = DEFAULT_USE_SERIAL; -// Settings.BaudRate = DEFAULT_SERIAL_BAUD; - #ifdef ESP32 + // Ethernet related settings are never used on ESP8266 Settings.ETH_Phy_Addr = gpio_settings.eth_phyaddr; Settings.ETH_Pin_mdc = gpio_settings.eth_mdc; @@ -228,8 +266,8 @@ void ResetFactory(bool formatFS) Settings.ETH_Pin_power = gpio_settings.eth_power; Settings.ETH_Phy_Type = gpio_settings.eth_phytype; Settings.ETH_Clock_Mode = gpio_settings.eth_clock_mode; -#endif - Settings.NetworkMedium = gpio_settings.network_medium; +#endif // ifdef ESP32 + Settings.NetworkMedium = gpio_settings.network_medium; /* Settings.GlobalSync = DEFAULT_USE_GLOBAL_SYNC; @@ -240,7 +278,8 @@ void ResetFactory(bool formatFS) Settings.ConnectionFailuresThreshold = DEFAULT_CON_FAIL_THRES; Settings.WireClockStretchLimit = DEFAULT_I2C_CLOCK_LIMIT; */ -// Settings.I2C_clockSpeed = DEFAULT_I2C_CLOCK_SPEED; + + // Settings.I2C_clockSpeed = DEFAULT_I2C_CLOCK_SPEED; Settings.JSONBoolWithoutQuotes(DEFAULT_JSON_BOOL_WITHOUT_QUOTES); Settings.EnableTimingStats(DEFAULT_ENABLE_TIMING_STATS); @@ -252,12 +291,12 @@ void ResetFactory(bool formatFS) #ifndef LIMIT_BUILD_SIZE addPredefinedPlugins(gpio_settings); addPredefinedRules(gpio_settings); -#endif +#endif // ifndef LIMIT_BUILD_SIZE #if DEFAULT_CONTROLLER { // Place in a scope to have its memory freed ASAP - MakeControllerSettings(ControllerSettings); //-V522 + MakeControllerSettings(ControllerSettings); // -V522 if (AllocatedControllerSettings()) { safe_strncpy(ControllerSettings->Subscribe, F(DEFAULT_SUB), sizeof(ControllerSettings->Subscribe)); @@ -271,7 +310,7 @@ void ResetFactory(bool formatFS) ControllerSettings->setHostname(F(DEFAULT_SERVER_HOST)); ControllerSettings->UseDNS = DEFAULT_SERVER_USEDNS; ControllerSettings->useExtendedCredentials(DEFAULT_USE_EXTD_CONTROLLER_CREDENTIALS); - ControllerSettings->Port = DEFAULT_PORT; + ControllerSettings->Port = DEFAULT_PORT; ControllerSettings->ClientTimeout = DEFAULT_CONTROLLER_TIMEOUT; setControllerUser(0, *ControllerSettings, F(DEFAULT_CONTROLLER_USER)); setControllerPass(0, *ControllerSettings, F(DEFAULT_CONTROLLER_PASS)); @@ -280,11 +319,52 @@ void ResetFactory(bool formatFS) } } #endif // if DEFAULT_CONTROLLER + +#ifdef ESP32 + { + ESPEasy_NVS_Helper preferences; + preferences.begin(F(FACTORY_DEFAULT_NVS_NAMESPACE), true); + + if (ResetFactoryDefaultPreference.from_NVS(preferences)) { + Settings.ResetFactoryDefaultPreference = ResetFactoryDefaultPreference.getPreference(); + } + + if (ResetFactoryDefaultPreference.keepUnitName()) + { + FactoryDefault_UnitName_NVS unitNameNVS{}; + unitNameNVS.applyToSettings_from_NVS(preferences); + } + if (ResetFactoryDefaultPreference.keepWiFi()) + { + FactoryDefault_WiFi_NVS wifiNVS{}; + wifiNVS.applyToSettings_from_NVS(preferences); + } + if (ResetFactoryDefaultPreference.keepNetwork()) + { + // Restore Network IP settings + FactoryDefault_Network_NVS network_nvs; + network_nvs.applyToSettings_from_NVS(preferences); + } + if (ResetFactoryDefaultPreference.keepLogConsoleSettings()) + { + // Restore Log and Console settings + FactoryDefault_LogConsoleSettings_NVS log_console_nvs; + log_console_nvs.applyToSettings_from_NVS(preferences); + } + +#if FEATURE_ALTERNATIVE_CDN_URL + if (ResetFactoryDefaultPreference.keepCustomCdnUrl()) { + FactoryDefault_CDN_customurl_NVS::applyToSettings_from_NVS(preferences); + } +#endif + } +#endif + const bool forFactoryReset = true; SaveSettings(forFactoryReset); #ifndef BUILD_NO_RAM_TRACKER checkRAM(F("ResetFactory2")); - #endif + #endif // ifndef BUILD_NO_RAM_TRACKER serialPrintln(F("RESET: Successful, rebooting. (you might need to press the reset button if you've just flashed the firmware)")); // NOTE: this is a known ESP8266 bug, not our fault. :) @@ -296,11 +376,70 @@ void ResetFactory(bool formatFS) reboot(IntendedRebootReason_e::ResetFactory); } - /*********************************************************************************************\ Collect the stored preference for factory default \*********************************************************************************************/ void applyFactoryDefaultPref() { // TODO TD-er: Store it in more places to make it more persistent Settings.ResetFactoryDefaultPreference = ResetFactoryDefaultPreference.getPreference(); + +#ifdef ESP32 + ESPEasy_NVS_Helper preferences; + preferences.begin(F(FACTORY_DEFAULT_NVS_NAMESPACE)); + ResetFactoryDefaultPreference.to_NVS(preferences); + { + FactoryDefault_UnitName_NVS unitNameNVS{}; + if (ResetFactoryDefaultPreference.keepUnitName()) + { + // Store Unit nr and hostname + unitNameNVS.fromSettings_to_NVS(preferences); + } else { + unitNameNVS.clear_from_NVS(preferences); + } + } + { + FactoryDefault_WiFi_NVS wifiNVS{}; + if (ResetFactoryDefaultPreference.keepWiFi()) + { + // Store WiFi credentials + wifiNVS.fromSettings_to_NVS(preferences); + } else { + wifiNVS.clear_from_NVS(preferences); + } + } + { + FactoryDefault_Network_NVS network_nvs{}; + if (ResetFactoryDefaultPreference.keepNetwork()) + { + // Store Network IP settings + network_nvs.fromSettings_to_NVS(preferences); + } else { + network_nvs.clear_from_NVS(preferences); + } + } + { + FactoryDefault_LogConsoleSettings_NVS log_console_nvs{}; + if (ResetFactoryDefaultPreference.keepLogConsoleSettings()) + { + // Store Log and Console settings + log_console_nvs.fromSettings_to_NVS(preferences); + } else { + log_console_nvs.clear_from_NVS(preferences); + } + } +# if FEATURE_ALTERNATIVE_CDN_URL + { + if (ResetFactoryDefaultPreference.keepCustomCdnUrl()) + { + // Store custom CDN + FactoryDefault_CDN_customurl_NVS::fromSettings_to_NVS(preferences); + } else { + FactoryDefault_CDN_customurl_NVS::clear_from_NVS(preferences); + } + } +# endif // if FEATURE_ALTERNATIVE_CDN_URL + + + preferences.end(); +#endif // ifdef ESP32 } diff --git a/src/src/Helpers/ESPEasy_NVS_Helper.cpp b/src/src/Helpers/ESPEasy_NVS_Helper.cpp new file mode 100644 index 0000000000..af035386e0 --- /dev/null +++ b/src/src/Helpers/ESPEasy_NVS_Helper.cpp @@ -0,0 +1,124 @@ +#include "../Helpers/ESPEasy_NVS_Helper.h" + +#ifdef ESP32 + +# include "../Helpers/StringConverter.h" + + +ESPEasy_NVS_Helper::~ESPEasy_NVS_Helper() +{ + _preferences.end(); +} + +bool ESPEasy_NVS_Helper::begin(const String& nvs_namespace, bool readOnly) +{ + return _preferences.begin(nvs_namespace.c_str(), readOnly); +} + +void ESPEasy_NVS_Helper::end() +{ + _preferences.end(); +} + +void ESPEasy_NVS_Helper::remove(const String& key) +{ + _preferences.remove(key.c_str()); +} + +bool ESPEasy_NVS_Helper::getPreference(const String& key, String& value) +{ + value = _preferences.getString(key.c_str()); + + const bool res = !value.isEmpty(); + + addLog(res ? LOG_LEVEL_INFO : LOG_LEVEL_ERROR, concat(F("NVS : Load "), key)); + return res; +} + +void ESPEasy_NVS_Helper::setPreference(const String& key, const String& value) +{ + if (value.isEmpty()) { + _preferences.remove(key.c_str()); + } + else if (!_preferences.getString(key.c_str(), EMPTY_STRING.c_str()).equals(value)) { + _preferences.putString(key.c_str(), value); + addLog(LOG_LEVEL_INFO, concat(F("NVS : Save "), key)); + } +} + +bool ESPEasy_NVS_Helper::getPreference(const String& key, uint32_t& value) +{ + constexpr uint32_t defaultValue = std::numeric_limits::max(); + + value = _preferences.getUInt(key.c_str(), defaultValue); + + const bool res = value != defaultValue; + + addLog(res ? LOG_LEVEL_INFO : LOG_LEVEL_ERROR, concat(F("NVS : Load "), key)); + return res; +} + +void ESPEasy_NVS_Helper::setPreference(const String& key, const uint32_t& value) +{ + constexpr uint32_t defaultValue = std::numeric_limits::max(); + + if (value == defaultValue) { + _preferences.remove(key.c_str()); + } + else if (_preferences.getUInt(key.c_str()) != value) { + _preferences.putUInt(key.c_str(), value); + addLog(LOG_LEVEL_INFO, concat(F("NVS : Save "), key)); + } +} + +bool ESPEasy_NVS_Helper::getPreference(const String& key, uint64_t& value) +{ + constexpr uint64_t defaultValue = std::numeric_limits::max(); + + value = _preferences.getULong64(key.c_str(), defaultValue); + + const bool res = value != defaultValue; + + addLog(res ? LOG_LEVEL_INFO : LOG_LEVEL_ERROR, concat(F("NVS : Load "), key)); + return res; +} + +void ESPEasy_NVS_Helper::setPreference(const String& key, const uint64_t& value) +{ + constexpr uint64_t defaultValue = std::numeric_limits::max(); + + if (value == defaultValue) { + _preferences.remove(key.c_str()); + } + else if (_preferences.getULong64(key.c_str()) != value) { + _preferences.putULong64(key.c_str(), value); + addLog(LOG_LEVEL_INFO, concat(F("NVS : Save "), key)); + } +} + +bool ESPEasy_NVS_Helper::getPreference(const String& key, uint8_t *data, size_t length) +{ + const bool res = _preferences.getBytes(key.c_str(), data, length) == length; + + addLog(res ? LOG_LEVEL_INFO : LOG_LEVEL_ERROR, concat(F("NVS : Load "), key)); + return res; +} + +void ESPEasy_NVS_Helper::setPreference(const String& key, const uint8_t *data, size_t length) +{ + { + uint8_t tmp[length]{}; + + if (_preferences.getBytes(key.c_str(), tmp, length) == length) { + if (memcmp(tmp, data, length) == 0) { + return; + } + } + } + + if (_preferences.putBytes(key.c_str(), data, length) == length) { + addLog(LOG_LEVEL_INFO, concat(F("NVS : Save "), key)); + } +} + +#endif // ifdef ESP32 diff --git a/src/src/Helpers/ESPEasy_NVS_Helper.h b/src/src/Helpers/ESPEasy_NVS_Helper.h new file mode 100644 index 0000000000..d164f52821 --- /dev/null +++ b/src/src/Helpers/ESPEasy_NVS_Helper.h @@ -0,0 +1,58 @@ +#ifndef HELPERS_ESPEASY_NVS_HELPER_H +#define HELPERS_ESPEASY_NVS_HELPER_H + +#include "../../ESPEasy_common.h" + +#ifdef ESP32 + +// Store in NVS partition +# include + + +// Max. 15 char namespace for ESPEasy Factory Default settings +# define FACTORY_DEFAULT_NVS_NAMESPACE "ESPEasyFacDef" + + +class ESPEasy_NVS_Helper { +public: + ESPEasy_NVS_Helper() = default; + + ~ESPEasy_NVS_Helper(); + + bool begin(const String& nvs_namespace, + bool readOnly = false); + + void end(); + + void remove(const String& key); + + bool getPreference(const String& key, + String & value); + void setPreference(const String& key, + const String& value); + + bool getPreference(const String& key, + uint32_t & value); + void setPreference(const String & key, + const uint32_t& value); + + bool getPreference(const String& key, + uint64_t & value); + void setPreference(const String & key, + const uint64_t& value); + + bool getPreference(const String& key, + uint8_t *value, + size_t length); + void setPreference(const String & key, + const uint8_t *value, + size_t length); + +private: + + Preferences _preferences; +}; + + +#endif // ifdef ESP32 +#endif // ifndef HELPERS_ESPEASY_NVS_HELPER_H diff --git a/src/src/Helpers/ESPEasy_Storage.cpp b/src/src/Helpers/ESPEasy_Storage.cpp index c60b901c15..5a7b6dddf0 100644 --- a/src/src/Helpers/ESPEasy_Storage.cpp +++ b/src/src/Helpers/ESPEasy_Storage.cpp @@ -566,6 +566,10 @@ String SaveSettings(bool forFactoryReset) Settings.validate(); initSerial(); + if (forFactoryReset) { + Settings.forceSave(); + } + if (!COMPUTE_STRUCT_CHECKSUM_UPDATE(SettingsStruct, Settings) /* computeChecksum( @@ -646,14 +650,25 @@ void afterloadSettings() { ExtraTaskSettings.clear(); // make sure these will not contain old settings. // Load ResetFactoryDefaultPreference from provisioning.dat if available. + // FIXME TD-er: Must actually move content of Provisioning.dat to NVS and then delete file uint32_t pref_temp = Settings.ResetFactoryDefaultPreference; + #ifdef ESP32 + if (pref_temp == 0) { + if (ResetFactoryDefaultPreference.getPreference() == 0) { + // Try loading from NVS + ResetFactoryDefaultPreference.init(); + pref_temp = ResetFactoryDefaultPreference.getPreference(); + } + } + #endif #if FEATURE_CUSTOM_PROVISIONING if (fileExists(getFileName(FileType::PROVISIONING_DAT))) { MakeProvisioningSettings(ProvisioningSettings); if (ProvisioningSettings.get()) { loadProvisioningSettings(*ProvisioningSettings); if (ProvisioningSettings->matchingFlashSize()) { - pref_temp = ProvisioningSettings->ResetFactoryDefaultPreference.getPreference(); + if (pref_temp == 0 && ProvisioningSettings->ResetFactoryDefaultPreference.getPreference() != 0) + pref_temp = ProvisioningSettings->ResetFactoryDefaultPreference.getPreference(); } } } @@ -667,6 +682,7 @@ void afterloadSettings() { if (modelMatchingFlashSize(pref.getDeviceModel())) { ResetFactoryDefaultPreference = pref_temp; } + applyFactoryDefaultPref(); Scheduler.setEcoMode(Settings.EcoPowerMode()); #ifdef ESP32 setCpuFrequencyMhz(Settings.EcoPowerMode() ? 80 : 240); @@ -946,6 +962,7 @@ String LoadStringArray(SettingsType::Enum settingsType, int index, String string \*********************************************************************************************/ String SaveStringArray(SettingsType::Enum settingsType, int index, const String strings[], uint16_t nrStrings, uint16_t maxStringLength, uint32_t posInBlock) { + // FIXME TD-er: Must add some check to see if the existing data has changed before saving. int offset, max_size; if (!SettingsType::getSettingsParameters(settingsType, index, offset, max_size)) { @@ -1144,6 +1161,50 @@ String LoadTaskSettings(taskIndex_t TaskIndex) return result; } +#if FEATURE_ALTERNATIVE_CDN_URL +String _CDN_url_cache; +bool _CDN_url_loaded = false; + +String get_CDN_url_custom() { + if (!_CDN_url_loaded) { + String strings[] = {EMPTY_STRING}; + + LoadStringArray( + SettingsType::Enum::CdnSettings_Type, 0, + strings, NR_ELEMENTS(strings), 255, 0); + _CDN_url_cache = strings[0]; + _CDN_url_loaded = true; + } + return _CDN_url_cache; +} + +void set_CDN_url_custom(const String &url) { + _CDN_url_cache = url; + _CDN_url_cache.trim(); + if (!_CDN_url_cache.isEmpty() && !_CDN_url_cache.endsWith(F("/"))) { + _CDN_url_cache.concat('/'); + } + _CDN_url_loaded = true; + + String strings[] = { EMPTY_STRING }; + + LoadStringArray( + SettingsType::Enum::CdnSettings_Type, 0, + strings, NR_ELEMENTS(strings), 255, 0); + + if (url.equals(strings[0])) { + // No need to save, is already the same + return; + } + + strings[0] = url; + + SaveStringArray( + SettingsType::Enum::CdnSettings_Type, 0, + strings, NR_ELEMENTS(strings), 255, 0); +} +#endif // if FEATURE_ALTERNATIVE_CDN_URL + /********************************************************************************************\ Save Custom Task settings to file system \*********************************************************************************************/ @@ -2096,6 +2157,10 @@ String downloadFileType(FileType::Enum filetype, unsigned int filenr) return F("Not Allowed"); } + if (!ProvisioningSettings->url[0]) { + return F("Provision Config incomplete"); + } + url = ProvisioningSettings->url; user = ProvisioningSettings->user; pass = ProvisioningSettings->pass; diff --git a/src/src/Helpers/ESPEasy_Storage.h b/src/src/Helpers/ESPEasy_Storage.h index d32ea7a1e1..c5d05eb216 100644 --- a/src/src/Helpers/ESPEasy_Storage.h +++ b/src/src/Helpers/ESPEasy_Storage.h @@ -167,6 +167,14 @@ String SaveTaskSettings(taskIndex_t TaskIndex); \*********************************************************************************************/ String LoadTaskSettings(taskIndex_t TaskIndex); +/********************************************************************************************\ + Load/Save CDN custom setting from file system + \*********************************************************************************************/ +#if FEATURE_ALTERNATIVE_CDN_URL +String get_CDN_url_custom(); +void set_CDN_url_custom(const String &url); +#endif // if FEATURE_ALTERNATIVE_CDN_URL + /********************************************************************************************\ Save Custom Task settings to file system \*********************************************************************************************/ diff --git a/src/src/Helpers/Networking.cpp b/src/src/Helpers/Networking.cpp index f165cf40f2..60a9cc61c4 100644 --- a/src/src/Helpers/Networking.cpp +++ b/src/src/Helpers/Networking.cpp @@ -1767,6 +1767,7 @@ bool downloadFirmware(String filename, String& error) if (ProvisioningSettings.get()) { loadProvisioningSettings(*ProvisioningSettings); if (!ProvisioningSettings->allowedFlags.allowFetchFirmware) { + error = F("Not Allowed"); return false; } baseurl = ProvisioningSettings->url; diff --git a/src/src/Static/WebStaticData.cpp b/src/src/Static/WebStaticData.cpp index d360c5b388..7972988e98 100644 --- a/src/src/Static/WebStaticData.cpp +++ b/src/src/Static/WebStaticData.cpp @@ -13,7 +13,17 @@ String generate_external_URL(const String& fname, bool isEmbedded) { // Generate some URL indicating static files which will need to be served with some cache-control header return concat(F("static_"), Cache.fileCacheClearMoment) + '_' + fname; } - return concat(get_CDN_url_prefix(), fname); + #if FEATURE_ALTERNATIVE_CDN_URL + String cdn = get_CDN_url_custom(); + if (!cdn.isEmpty()) { + cdn = parseTemplate(cdn); // Replace system variables. + return concat(cdn, fname); // cdn.endsWith('/') check done at save + } else { + #endif // if FEATURE_ALTERNATIVE_CDN_URL + return concat(get_CDN_url_prefix(), fname); + #if FEATURE_ALTERNATIVE_CDN_URL + } + #endif // if FEATURE_ALTERNATIVE_CDN_URL } void serve_CDN_CSS(const __FlashStringHelper * fname, bool isEmbedded) { diff --git a/src/src/WebServer/ConfigPage.cpp b/src/src/WebServer/ConfigPage.cpp index ca75fd5f7a..7a45bb0838 100644 --- a/src/src/WebServer/ConfigPage.cpp +++ b/src/src/WebServer/ConfigPage.cpp @@ -146,6 +146,9 @@ void handle_config() { webArg2ip(F("espethsubnet"), Settings.ETH_Subnet); webArg2ip(F("espethdns"), Settings.ETH_DNS); #endif // if FEATURE_ETHERNET + #if FEATURE_ALTERNATIVE_CDN_URL + set_CDN_url_custom(webArg(F("alturl"))); + #endif // if FEATURE_ALTERNATIVE_CDN_URL addHtmlError(SaveSettings()); } @@ -259,6 +262,15 @@ void handle_config() { addFormSeparator(2); + #if FEATURE_ALTERNATIVE_CDN_URL + addFormSubHeader(F("CDN (Content delivery network)")); + + addFormTextBox(F("Custom CDN URL"), F("alturl"), get_CDN_url_custom(), 255); + addFormNote(concat(F("Leave empty for default CDN url: "), get_CDN_url_prefix())); + + addFormSeparator(2); + #endif // if FEATURE_ALTERNATIVE_CDN_URL + html_TR_TD(); html_TD(); addSubmitButton(); diff --git a/src/src/WebServer/FactoryResetPage.cpp b/src/src/WebServer/FactoryResetPage.cpp index 970aa4ce9a..ee1f2ffe38 100644 --- a/src/src/WebServer/FactoryResetPage.cpp +++ b/src/src/WebServer/FactoryResetPage.cpp @@ -51,7 +51,10 @@ void handle_factoryreset() { ResetFactoryDefaultPreference.keepWiFi(isFormItemChecked(F("kw"))); ResetFactoryDefaultPreference.keepNetwork(isFormItemChecked(F("knet"))); ResetFactoryDefaultPreference.keepNTP(isFormItemChecked(F("kntp"))); - ResetFactoryDefaultPreference.keepLogSettings(isFormItemChecked(F("klog"))); + ResetFactoryDefaultPreference.keepLogConsoleSettings(isFormItemChecked(F("klog"))); +# if FEATURE_ALTERNATIVE_CDN_URL + ResetFactoryDefaultPreference.keepCustomCdnUrl(isFormItemChecked(F("kcdn"))); +#endif applyFactoryDefaultPref(); addHtmlError(SaveSettings()); } @@ -80,8 +83,13 @@ void handle_factoryreset() { addRowLabel(F("Keep NTP/DST config")); addCheckBox(F("kntp"), ResetFactoryDefaultPreference.keepNTP()); - addRowLabel(F("Keep log config")); - addCheckBox(F("klog"), ResetFactoryDefaultPreference.keepLogSettings()); + addRowLabel(F("Keep Console/Log config")); + addCheckBox(F("klog"), ResetFactoryDefaultPreference.keepLogConsoleSettings()); + +# if FEATURE_ALTERNATIVE_CDN_URL + addRowLabel(F("Keep Custom CDN url")); + addCheckBox(F("kcdn"), ResetFactoryDefaultPreference.keepCustomCdnUrl()); +#endif addTableSeparator(F("Pre-defined configurations"), 2, 3); addRowLabel(F("Pre-defined config")); @@ -157,8 +165,16 @@ void handle_factoryreset_json() { } if (hasArg(F("klog"))) { - ResetFactoryDefaultPreference.keepLogSettings(isFormItemChecked(F("klog"))); + ResetFactoryDefaultPreference.keepLogConsoleSettings(isFormItemChecked(F("klog"))); + } + +# if FEATURE_ALTERNATIVE_CDN_URL + if (hasArg(F("kcdn"))) { + ResetFactoryDefaultPreference.keepCustomCdnUrl(isFormItemChecked(F("kcdn"))); } +#endif + + #endif String error; bool performReset = false; diff --git a/src/src/WebServer/SettingsArchive.cpp b/src/src/WebServer/SettingsArchive.cpp index 74ddb07720..c0e2ec9bc9 100644 --- a/src/src/WebServer/SettingsArchive.cpp +++ b/src/src/WebServer/SettingsArchive.cpp @@ -257,6 +257,7 @@ void storeDownloadFiletypeCheckbox(FileType::Enum filetype, unsigned int filenr) case FileType::NOTIFICATION_DAT: ResetFactoryDefaultPreference.fetchNotificationDat(isChecked); break; case FileType::RULES_TXT: { ResetFactoryDefaultPreference.fetchRulesTXT(filenr, isChecked); break; } case FileType::PROVISIONING_DAT: { ResetFactoryDefaultPreference.fetchProvisioningDat(isChecked); break; } + case FileType::MAX_FILETYPE: break; } diff --git a/tools/pio/generate-compiletime-defines.py b/tools/pio/generate-compiletime-defines.py index 443e47d7e5..f98dc961e6 100644 --- a/tools/pio/generate-compiletime-defines.py +++ b/tools/pio/generate-compiletime-defines.py @@ -57,14 +57,14 @@ def get_cdn_url_prefix(): tag = tags[0] # work-around to allow users to use files not yet available on a tagged version if '20220809' in tag: - return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy/static/' + return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega/static/' tag = tag.replace('refs/tags/','@') return "https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy{0}/static/".format(tag) except: - return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega-20231013/static/' + return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega/static/' except ImportError: - return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega-20231013/static/' + return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega/static/'