diff --git a/config_allfeatures.cmake b/config_allfeatures.cmake index de85f5c..627b772 100644 --- a/config_allfeatures.cmake +++ b/config_allfeatures.cmake @@ -42,7 +42,6 @@ set(BOBBYCAR_BUILDFLAGS -DDEFAULT_FIELDADVMAX=40 -DFEATURE_WEBSERVER -DFEATURE_OTA - -DOTA_USERNAME="allfeatures" # -DFEATURE_DPAD_5WIRESW # -DPINS_DPAD_5WIRESW_OUT=4 # -DPINS_DPAD_5WIRESW_IN1=5 diff --git a/config_comred.cmake b/config_comred.cmake index db3740d..4167af5 100644 --- a/config_comred.cmake +++ b/config_comred.cmake @@ -42,7 +42,6 @@ set(BOBBYCAR_BUILDFLAGS -DDEFAULT_FIELDADVMAX=40 -DFEATURE_WEBSERVER -DFEATURE_OTA - -DOTA_USERNAME="comred" # -DFEATURE_DPAD_5WIRESW # -DPINS_DPAD_5WIRESW_OUT=4 # -DPINS_DPAD_5WIRESW_IN1=5 diff --git a/config_feedc0de.cmake b/config_feedc0de.cmake index b22ed9c..23ea111 100644 --- a/config_feedc0de.cmake +++ b/config_feedc0de.cmake @@ -42,7 +42,6 @@ set(BOBBYCAR_BUILDFLAGS -DDEFAULT_FIELDADVMAX=40 -DFEATURE_WEBSERVER -DFEATURE_OTA - -DOTA_USERNAME="feedc0de" -DFEATURE_DPAD_5WIRESW_2OUT -DPINS_DPAD_5WIRESW_OUT1=18 -DPINS_DPAD_5WIRESW_OUT2=19 @@ -96,7 +95,7 @@ set(BOBBYCAR_BUILDFLAGS -DLEDSTRIP_ANIMATION_DEFAULT=0 -DLEDS_PER_METER=144 -DOLD_NVS -# -DFEATURE_DNS_NS + -DFEATURE_DNS_NS # -DSWITCH_BLINK # -DFEATURE_ESPNOW ) diff --git a/config_greyhash.cmake b/config_greyhash.cmake index 962d2a4..3055769 100644 --- a/config_greyhash.cmake +++ b/config_greyhash.cmake @@ -42,7 +42,6 @@ set(BOBBYCAR_BUILDFLAGS -DDEFAULT_FIELDADVMAX=40 # -DFEATURE_WEBSERVER # -DFEATURE_OTA -# -DOTA_USERNAME="greyhash" -DFEATURE_DPAD_5WIRESW -DPINS_DPAD_5WIRESW_OUT=4 -DPINS_DPAD_5WIRESW_IN1=5 diff --git a/config_mick.cmake b/config_mick.cmake index aa97e23..2e04bec 100644 --- a/config_mick.cmake +++ b/config_mick.cmake @@ -42,7 +42,6 @@ set(BOBBYCAR_BUILDFLAGS -DDEFAULT_FIELDADVMAX=40 -DFEATURE_WEBSERVER # -DFEATURE_OTA - -DOTA_USERNAME="mick" # -DFEATURE_DPAD_5WIRESW # -DPINS_DPAD_5WIRESW_OUT=4 # -DPINS_DPAD_5WIRESW_IN1=5 diff --git a/config_nofeatures.cmake b/config_nofeatures.cmake index 708278a..d2943ff 100644 --- a/config_nofeatures.cmake +++ b/config_nofeatures.cmake @@ -42,7 +42,6 @@ set(BOBBYCAR_BUILDFLAGS -DDEFAULT_FIELDADVMAX=40 # -DFEATURE_WEBSERVER # -DFEATURE_OTA - -DOTA_USERNAME="nofeatures" # -DFEATURE_DPAD_5WIRESW # -DPINS_DPAD_5WIRESW_OUT=4 # -DPINS_DPAD_5WIRESW_IN1=5 diff --git a/config_peter.cmake b/config_peter.cmake index 83bde44..e616ae9 100644 --- a/config_peter.cmake +++ b/config_peter.cmake @@ -42,7 +42,6 @@ set(BOBBYCAR_BUILDFLAGS -DDEFAULT_FIELDADVMAX=40 -DFEATURE_WEBSERVER -DFEATURE_OTA - -DOTA_USERNAME="peter" -DFEATURE_DPAD_5WIRESW_2OUT -DPINS_DPAD_5WIRESW_OUT1=18 -DPINS_DPAD_5WIRESW_OUT2=19 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 78658ff..a18687a 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -201,7 +201,6 @@ set(headers settingsutils.h statistics.h statustexthelper.h - stringsettings.h taskmanager.h texts.h time_bobbycar.h @@ -215,7 +214,6 @@ set(headers webserver_lock.h webserver_ota.h webserver_settings.h - webserver_stringsettings.h webserver_newsettings.h widgets/doubleprogressbar.h displays/menudisplaywithtime.h @@ -439,7 +437,6 @@ set(sources settingsutils.cpp statistics.cpp statustexthelper.cpp - stringsettings.cpp taskmanager.cpp texts.cpp time_bobbycar.cpp @@ -453,7 +450,6 @@ set(sources webserver_lock.cpp webserver_ota.cpp webserver_settings.cpp - webserver_stringsettings.cpp webserver_newsettings.cpp widgets/doubleprogressbar.cpp wifi_bobbycar.cpp diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index b5eb737..d393361 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -90,17 +90,29 @@ struct CloudTransmitTimeoutAccessor : public RefAccessorSaveSettings { // Time struct TimezoneOffsetAccessor : public virtual espgui::AccessorInterface { - int32_t getValue() const override { return settings.timeSettings.timezoneOffset.count(); } - void setValue(int32_t value) override { settings.timeSettings.timezoneOffset = espchrono::minutes32{value}; saveSettings(); } + int32_t getValue() const override { return configs.timezoneOffset.value.count(); } + void setValue(int32_t value) override { configs.write_config(configs.timezoneOffset, espchrono::minutes32{value}); } +}; +struct DaylightSavingModeAccessor : public virtual espgui::AccessorInterface +{ + espchrono::DayLightSavingMode getValue() const override { return configs.timeDst.value; } + void setValue(espchrono::DayLightSavingMode value) override { configs.write_config(configs.timeDst, value); } }; -struct DaylightSavingModeAccessor : public RefAccessorSaveSettings { espchrono::DayLightSavingMode &getRef() const override { return settings.timeSettings.daylightSavingMode; } }; #ifdef FEATURE_NTP -struct TimeServerEnabledAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.timeSettings.timeServerEnabled; } }; -struct TimeSyncModeAccessor : public RefAccessorSaveSettings { sntp_sync_mode_t &getRef() const override { return settings.timeSettings.timeSyncMode; } }; +struct TimeServerEnabledAccessor : public virtual espgui::AccessorInterface +{ + bool getValue() const override { return configs.timeServerEnabled.value; } + void setValue(bool value) override { configs.write_config(configs.timeServerEnabled, value); } +}; +struct TimeSyncModeAccessor : public virtual espgui::AccessorInterface +{ + sntp_sync_mode_t getValue() const override { return configs.timeSyncMode.value; } + void setValue(sntp_sync_mode_t value) override { configs.write_config(configs.timeSyncMode, value); } +}; struct TimeSyncIntervalAccessor : public virtual espgui::AccessorInterface { - int32_t getValue() const override { return settings.timeSettings.timeSyncInterval.count(); } - void setValue(int32_t value) override { settings.timeSettings.timeSyncInterval = espchrono::milliseconds32{value}; saveSettings(); } + int32_t getValue() const override { return configs.timeSyncInterval.value.count(); } + void setValue(int32_t value) override { configs.write_config(configs.timeSyncInterval, espchrono::milliseconds32{value}); } }; #endif diff --git a/main/actions/erasenvsaction.h b/main/actions/erasenvsaction.h index a918c84..86e3215 100644 --- a/main/actions/erasenvsaction.h +++ b/main/actions/erasenvsaction.h @@ -25,7 +25,6 @@ public: } settings = presets::defaultSettings; - stringSettings = presets::makeDefaultStringSettings(); if (!settingsPersister.openCommon()) { @@ -47,12 +46,6 @@ public: ESP_LOGE("BOBBY", "load() for settings failed"); //return; } - - if (!settingsPersister.load(stringSettings)) - { - ESP_LOGE("BOBBY", "load() for stringSettings failed"); - //return; - } } }; } diff --git a/main/buildserver.cpp b/main/buildserver.cpp index c349258..8ea6dca 100644 --- a/main/buildserver.cpp +++ b/main/buildserver.cpp @@ -1,20 +1,20 @@ #include "buildserver.h" -#include -#include -#include +// esp-idf +#include "esp_http_client.h" +#include "esp_log.h" // 3rdparty lib includes #include #include +#include +#include +#include +#include "fmt/core.h" // local includes #include "globals.h" -#include "esp_log.h" -#include "fmt/core.h" - -// esp-idf -#include "esp_http_client.h" +#include "newsettings.h" #ifdef FEATURE_OTA @@ -23,8 +23,8 @@ namespace buildserver { uint16_t count_available_buildserver() { uint16_t count = 0; - for (const auto &otaServer : stringSettings.otaServers) { - if (!otaServer.url.empty()) count++; + for (const auto &otaServer : configs.otaServers) { + if (!otaServer.url.value.empty()) count++; } return count; } @@ -52,7 +52,7 @@ namespace buildserver { return; } - const auto url = fmt::format("{}/otaDescriptor?username={}&branches", server_base_url, OTA_USERNAME); + const auto url = fmt::format("{}/otaDescriptor?username={}&branches", server_base_url, configs.otaUsername.value); ESP_LOGD("BOBBY", "requesting data..."); if (const auto result = request->start(url); !result) { @@ -135,12 +135,12 @@ namespace buildserver { std::string get_ota_url_from_index(uint16_t index) { - if (index < stringSettings.otaServers.size()) + if (index < configs.otaServers.size()) { - auto otaServer = stringSettings.otaServers[index]; - if (!otaServer.url.empty()) + const auto &otaServer = configs.otaServers[index]; + if (!otaServer.url.value.empty()) { - return otaServer.url; + return otaServer.url.value; } else { @@ -167,10 +167,10 @@ namespace buildserver { std::string get_descriptor_url(std::string base_url) { - if (stringSettings.otaServerBranch.empty()) - return fmt::format("{}/otaDescriptor?username={}", base_url, OTA_USERNAME); + if (configs.otaServerBranch.value.empty()) + return fmt::format("{}/otaDescriptor?username={}", base_url, configs.otaUsername.value); else - return fmt::format("{}/otaDescriptor?username={}&branch={}", base_url, OTA_USERNAME, stringSettings.otaServerBranch); + return fmt::format("{}/otaDescriptor?username={}&branch={}", base_url, configs.otaUsername.value, configs.otaServerBranch.value); } void parse_response_into_variables(std::string response) @@ -198,8 +198,8 @@ namespace buildserver { index = 0; - url_for_latest = fmt::format("{}{}", stringSettings.otaServerUrl, doc["latest"].as()); - url_for_hashes = fmt::format("{}{}", stringSettings.otaServerUrl, doc["url"].as()); + url_for_latest = fmt::format("{}{}", configs.otaServerUrl.value, doc["latest"].as()); + url_for_hashes = fmt::format("{}{}", configs.otaServerUrl.value, doc["url"].as()); parsing_finished = true; } diff --git a/main/displays/menus/selectbuildserverbranch.cpp b/main/displays/menus/selectbuildserverbranch.cpp index e1c5679..e6ffbb6 100644 --- a/main/displays/menus/selectbuildserverbranch.cpp +++ b/main/displays/menus/selectbuildserverbranch.cpp @@ -13,6 +13,7 @@ #include "icons/back.h" #include "icons/reboot.h" #include "utils.h" +#include "newsettings.h" #define ERR_MESSAGE(text) \ constructMenuItem, DefaultFont, StaticColor, DummyAction>>(); \ @@ -51,7 +52,7 @@ public: namespace { std::string CurrentBranch::text() const { - return stringSettings.otaServerBranch.empty() ? "All builds" : stringSettings.otaServerBranch; + return configs.otaServerBranch.value.empty() ? "All builds" : configs.otaServerBranch.value; } std::string BranchMenuItem::text() const @@ -71,16 +72,14 @@ void BranchMenuItem::setName(const std::string &name) void BranchMenuItem::triggered() { - stringSettings.otaServerBranch = m_name; - saveSettings(); + configs.write_config(configs.otaServerBranch, m_name); // mir egal ob succeeded } void ClearBranchAction::triggered() { - stringSettings.otaServerBranch = {}; - saveSettings(); -} + configs.write_config(configs.otaServerBranch, {}); // mir egal ob succeeded } +} // namespace SelectBuildserverBranchMenu::SelectBuildserverBranchMenu() { @@ -89,7 +88,7 @@ SelectBuildserverBranchMenu::SelectBuildserverBranchMenu() ERR_MESSAGE(TEXT_OTA_NOBUILDSERVERAVAILABLE); // E:No server saved. } - if (stringSettings.otaServerUrl.empty()) + if (configs.otaServerUrl.value.empty()) { ERR_MESSAGE(TEXT_OTA_NOBUILDSERVERSELECTED); // E:No server selected. } @@ -100,7 +99,7 @@ SelectBuildserverBranchMenu::SelectBuildserverBranchMenu() } SelectBranch::setup_request(); - SelectBranch::start_descriptor_request(stringSettings.otaServerUrl); + SelectBranch::start_descriptor_request(configs.otaServerUrl.value); } void SelectBuildserverBranchMenu::update() diff --git a/main/displays/menus/selectbuildservermenu.cpp b/main/displays/menus/selectbuildservermenu.cpp index ad7955f..31e5e67 100644 --- a/main/displays/menus/selectbuildservermenu.cpp +++ b/main/displays/menus/selectbuildservermenu.cpp @@ -32,12 +32,10 @@ public: void triggered() override { - stringSettings.otaServerUrl = m_buildserver_url; + configs.write_config(configs.otaServerUrl, m_buildserver_url); // mir egal ob succeeded if (m_buildserver_url.substr(m_buildserver_url.length() - 4) == ".bin") - { configs.write_config(configs.otaUrl, m_buildserver_url); // mir egal ob es succeeded - } - saveSettings(); + url_for_latest.clear(); url_for_hashes.clear(); availableVersions = {}; @@ -51,10 +49,10 @@ private: SelectBuildServerMenu::SelectBuildServerMenu() { - for (const auto &otaServer : stringSettings.otaServers) + for (const auto &otaServer : configs.otaServers) { - std::string url = otaServer.url; - std::string name = (otaServer.name.empty()) ? url : otaServer.name; + std::string url = otaServer.url.value; + std::string name = (otaServer.name.value.empty()) ? url : otaServer.name.value; if (!name.empty()) { diff --git a/main/displays/menus/selectotabuildmenu.cpp b/main/displays/menus/selectotabuildmenu.cpp index 88549e7..a908c3c 100644 --- a/main/displays/menus/selectotabuildmenu.cpp +++ b/main/displays/menus/selectotabuildmenu.cpp @@ -54,7 +54,7 @@ SelectBuildMenu::SelectBuildMenu() MESSAGE(TEXT_OTA_NOBUILDSERVERAVAILABLE); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); } - else if (stringSettings.otaServerUrl.empty()) + else if (configs.otaServerUrl.value.empty()) { MESSAGE(TEXT_OTA_NOBUILDSERVERSELECTED); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); @@ -69,7 +69,7 @@ SelectBuildMenu::SelectBuildMenu() } else { - std::string serverUrl = stringSettings.otaServerUrl; + std::string serverUrl = configs.otaServerUrl.value; if (serverUrl.substr(serverUrl.length() - 4) == ".bin") { auto &menuitem = constructMenuItem>(); diff --git a/main/displays/menus/timesettingsmenu.cpp b/main/displays/menus/timesettingsmenu.cpp index 1464893..92dac51 100644 --- a/main/displays/menus/timesettingsmenu.cpp +++ b/main/displays/menus/timesettingsmenu.cpp @@ -38,9 +38,8 @@ public: { #ifdef CONFIG_ESPCHRONO_SUPPORT_DEFAULT_TIMEZONE return fmt::format("local: {}", espchrono::toString(espchrono::toDateTime(espchrono::local_clock::now()))); -#else - // Crude local time implementation - return fmt::format("local: {}", espchrono::toString(espchrono::toDateTime(espchrono::utc_clock::now() + settings.timeSettings.timezoneOffset))); +#else // Mir egal ob die lokalzeit richtig is + return fmt::format("local: {}", espchrono::toString(espchrono::toDateTime(espchrono::utc_clock::now() + configs.timezoneOffset.value))); #endif } }; diff --git a/main/dnsannounce.cpp b/main/dnsannounce.cpp index 78b99c7..db9bb4a 100644 --- a/main/dnsannounce.cpp +++ b/main/dnsannounce.cpp @@ -10,80 +10,49 @@ #include "cpputils.h" #include "lwip/dns.h" #include "globals.h" +#include "newsettings.h" + +std::string dns_lastIpAddress_v4; +std::string dns_lastIpAddress_v6; +std::string dns_lastIpAddress_v6_global; void init_dns_announce() { - } void handle_dns_announce() { - const auto staStatus = wifi_stack::get_sta_status(); - const auto randDNSName = cpputils::randomNumber(espcpputils::esp_random_device{}); - if (staStatus == wifi_stack::WiFiStaStatus::CONNECTED) - { - EVERY_N_SECONDS ( 2 ) - { - // Get IPv4 - if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result) - { - std::string curIpAddress = wifi_stack::toString(result->ip); - if (curIpAddress != "0.0.0.0") - { - if (dns_lastIpAddress_v4 != curIpAddress) - { - dns_lastIpAddress_v4 = curIpAddress; - ip_addr_t tmpIpResolved; - std::string toLookup = fmt::format("{}__{}.{}.announce.bobbycar.cloud", randDNSName, curIpAddress, OTA_USERNAME); - ESP_LOGI("BOBBY", "Trying to look up %s", toLookup.c_str()); - if (const auto err = dns_gethostbyname(toLookup.c_str(), &tmpIpResolved, NULL, NULL); err != ERR_OK && err != ERR_INPROGRESS) - { - ESP_LOGW("BOBBY", "There is a error in the matrix (dns ipv4 lookup failed) -> %d", err); - dns_lastIpAddress_v4 = "-"; - dns_lastIpAddress_v6 = "-"; - dns_lastIpAddress_v6_global = "-"; - } - } - } - } - else - { - ESP_LOGW("BOBBY", "get_ip_info() failed with %.*s", result.error().size(), result.error().data()); - } - esp_ip6_addr_t tmpv6addr; - if (const auto result = esp_netif_get_ip6_linklocal(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &tmpv6addr); result == ESP_OK) - { - std::string curIpV6Address = wifi_stack::toString(tmpv6addr); - std::replace(curIpV6Address.begin(), curIpV6Address.end(), ':', '-'); - if (dns_lastIpAddress_v6 != curIpV6Address) - { - dns_lastIpAddress_v6 = curIpV6Address; - ip_addr_t tmpIpResolved; - std::string toLookup = fmt::format("{}__{}.{}.announce6.bobbycar.cloud", randDNSName, curIpV6Address, OTA_USERNAME); - ESP_LOGI("BOBBY", "Trying to look up %s", toLookup.c_str()); - if (const auto err = dns_gethostbyname(toLookup.c_str(), &tmpIpResolved, NULL, NULL); err != ERR_OK && err != ERR_INPROGRESS) - { - ESP_LOGW("BOBBY", "There is a error in the matrix (dns ipv6 local lookup failed) -> %d", err); - dns_lastIpAddress_v4 = "-"; - dns_lastIpAddress_v6 = "-"; - dns_lastIpAddress_v6_global = "-"; - } - } - } + if (!configs.dns_announce_enabled.value) + return; - if (const auto result = esp_netif_get_ip6_global(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &tmpv6addr); result == ESP_OK) + if (wifi_stack::get_sta_status() != wifi_stack::WiFiStaStatus::CONNECTED) + { + dns_lastIpAddress_v4 = "-"; + dns_lastIpAddress_v6 = "-"; + dns_lastIpAddress_v6_global = "-"; + + return; + } + + const auto randDNSName = cpputils::randomNumber(espcpputils::esp_random_device{}); + + EVERY_N_SECONDS ( 2 ) + { + // Get IPv4 + if (const auto result = wifi_stack::get_ip_info(TCPIP_ADAPTER_IF_STA); result) + { + std::string curIpAddress = wifi_stack::toString(result->ip); + if (curIpAddress != "0.0.0.0") { - std::string curIpV6Address = wifi_stack::toString(tmpv6addr); - if (dns_lastIpAddress_v6_global != curIpV6Address) + if (dns_lastIpAddress_v4 != curIpAddress) { - dns_lastIpAddress_v6_global = curIpV6Address; - std::replace(curIpV6Address.begin(), curIpV6Address.end(), ':', '-'); + dns_lastIpAddress_v4 = curIpAddress; ip_addr_t tmpIpResolved; - std::string toLookup = fmt::format("{}global__{}.{}.announce6.bobbycar.cloud", randDNSName, curIpV6Address, OTA_USERNAME); + std::string toLookup = fmt::format("{}__{}.{}.announce.bobbycar.cloud", randDNSName, curIpAddress, configs.otaUsername.value); ESP_LOGI("BOBBY", "Trying to look up %s", toLookup.c_str()); if (const auto err = dns_gethostbyname(toLookup.c_str(), &tmpIpResolved, NULL, NULL); err != ERR_OK && err != ERR_INPROGRESS) { - ESP_LOGW("BOBBY", "There is a error in the matrix (dns ipv6 global lookup failed) -> %d", err); + ESP_LOGW("BOBBY", "There is a error in the matrix (dns ipv4 lookup failed) -> %d", err); dns_lastIpAddress_v4 = "-"; dns_lastIpAddress_v6 = "-"; dns_lastIpAddress_v6_global = "-"; @@ -91,15 +60,54 @@ void handle_dns_announce() } } } + else + { + ESP_LOGW("BOBBY", "get_ip_info() failed with %.*s", result.error().size(), result.error().data()); + } - EVERY_N_SECONDS( 120 ) { - dns_lastIpAddress_v4 = "-"; - dns_lastIpAddress_v6 = "-"; - dns_lastIpAddress_v6_global = "-"; + esp_ip6_addr_t tmpv6addr; + if (const auto result = esp_netif_get_ip6_linklocal(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &tmpv6addr); result == ESP_OK) + { + std::string curIpV6Address = wifi_stack::toString(tmpv6addr); + std::replace(curIpV6Address.begin(), curIpV6Address.end(), ':', '-'); + if (dns_lastIpAddress_v6 != curIpV6Address) + { + dns_lastIpAddress_v6 = curIpV6Address; + ip_addr_t tmpIpResolved; + std::string toLookup = fmt::format("{}__{}.{}.announce6.bobbycar.cloud", randDNSName, curIpV6Address, configs.otaUsername.value); + ESP_LOGI("BOBBY", "Trying to look up %s", toLookup.c_str()); + if (const auto err = dns_gethostbyname(toLookup.c_str(), &tmpIpResolved, NULL, NULL); err != ERR_OK && err != ERR_INPROGRESS) + { + ESP_LOGW("BOBBY", "There is a error in the matrix (dns ipv6 local lookup failed) -> %d", err); + dns_lastIpAddress_v4 = "-"; + dns_lastIpAddress_v6 = "-"; + dns_lastIpAddress_v6_global = "-"; + } + } + } + + if (const auto result = esp_netif_get_ip6_global(wifi_stack::esp_netifs[ESP_IF_WIFI_STA], &tmpv6addr); result == ESP_OK) + { + std::string curIpV6Address = wifi_stack::toString(tmpv6addr); + if (dns_lastIpAddress_v6_global != curIpV6Address) + { + dns_lastIpAddress_v6_global = curIpV6Address; + std::replace(curIpV6Address.begin(), curIpV6Address.end(), ':', '-'); + ip_addr_t tmpIpResolved; + std::string toLookup = fmt::format("{}global__{}.{}.announce6.bobbycar.cloud", randDNSName, curIpV6Address, configs.otaUsername.value); + ESP_LOGI("BOBBY", "Trying to look up %s", toLookup.c_str()); + if (const auto err = dns_gethostbyname(toLookup.c_str(), &tmpIpResolved, NULL, NULL); err != ERR_OK && err != ERR_INPROGRESS) + { + ESP_LOGW("BOBBY", "There is a error in the matrix (dns ipv6 global lookup failed) -> %d", err); + dns_lastIpAddress_v4 = "-"; + dns_lastIpAddress_v6 = "-"; + dns_lastIpAddress_v6_global = "-"; + } + } } } - else - { + + EVERY_N_SECONDS( 120 ) { dns_lastIpAddress_v4 = "-"; dns_lastIpAddress_v6 = "-"; dns_lastIpAddress_v6_global = "-"; diff --git a/main/dnsannounce.h b/main/dnsannounce.h index f42b211..96c5ea7 100644 --- a/main/dnsannounce.h +++ b/main/dnsannounce.h @@ -1,4 +1,13 @@ #pragma once +// system includes +#include + +#ifdef FEATURE_DNS_NS +extern std::string dns_lastIpAddress_v4; +extern std::string dns_lastIpAddress_v6; +extern std::string dns_lastIpAddress_v6_global; + void init_dns_announce(); void handle_dns_announce(); +#endif diff --git a/main/globals.cpp b/main/globals.cpp index a90cf92..3d379e4 100644 --- a/main/globals.cpp +++ b/main/globals.cpp @@ -24,14 +24,7 @@ bool simplified = #endif ; -#ifdef FEATURE_DNS_NS -std::string dns_lastIpAddress_v4 = ""; -std::string dns_lastIpAddress_v6 = ""; -std::string dns_lastIpAddress_v6_global = ""; -#endif - Settings settings; -StringSettings stringSettings; SettingsPersister settingsPersister; std::array ledstrip_custom_colors; diff --git a/main/globals.h b/main/globals.h index 12dd799..9b11b09 100644 --- a/main/globals.h +++ b/main/globals.h @@ -23,7 +23,6 @@ #include "display.h" #include "modeinterface.h" #include "settings.h" -#include "stringsettings.h" #include "settingspersister.h" #include "macros_bobbycar.h" @@ -48,16 +47,9 @@ extern bool isLocked; #include GLOBALS_PLUGIN #endif -#ifdef FEATURE_DNS_NS -extern std::string dns_lastIpAddress_v4; -extern std::string dns_lastIpAddress_v6; -extern std::string dns_lastIpAddress_v6_global; -#endif - extern bool simplified; extern Settings settings; -extern StringSettings stringSettings; extern SettingsPersister settingsPersister; extern std::array ledstrip_custom_colors; diff --git a/main/main.cpp b/main/main.cpp index 9bd989a..d9d2d41 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,9 +1,5 @@ constexpr const char * const TAG = "BOBBY"; -#ifndef OTA_USERNAME -#error No OTA username! -#endif - // system includes #include @@ -51,7 +47,6 @@ extern "C" void app_main() ESP_LOGE(TAG, "config_init_settings() failed with %s", esp_err_to_name(result)); settings = presets::defaultSettings; - stringSettings = presets::makeDefaultStringSettings(); if (settingsPersister.init()) { diff --git a/main/newsettings.h b/main/newsettings.h index c85f23f..bf7ff56 100644 --- a/main/newsettings.h +++ b/main/newsettings.h @@ -7,12 +7,17 @@ #include #include +// esp-idf includes +#include + // 3rdparty lib includes #include #include #include +#include #include #include +#include #include using namespace espconfig; @@ -61,6 +66,18 @@ public: ConfigWrapper doorToken; }; +class ConfiguredOtaServer +{ +public: + ConfiguredOtaServer(const char *nameKey, const char *urlKey) : + name{std::string{}, DoReset, {}, nameKey }, + url {std::string{}, DoReset, StringOr, urlKey } + {} + + ConfigWrapper name; + ConfigWrapper url; +}; + class ConfigContainer { using mac_t = wifi_stack::mac_t; @@ -90,6 +107,13 @@ public: ConfigWrapper wifiApChannel {1, DoReset, {}, "wifiApChannel" }; ConfigWrapper wifiApAuthmode{WIFI_AUTH_WPA2_PSK, DoReset, {}, "wifiApAuthmode" }; + ConfigWrapper timeServerEnabled {false, DoReset, {}, "timeServerEnabl" }; + ConfigWrapper timeServer {"europe.pool.ntp.org", NoReset, StringMaxSize<64>, "timeServer" }; + ConfigWrapper timeSyncMode {SNTP_SYNC_MODE_IMMED, NoReset, {}, "timeSyncMode" }; + ConfigWrapper timeSyncInterval{espchrono::milliseconds32{CONFIG_LWIP_SNTP_UPDATE_DELAY}, NoReset, MinTimeSyncInterval, "timeSyncInterva" }; + ConfigWrapper timezoneOffset{espchrono::minutes32{60}, DoReset, {}, "timezoneOffset" }; // MinMaxValue + ConfigWrappertimeDst{espchrono::DayLightSavingMode::EuropeanSummerTime, DoReset, {}, "time_dst" }; + ConfigWrapper canBusResetOnError {false, DoReset, {}, "canBusRstErr" }; std::array wireless_door_configs { @@ -110,8 +134,21 @@ public: ConfigWrapper cloudUrl {std::string{}, DoReset, StringOr, "cloudUrl" }; ConfigWrapper udpCloudHost {std::string{}, DoReset, {}, "udpCloudHost" }; - ConfigWrapper otaUrl {std::string{}, DoReset, StringOr, "otaUrl" }; + ConfigWrapper otaUrl {std::string{}, DoReset, StringOr, "otaUrl" }; + ConfigWrapper otaUsername {std::string{}, DoReset, {}, "otaUsername" }; + ConfigWrapper otaServerUrl {std::string{}, DoReset, StringOr, "otaServerUrl" }; + ConfigWrapper otaServerBranch {std::string{}, DoReset, {}, "otaServerBranch" }; + std::array otaServers { + ConfiguredOtaServer { "otaName0", "otaUrl0" }, + ConfiguredOtaServer { "otaName1", "otaUrl1" }, + ConfiguredOtaServer { "otaName2", "otaUrl2" }, + ConfiguredOtaServer { "otaName3", "otaUrl3" }, + ConfiguredOtaServer { "otaName4", "otaUrl4" } + }; + + ConfigWrapper dns_announce_enabled{true, DoReset, {}, "dnsAnnounceEnab" }; + ConfigWrapper dns_announce_key {std::string{}, DoReset, {}, "dnsAnnounceKey" }; ConfigWrapper webserverPassword {std::string{}, DoReset, {}, "websPassword" }; #define NEW_SETTINGS(x) \ @@ -228,6 +265,13 @@ public: x(wifiApChannel) \ x(wifiApAuthmode) \ \ + x(timeServerEnabled) \ + x(timeServer) \ + x(timeSyncMode) \ + x(timeSyncInterval) \ + x(timezoneOffset) \ + x(timeDst) \ + \ x(canBusResetOnError) \ \ x(wireless_door_configs[0].doorId) \ @@ -251,8 +295,24 @@ public: \ x(cloudUrl) \ x(udpCloudHost) \ - x(otaUrl) \ \ + x(otaUrl) \ + x(otaUsername) \ + x(otaServerUrl) \ + x(otaServerBranch) \ + x(otaServers[0].name) \ + x(otaServers[0].url) \ + x(otaServers[1].name) \ + x(otaServers[1].url) \ + x(otaServers[2].name) \ + x(otaServers[2].url) \ + x(otaServers[3].name) \ + x(otaServers[3].url) \ + x(otaServers[4].name) \ + x(otaServers[4].url) \ + \ + x(dns_announce_enabled) \ + x(dns_announce_key) \ // x(webserverPassword) template diff --git a/main/presets.cpp b/main/presets.cpp index 2086955..7a06679 100644 --- a/main/presets.cpp +++ b/main/presets.cpp @@ -1,35 +1 @@ #include "presets.h" -#include "macros_bobbycar.h" - -namespace presets { -StringSettings makeDefaultStringSettings() -{ -#ifdef FEATURE_OTA - using ConfiguredOtaServer = StringSettings::ConfiguredOtaServer; -#endif - - return { -#ifdef FEATURE_NTP - .timeServer = "europe.pool.ntp.org", -#endif -#ifdef FEATURE_OTA - .otaServers = std::array { - ConfiguredOtaServer { .name = {}, .url = {} }, - ConfiguredOtaServer { .name = {}, .url = {} }, - ConfiguredOtaServer { .name = {}, .url = {} }, - ConfiguredOtaServer { .name = {}, .url = {} }, - ConfiguredOtaServer { .name = {}, .url = {} }, -// ConfiguredOtaServer { .name = {}, .url = {} }, -// ConfiguredOtaServer { .name = {}, .url = {} }, -// ConfiguredOtaServer { .name = {}, .url = {} }, -// ConfiguredOtaServer { .name = {}, .url = {} }, -// ConfiguredOtaServer { .name = {}, .url = {} }, - }, - .otaServerUrl = {}, -#endif -#ifdef FEATURE_OTA - .otaServerBranch = {}, -#endif - }; -} -} // namespace presets diff --git a/main/presets.h b/main/presets.h index 9b1af6e..a172063 100644 --- a/main/presets.h +++ b/main/presets.h @@ -11,7 +11,6 @@ // local includes #include "settings.h" -#include "stringsettings.h" #include "ledstripdefines.h" #include "ledstrip.h" @@ -34,16 +33,6 @@ constexpr Settings::Limits kidsLimits { .phaseAdvMax = 20 }; -constexpr Settings::TimeSettings defaultTimeSettings { - .timezoneOffset = 60min, - .daylightSavingMode = espchrono::DayLightSavingMode::EuropeanSummerTime, -#ifdef FEATURE_NTP - .timeServerEnabled = true, - .timeSyncMode = SNTP_SYNC_MODE_IMMED, - .timeSyncInterval = espchrono::milliseconds32{CONFIG_LWIP_SNTP_UPDATE_DELAY}, -#endif -}; - constexpr Settings::ControllerHardware defaultControllerHardware { .enableFrontLeft = true, .enableFrontRight = true, @@ -313,7 +302,6 @@ constexpr Settings defaultSettings { #ifdef FEATURE_BLE .bleSettings = defaultBleSettings, #endif - .timeSettings = defaultTimeSettings, .controllerHardware = defaultControllerHardware, .boardcomputerHardware = defaultBoardcomputerHardware, #ifdef FEATURE_CLOUD @@ -338,6 +326,4 @@ constexpr Settings defaultSettings { .espnow = defaultEspNowSettings, #endif }; - -StringSettings makeDefaultStringSettings(); } // namespace presets diff --git a/main/qrimport.cpp b/main/qrimport.cpp index f81604c..dc2093f 100644 --- a/main/qrimport.cpp +++ b/main/qrimport.cpp @@ -12,6 +12,7 @@ // local includes #include "globals.h" +#include "newsettings.h" namespace qrimport { @@ -109,7 +110,7 @@ tl::expected start_qr_request() return tl::make_unexpected("request im oarsch"); } - if (const auto res = http_request->start(fmt::format("http://qr.bobbycar.cloud/{}.qr", OTA_USERNAME)); !res) + if (const auto res = http_request->start(fmt::format("http://qr.bobbycar.cloud/{}.qr", configs.otaUsername.value)); !res) { return res; } diff --git a/main/settings.h b/main/settings.h index 40b759c..a13a908 100644 --- a/main/settings.h +++ b/main/settings.h @@ -52,17 +52,6 @@ struct Settings } bleSettings; #endif - struct TimeSettings { - espchrono::minutes32 timezoneOffset; - espchrono::DayLightSavingMode daylightSavingMode; - -#ifdef FEATURE_NTP - bool timeServerEnabled; - sntp_sync_mode_t timeSyncMode; - espchrono::milliseconds32 timeSyncInterval; -#endif - } timeSettings; - struct ControllerHardware { bool enableFrontLeft, enableFrontRight, enableBackLeft, enableBackRight; bool invertFrontLeft, invertFrontRight, invertBackLeft, invertBackRight; @@ -244,14 +233,6 @@ void Settings::executeForEveryCommonSetting(T &&callable) callable("bleEnabled", bleSettings.bleEnabled); #endif - callable("timezoneOffset", timeSettings.timezoneOffset); - callable("daylightSaving", timeSettings.daylightSavingMode); -#ifdef FEATURE_NTP - callable("timeServerEnab", timeSettings.timeServerEnabled); - callable("timeSyncMode", timeSettings.timeSyncMode); - callable("timeSyncInterv", timeSettings.timeSyncInterval); -#endif - callable("wheelDiameter", controllerHardware.wheelDiameter); callable("numMagnetPoles", controllerHardware.numMagnetPoles); callable("swapFrontBack", controllerHardware.swapFrontBack); diff --git a/main/settingspersister.cpp b/main/settingspersister.cpp index 0da03fc..335b70a 100644 --- a/main/settingspersister.cpp +++ b/main/settingspersister.cpp @@ -24,7 +24,6 @@ #endif #include "unifiedmodelmode.h" #include "settings.h" -#include "stringsettings.h" bool SettingsPersister::init() { @@ -327,7 +326,6 @@ bool SettingsPersister::load(T &settings) } template bool SettingsPersister::load(Settings &settings); -template bool SettingsPersister::load(StringSettings &settings); template struct nvsSetterHelper; template<> struct nvsSetterHelper { static constexpr auto nvs_set = &nvs_set_i8; }; @@ -455,7 +453,6 @@ bool SettingsPersister::save(T &settings) } template bool SettingsPersister::save(Settings &settings); -template bool SettingsPersister::save(StringSettings &settings); std::optional SettingsPersister::currentlyOpenProfileIndex() const { diff --git a/main/settingsutils.cpp b/main/settingsutils.cpp index 87b64bb..3f8967e 100644 --- a/main/settingsutils.cpp +++ b/main/settingsutils.cpp @@ -22,7 +22,6 @@ void switchProfile(uint8_t index) #endif settings = presets::defaultSettings; - stringSettings = presets::makeDefaultStringSettings(); if (!settingsPersister.openProfile(index)) { @@ -35,11 +34,5 @@ void switchProfile(uint8_t index) ESP_LOGE("BOBBY", "load() for settings failed"); return; } - - if (!settingsPersister.load(stringSettings)) - { - ESP_LOGE("BOBBY", "load() for stringSettings failed"); - return; - } } } // namespace diff --git a/main/stringsettings.cpp b/main/stringsettings.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/main/stringsettings.h b/main/stringsettings.h deleted file mode 100644 index 68d5d68..0000000 --- a/main/stringsettings.h +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -// system includes -#include -#include - -struct StringSettings -{ -#ifdef FEATURE_NTP - std::string timeServer; -#endif - - template - void executeForEveryCommonSetting(T &&callable); - - template - void executeForEveryProfileSetting(T &&callable); - -#ifdef FEATURE_OTA - struct ConfiguredOtaServer { - std::string name; - std::string url; - }; - - std::array otaServers; - std::string otaServerUrl; -#endif -#ifdef FEATURE_DNS_NS - std::string dns_key; -#endif -#ifdef FEATURE_OTA - std::string otaServerBranch; -#endif -}; - -template -void StringSettings::executeForEveryCommonSetting(T &&callable) -{ -#ifdef FEATURE_NTP - callable("timeServer", timeServer); -#endif -#ifdef FEATURE_OTA - callable("otaName0", otaServers[0].name); - callable("otaUrl0", otaServers[0].url); - callable("otaName1", otaServers[1].name); - callable("otaUrl1", otaServers[1].url); - callable("otaName2", otaServers[2].name); - callable("otaUrl2", otaServers[2].url); - callable("otaName3", otaServers[3].name); - callable("otaUrl3", otaServers[3].url); - callable("otaName4", otaServers[4].name); - callable("otaUrl4", otaServers[4].url); -// callable("otaName5", otaServers[5].name); -// callable("otaUrl5", otaServers[5].url); -// callable("otaName6", otaServers[6].name); -// callable("otaUrl6", otaServers[6].url); -// callable("otaName7", otaServers[7].name); -// callable("otaUrl7", otaServers[7].url); -// callable("otaName8", otaServers[8].name); -// callable("otaUrl8", otaServers[8].url); -// callable("otaName9", otaServers[9].name); -// callable("otaUrl9", otaServers[9].url); - - callable("otaserver", otaServerUrl); - callable("otaBranch", otaServerBranch); -#endif -#ifdef FEATURE_DNS_NS - callable("dnskey", dns_key); -#endif -} - -template -void StringSettings::executeForEveryProfileSetting(T &&callable) -{ -} diff --git a/main/time_bobbycar.cpp b/main/time_bobbycar.cpp index f95c6a4..a0a4cc9 100644 --- a/main/time_bobbycar.cpp +++ b/main/time_bobbycar.cpp @@ -11,12 +11,12 @@ #include // local includes -#include "globals.h" +#include "newsettings.h" espchrono::time_zone get_default_timezone() noexcept { using namespace espchrono; - return time_zone{minutes32{settings.timeSettings.timezoneOffset}, settings.timeSettings.daylightSavingMode}; + return time_zone{configs.timezoneOffset.value, configs.timeDst.value}; } #ifdef CONFIG_ESPCHRONO_SUPPORT_DEFAULT_TIMEZONE @@ -37,11 +37,11 @@ void initTime() { sntp_setoperatingmode(SNTP_OPMODE_POLL); static_assert(SNTP_MAX_SERVERS >= 1); - sntp_setservername(0, stringSettings.timeServer.c_str()); + sntp_setservername(0, configs.timeServer.value.c_str()); sntp_set_time_sync_notification_cb(time_sync_notification_cb); - sntp_set_sync_mode(settings.timeSettings.timeSyncMode); - sntp_set_sync_interval(espchrono::milliseconds32{settings.timeSettings.timeSyncInterval}.count()); - if (settings.timeSettings.timeServerEnabled) + sntp_set_sync_mode(configs.timeSyncMode.value); + sntp_set_sync_interval(espchrono::milliseconds32{configs.timeSyncInterval.value}.count()); + if (configs.timeServerEnabled.value) { ESP_LOGI("BOBBY", "sntp_init() ..."); sntp_init(); @@ -54,9 +54,9 @@ void initTime() void updateTime() { - if (bool(sntp_enabled()) != settings.timeSettings.timeServerEnabled) + if (bool(sntp_enabled()) != configs.timeServerEnabled.value) { - if (settings.timeSettings.timeServerEnabled) + if (configs.timeServerEnabled.value) { ESP_LOGD("BOBBY", "calling sntp_init()..."); sntp_init(); @@ -70,24 +70,24 @@ void updateTime() } } - if (stringSettings.timeServer != sntp_getservername(0)) + if (configs.timeServer.value != sntp_getservername(0)) { - ESP_LOGD("BOBBY", "calling sntp_getservername() with %s...", stringSettings.timeServer.c_str()); - sntp_setservername(0, stringSettings.timeServer.c_str()); + ESP_LOGD("BOBBY", "calling sntp_getservername() with %s...", configs.timeServer.value.c_str()); + sntp_setservername(0, configs.timeServer.value.c_str()); ESP_LOGI("BOBBY", "sntp_getservername() finished"); } - if (settings.timeSettings.timeSyncMode != sntp_get_sync_mode()) + if (configs.timeSyncMode.value != sntp_get_sync_mode()) { - ESP_LOGD("BOBBY", "calling sntp_set_sync_mode() with %s...", espcpputils::toString(settings.timeSettings.timeSyncMode).c_str()); - sntp_set_sync_mode(settings.timeSettings.timeSyncMode); + ESP_LOGD("BOBBY", "calling sntp_set_sync_mode() with %s...", espcpputils::toString(configs.timeSyncMode.value).c_str()); + sntp_set_sync_mode(configs.timeSyncMode.value); ESP_LOGI("BOBBY", "sntp_set_sync_mode() finished"); } - if (settings.timeSettings.timeSyncInterval != espchrono::milliseconds32{sntp_get_sync_interval()}) + if (configs.timeSyncInterval.value != espchrono::milliseconds32{sntp_get_sync_interval()}) { - ESP_LOGD("BOBBY", "calling sntp_set_sync_interval() with %s...", espchrono::toString(settings.timeSettings.timeSyncInterval).c_str()); - sntp_set_sync_interval(espchrono::milliseconds32{settings.timeSettings.timeSyncInterval}.count()); + ESP_LOGD("BOBBY", "calling sntp_set_sync_interval() with %s...", espchrono::toString(configs.timeSyncInterval.value).c_str()); + sntp_set_sync_interval(espchrono::milliseconds32{configs.timeSyncInterval.value}.count()); ESP_LOGI("BOBBY", "sntp_set_sync_interval() finished"); } } @@ -108,3 +108,20 @@ void time_sync_notification_cb(struct timeval *tv) ESP_LOGI("BOBBY", "nullptr"); } #endif + +void time_set_now(espchrono::utc_clock::time_point now) +{ + using namespace espchrono; + // ESP_LOGI("BOBBY", "%s (%lld)%s", toString(toDateTime(now)).c_str(), std::chrono::floor(now.time_since_epoch()).count(), time_valid(now) ? "":" (probably invalid)"); + const auto seconds = std::chrono::floor(now.time_since_epoch()); + + timeval ts { + .tv_sec = (long int)seconds.count(), + .tv_usec = (long int)std::chrono::floor(now.time_since_epoch() - seconds).count() + }; + timezone tz { + .tz_minuteswest = 0, + .tz_dsttime = 0 + }; + settimeofday(&ts, &tz); +} diff --git a/main/time_bobbycar.h b/main/time_bobbycar.h index 2d9d88c..5e38aa0 100644 --- a/main/time_bobbycar.h +++ b/main/time_bobbycar.h @@ -11,3 +11,5 @@ espchrono::time_zone get_default_timezone() noexcept; void initTime(); void updateTime(); #endif + +void time_set_now(espchrono::utc_clock::time_point now); diff --git a/main/utils.cpp b/main/utils.cpp index 3fe823b..88f192f 100644 --- a/main/utils.cpp +++ b/main/utils.cpp @@ -202,8 +202,6 @@ bool loadSettings() bool result{true}; if (!settingsPersister.load(settings)) result = false; - if (!settingsPersister.load(stringSettings)) - result = false; return result; } @@ -213,8 +211,6 @@ bool saveSettings() bool result{true}; if (!settingsPersister.save(settings)) result = false; - if (!settingsPersister.save(stringSettings)) - result = false; return result; } @@ -276,25 +272,13 @@ uint8_t time_to_percent(espchrono::milliseconds32 repeat, espchrono::millisecond return invert ? numLeds : 0; } -void time_set_now(espchrono::utc_clock::time_point now) -{ - using namespace espchrono; - // ESP_LOGI("BOBBY", "%s (%lld)%s", toString(toDateTime(now)).c_str(), std::chrono::floor(now.time_since_epoch()).count(), time_valid(now) ? "":" (probably invalid)"); - const auto seconds = std::chrono::floor(now.time_since_epoch()); - - timeval ts { - .tv_sec = (long int)seconds.count(), - .tv_usec = (long int)std::chrono::floor(now.time_since_epoch() - seconds).count() - }; - timezone tz { - .tz_minuteswest = 0, - .tz_dsttime = 0 - }; - settimeofday(&ts, &tz); -} - std::string local_clock_string() { - const auto dt = espchrono::toDateTime(espchrono::utc_clock::now() + settings.timeSettings.timezoneOffset); +#ifdef CONFIG_ESPCHRONO_SUPPORT_DEFAULT_TIMEZONE + const auto now = espchrono::local_clock::now(); +#else // mir egal ob die lokalzeit richtig is + const auto now = espchrono::utc_clock::now() + configs.timezoneOffset.value; +#endif + const auto dt = espchrono::toDateTime(now); return fmt::format("{:02d}:{:02d}:{:02d}", dt.hour, dt.minute, dt.second); } diff --git a/main/utils.h b/main/utils.h index ba20812..2cc4a8f 100644 --- a/main/utils.h +++ b/main/utils.h @@ -59,5 +59,4 @@ void readPotis(); float wattToAmpere(float watt); float wattToMotorCurrent(float watt); uint8_t time_to_percent(espchrono::milliseconds32 repeat, espchrono::milliseconds32 riseTime, espchrono::milliseconds32 fullTime, size_t numLeds, bool invert); -void time_set_now(espchrono::utc_clock::time_point now); std::string local_clock_string(); diff --git a/main/webserver.cpp b/main/webserver.cpp index f8a6105..899722c 100644 --- a/main/webserver.cpp +++ b/main/webserver.cpp @@ -24,7 +24,6 @@ #include "webserver_ota.h" #endif #include "webserver_settings.h" -#include "webserver_stringsettings.h" #include "webserver_newsettings.h" #ifdef OLD_NVS #include "webserver_dumpnvs.h" @@ -60,7 +59,7 @@ void initWebserver() { httpd_config_t httpConfig HTTPD_DEFAULT_CONFIG(); httpConfig.core_id = 1; - httpConfig.max_uri_handlers = 17; + httpConfig.max_uri_handlers = 15; httpConfig.stack_size = 8192; const auto result = httpd_start(&httpdHandle, &httpConfig); @@ -82,8 +81,6 @@ void initWebserver() #endif httpd_uri_t { .uri = "/settings", .method = HTTP_GET, .handler = webserver_settings_handler, .user_ctx = NULL }, httpd_uri_t { .uri = "/saveSettings", .method = HTTP_GET, .handler = webserver_saveSettings_handler, .user_ctx = NULL }, - httpd_uri_t { .uri = "/stringSettings", .method = HTTP_GET, .handler = webserver_stringSettings_handler, .user_ctx = NULL }, - httpd_uri_t { .uri = "/saveStringSettings", .method = HTTP_GET, .handler = webserver_saveStringSettings_handler, .user_ctx = NULL }, httpd_uri_t { .uri = "/newSettings", .method = HTTP_GET, .handler = webserver_newSettings_handler, .user_ctx = NULL }, httpd_uri_t { .uri = "/saveNewSettings", .method = HTTP_GET, .handler = webserver_saveNewSettings_handler, .user_ctx = NULL }, httpd_uri_t { .uri = "/resetNewSettings", .method = HTTP_GET, .handler = webserver_resetNewSettings_handler, .user_ctx = NULL }, diff --git a/main/webserver_displaycontrol.cpp b/main/webserver_displaycontrol.cpp index e131723..f3ffc99 100644 --- a/main/webserver_displaycontrol.cpp +++ b/main/webserver_displaycontrol.cpp @@ -184,7 +184,6 @@ esp_err_t webserver_root_handler(httpd_req_t *req) #endif "Settings - " - "String Settings - " "New Settings - " "Dump NVS"; } diff --git a/main/webserver_dumpnvs.cpp b/main/webserver_dumpnvs.cpp index 278c8ad..773af51 100644 --- a/main/webserver_dumpnvs.cpp +++ b/main/webserver_dumpnvs.cpp @@ -154,11 +154,6 @@ esp_err_t webserver_dump_nvs_handler(httpd_req_t *req) showInputForSetting(key, value, json_settings); }); - JsonObject json_stringSettings = doc.createNestedObject("stringSettings"); - stringSettings.executeForEveryCommonSetting([&](std::string_view key, const auto &value){ - showInputForSetting(key, value, json_stringSettings); - }); - JsonObject profiles = doc.createNestedObject("profiles"); // Profile settings @@ -175,13 +170,8 @@ esp_err_t webserver_dump_nvs_handler(httpd_req_t *req) const auto profile_str = cur_profile ? std::to_string(*cur_profile) : "-"; JsonObject profile = profiles.createNestedObject(profile_str); - JsonObject profile_stringSettings = profile.createNestedObject("stringSettings"); JsonObject profile_settings = profile.createNestedObject("settings"); - stringSettings.executeForEveryProfileSetting([&](const char *key, auto &value){ - showInputForSetting(key, value, profile_stringSettings); - }); - settings.executeForEveryProfileSetting([&](const char *key, auto &value){ showInputForSetting(key, value, profile_settings); }); diff --git a/main/webserver_newsettings.cpp b/main/webserver_newsettings.cpp index dc74d57..2af1af2 100644 --- a/main/webserver_newsettings.cpp +++ b/main/webserver_newsettings.cpp @@ -169,7 +169,6 @@ esp_err_t webserver_newSettings_handler(httpd_req_t *req) "Update - " #endif "Settings - " - "String Settings - " "New Settings - " "Dump NVS"; } diff --git a/main/webserver_ota.cpp b/main/webserver_ota.cpp index ecaa7f4..2d614f6 100644 --- a/main/webserver_ota.cpp +++ b/main/webserver_ota.cpp @@ -209,7 +209,6 @@ esp_err_t webserver_ota_handler(httpd_req_t *req) body += "Display control - " "Update - " "Settings - " - "String Settings - " "New Settings - " "Dump NVS"; } diff --git a/main/webserver_settings.cpp b/main/webserver_settings.cpp index dd9fee0..ebf2404 100644 --- a/main/webserver_settings.cpp +++ b/main/webserver_settings.cpp @@ -146,7 +146,6 @@ esp_err_t webserver_settings_handler(httpd_req_t *req) "Update - " #endif "Settings - " - "String Settings - " "New Settings - " "Dump NVS"; } diff --git a/main/webserver_stringsettings.cpp b/main/webserver_stringsettings.cpp deleted file mode 100644 index 92b995e..0000000 --- a/main/webserver_stringsettings.cpp +++ /dev/null @@ -1,191 +0,0 @@ -#include "webserver_stringsettings.h" - -// esp-idf includes -#ifdef FEATURE_WEBSERVER -#include -#endif - -// 3rdparty lib includes -#include -#include -#include -#include -#include -#include - -// local includes -#include "globals.h" -#include "webserver_lock.h" - -#ifdef FEATURE_WEBSERVER -using namespace std::chrono_literals; -using esphttpdutils::HtmlTag; - -namespace { -constexpr const char * const TAG = "BOBBYWEB"; -} // namespace - -esp_err_t webserver_stringSettings_handler(httpd_req_t *req) -{ -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } -#endif - - std::string body; - - { - HtmlTag htmlTag{"html", body}; - - { - HtmlTag headTag{"head", body}; - - { - HtmlTag titleTag{"title", body}; - body += "String Settings"; - } - - body += ""; - - HtmlTag styleTag{"style", "type=\"text/css\"", body}; - body += - ".form-table {" - "display: table;" - "border-collapse: separate;" - "border-spacing: 10px 0;" - "}" - - ".form-table .form-table-row {" - "display: table-row;" - "}" - - ".form-table .form-table-row .form-table-cell {" - "display: table-cell;" - "}"; - } - - { - HtmlTag bodyTag{"body", body}; - - { - HtmlTag h1Tag{"h1", body}; - body += "String Settings"; - } - - { - HtmlTag pTag{"p", body}; - body += "Display control - " -#ifdef FEATURE_OTA - "Update - " -#endif - "Settings - " - "String Settings - " - "New Settings - " - "Dump NVS"; - } - - HtmlTag divTag{"div", "class=\"form-table\"", body}; - stringSettings.executeForEveryCommonSetting([&](std::string_view key, const auto &value){ - HtmlTag formTag{"form", "class=\"form-table-row\" action=\"/saveStringSettings\" method=\"GET\"", body}; - - { - HtmlTag divTag{"div", "class=\"form-table\"", body}; - HtmlTag bTag{"b", body}; - body += esphttpdutils::htmlentities(key); - } - - { - HtmlTag divTag{"div", "class=\"form-table-cell\"", body}; - body += fmt::format("", - esphttpdutils::htmlentities(key), - esphttpdutils::htmlentities(value)); - } - - { - HtmlTag divTag{"div", "class=\"form-table-cell\"", body}; - HtmlTag buttonTag{"button", "type=\"submit\"", body}; - body += "Save"; - } - }); - } - } - - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, "text/html", body) -} - -esp_err_t webserver_saveStringSettings_handler(httpd_req_t *req) -{ -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } -#endif - - std::string query; - if (auto result = esphttpdutils::webserver_get_query(req)) - query = *result; - else - { - ESP_LOGE(TAG, "%.*s", result.error().size(), result.error().data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", result.error()); - } - - std::string body; - bool success{true}; - - stringSettings.executeForEveryCommonSetting([&](std::string_view key, auto &value){ - char valueBufEncoded[256]; - if (const auto result = httpd_query_key_value(query.data(), key.data(), valueBufEncoded, 256); result != ESP_OK) - { - if (result != ESP_ERR_NOT_FOUND) - { - const auto msg = fmt::format("{}: httpd_query_key_value() failed with {}", key, esp_err_to_name(result)); - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - body += msg; - body += '\n'; - success = false; - } - return; - } - - char valueBuf[257]; - esphttpdutils::urldecode(valueBuf, valueBufEncoded); - - value = valueBuf; - body += fmt::format("{}: applied", key); - body += '\n'; - }); - - if (body.empty()) - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, "text/plain", "nothing changed?!") - - if (settingsPersister.save(stringSettings)) - body += "string settings persisted successfully"; - else - { - body += "error while persisting string settings"; - success = false; - } - - if (success) - { - CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Location", "/stringSettings") - body += "\nOk, continue at /stringSettings"; - } - - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, - req, - success ? esphttpdutils::ResponseStatus::TemporaryRedirect : esphttpdutils::ResponseStatus::BadRequest, - "text/plain", - body) -} -#endif diff --git a/main/webserver_stringsettings.h b/main/webserver_stringsettings.h deleted file mode 100644 index abd4309..0000000 --- a/main/webserver_stringsettings.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -// esp-idf includes -#ifdef FEATURE_WEBSERVER -#include -#endif -#include - -#ifdef FEATURE_WEBSERVER -esp_err_t webserver_stringSettings_handler(httpd_req_t *req); -esp_err_t webserver_saveStringSettings_handler(httpd_req_t *req); -#endif -