Merge pull request #202 from bobbycar-graz/more-configs-in-newsettings
Remove string settings
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -90,17 +90,29 @@ struct CloudTransmitTimeoutAccessor : public RefAccessorSaveSettings<int16_t> {
|
||||
// Time
|
||||
struct TimezoneOffsetAccessor : public virtual espgui::AccessorInterface<int32_t>
|
||||
{
|
||||
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>
|
||||
{
|
||||
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> { espchrono::DayLightSavingMode &getRef() const override { return settings.timeSettings.daylightSavingMode; } };
|
||||
#ifdef FEATURE_NTP
|
||||
struct TimeServerEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.timeSettings.timeServerEnabled; } };
|
||||
struct TimeSyncModeAccessor : public RefAccessorSaveSettings<sntp_sync_mode_t> { sntp_sync_mode_t &getRef() const override { return settings.timeSettings.timeSyncMode; } };
|
||||
struct TimeServerEnabledAccessor : public virtual espgui::AccessorInterface<bool>
|
||||
{
|
||||
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>
|
||||
{
|
||||
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>
|
||||
{
|
||||
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
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
#include "buildserver.h"
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <cpputils.h>
|
||||
#include <cleanuphelper.h>
|
||||
// esp-idf
|
||||
#include "esp_http_client.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <asynchttprequest.h>
|
||||
#include <delayedconstruction.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <cpputils.h>
|
||||
#include <cleanuphelper.h>
|
||||
#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<std::string>());
|
||||
url_for_hashes = fmt::format("{}{}", stringSettings.otaServerUrl, doc["url"].as<std::string>());
|
||||
url_for_latest = fmt::format("{}{}", configs.otaServerUrl.value, doc["latest"].as<std::string>());
|
||||
url_for_hashes = fmt::format("{}{}", configs.otaServerUrl.value, doc["url"].as<std::string>());
|
||||
parsing_finished = true;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "icons/back.h"
|
||||
#include "icons/reboot.h"
|
||||
#include "utils.h"
|
||||
#include "newsettings.h"
|
||||
|
||||
#define ERR_MESSAGE(text) \
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<text>, DefaultFont, StaticColor<TFT_RED>, 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()
|
||||
|
@ -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())
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ SelectBuildMenu::SelectBuildMenu()
|
||||
MESSAGE(TEXT_OTA_NOBUILDSERVERAVAILABLE);
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<OtaMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||
}
|
||||
else if (stringSettings.otaServerUrl.empty())
|
||||
else if (configs.otaServerUrl.value.empty())
|
||||
{
|
||||
MESSAGE(TEXT_OTA_NOBUILDSERVERSELECTED);
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<OtaMenu>, 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<VersionMenuItem<TFT_WHITE>>();
|
||||
|
@ -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
|
||||
}
|
||||
};
|
||||
|
@ -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<uint16_t>(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<uint16_t>(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 = "-";
|
||||
|
@ -1,4 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <string>
|
||||
|
||||
#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
|
||||
|
@ -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<CRGB, 8> ledstrip_custom_colors;
|
||||
|
@ -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<CRGB, 8> ledstrip_custom_colors;
|
||||
|
@ -1,9 +1,5 @@
|
||||
constexpr const char * const TAG = "BOBBY";
|
||||
|
||||
#ifndef OTA_USERNAME
|
||||
#error No OTA username!
|
||||
#endif
|
||||
|
||||
// system includes
|
||||
#include <cstdio>
|
||||
|
||||
@ -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())
|
||||
{
|
||||
|
@ -7,12 +7,17 @@
|
||||
#include <array>
|
||||
#include <optional>
|
||||
|
||||
// esp-idf includes
|
||||
#include <esp_sntp.h>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <fmt/core.h>
|
||||
#include <configmanager.h>
|
||||
#include <configconstraints_base.h>
|
||||
#include <configconstraints_espchrono.h>
|
||||
#include <configwrapper.h>
|
||||
#include <espwifiutils.h>
|
||||
#include <espchrono.h>
|
||||
#include <makearray.h>
|
||||
|
||||
using namespace espconfig;
|
||||
@ -61,6 +66,18 @@ public:
|
||||
ConfigWrapper<std::string> doorToken;
|
||||
};
|
||||
|
||||
class ConfiguredOtaServer
|
||||
{
|
||||
public:
|
||||
ConfiguredOtaServer(const char *nameKey, const char *urlKey) :
|
||||
name{std::string{}, DoReset, {}, nameKey },
|
||||
url {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, urlKey }
|
||||
{}
|
||||
|
||||
ConfigWrapper<std::string> name;
|
||||
ConfigWrapper<std::string> url;
|
||||
};
|
||||
|
||||
class ConfigContainer
|
||||
{
|
||||
using mac_t = wifi_stack::mac_t;
|
||||
@ -90,6 +107,13 @@ public:
|
||||
ConfigWrapper<uint8_t> wifiApChannel {1, DoReset, {}, "wifiApChannel" };
|
||||
ConfigWrapper<wifi_auth_mode_t> wifiApAuthmode{WIFI_AUTH_WPA2_PSK, DoReset, {}, "wifiApAuthmode" };
|
||||
|
||||
ConfigWrapper<bool> timeServerEnabled {false, DoReset, {}, "timeServerEnabl" };
|
||||
ConfigWrapper<std::string> timeServer {"europe.pool.ntp.org", NoReset, StringMaxSize<64>, "timeServer" };
|
||||
ConfigWrapper<sntp_sync_mode_t> timeSyncMode {SNTP_SYNC_MODE_IMMED, NoReset, {}, "timeSyncMode" };
|
||||
ConfigWrapper<espchrono::milliseconds32> timeSyncInterval{espchrono::milliseconds32{CONFIG_LWIP_SNTP_UPDATE_DELAY}, NoReset, MinTimeSyncInterval, "timeSyncInterva" };
|
||||
ConfigWrapper<espchrono::minutes32> timezoneOffset{espchrono::minutes32{60}, DoReset, {}, "timezoneOffset" }; // MinMaxValue<minutes32, -1440m, 1440m>
|
||||
ConfigWrapper<espchrono::DayLightSavingMode>timeDst{espchrono::DayLightSavingMode::EuropeanSummerTime, DoReset, {}, "time_dst" };
|
||||
|
||||
ConfigWrapper<bool> canBusResetOnError {false, DoReset, {}, "canBusRstErr" };
|
||||
|
||||
std::array<WirelessDoorsConfig, 5> wireless_door_configs {
|
||||
@ -110,8 +134,21 @@ public:
|
||||
|
||||
ConfigWrapper<std::string> cloudUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "cloudUrl" };
|
||||
ConfigWrapper<std::string> udpCloudHost {std::string{}, DoReset, {}, "udpCloudHost" };
|
||||
ConfigWrapper<std::string> otaUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaUrl" };
|
||||
|
||||
ConfigWrapper<std::string> otaUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaUrl" };
|
||||
ConfigWrapper<std::string> otaUsername {std::string{}, DoReset, {}, "otaUsername" };
|
||||
ConfigWrapper<std::string> otaServerUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaServerUrl" };
|
||||
ConfigWrapper<std::string> otaServerBranch {std::string{}, DoReset, {}, "otaServerBranch" };
|
||||
std::array<ConfiguredOtaServer, 5> otaServers {
|
||||
ConfiguredOtaServer { "otaName0", "otaUrl0" },
|
||||
ConfiguredOtaServer { "otaName1", "otaUrl1" },
|
||||
ConfiguredOtaServer { "otaName2", "otaUrl2" },
|
||||
ConfiguredOtaServer { "otaName3", "otaUrl3" },
|
||||
ConfiguredOtaServer { "otaName4", "otaUrl4" }
|
||||
};
|
||||
|
||||
ConfigWrapper<bool> dns_announce_enabled{true, DoReset, {}, "dnsAnnounceEnab" };
|
||||
ConfigWrapper<std::string> dns_announce_key {std::string{}, DoReset, {}, "dnsAnnounceKey" };
|
||||
ConfigWrapper<std::string> 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<typename T>
|
||||
|
@ -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, 5> {
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
// local includes
|
||||
#include "globals.h"
|
||||
#include "newsettings.h"
|
||||
|
||||
namespace qrimport {
|
||||
|
||||
@ -109,7 +110,7 @@ tl::expected<void, std::string> 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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 &settings);
|
||||
template bool SettingsPersister::load<StringSettings>(StringSettings &settings);
|
||||
|
||||
template<typename T> struct nvsSetterHelper;
|
||||
template<> struct nvsSetterHelper<int8_t> { static constexpr auto nvs_set = &nvs_set_i8; };
|
||||
@ -455,7 +453,6 @@ bool SettingsPersister::save(T &settings)
|
||||
}
|
||||
|
||||
template bool SettingsPersister::save<Settings>(Settings &settings);
|
||||
template bool SettingsPersister::save<StringSettings>(StringSettings &settings);
|
||||
|
||||
std::optional<uint8_t> SettingsPersister::currentlyOpenProfileIndex() const
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -1,75 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
struct StringSettings
|
||||
{
|
||||
#ifdef FEATURE_NTP
|
||||
std::string timeServer;
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
void executeForEveryCommonSetting(T &&callable);
|
||||
|
||||
template<typename T>
|
||||
void executeForEveryProfileSetting(T &&callable);
|
||||
|
||||
#ifdef FEATURE_OTA
|
||||
struct ConfiguredOtaServer {
|
||||
std::string name;
|
||||
std::string url;
|
||||
};
|
||||
|
||||
std::array<ConfiguredOtaServer, 5> otaServers;
|
||||
std::string otaServerUrl;
|
||||
#endif
|
||||
#ifdef FEATURE_DNS_NS
|
||||
std::string dns_key;
|
||||
#endif
|
||||
#ifdef FEATURE_OTA
|
||||
std::string otaServerBranch;
|
||||
#endif
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
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<typename T>
|
||||
void StringSettings::executeForEveryProfileSetting(T &&callable)
|
||||
{
|
||||
}
|
@ -11,12 +11,12 @@
|
||||
#include <espstrutils.h>
|
||||
|
||||
// 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<std::chrono::seconds>(now.time_since_epoch()).count(), time_valid(now) ? "":" (probably invalid)");
|
||||
const auto seconds = std::chrono::floor<std::chrono::seconds>(now.time_since_epoch());
|
||||
|
||||
timeval ts {
|
||||
.tv_sec = (long int)seconds.count(),
|
||||
.tv_usec = (long int)std::chrono::floor<std::chrono::microseconds>(now.time_since_epoch() - seconds).count()
|
||||
};
|
||||
timezone tz {
|
||||
.tz_minuteswest = 0,
|
||||
.tz_dsttime = 0
|
||||
};
|
||||
settimeofday(&ts, &tz);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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<std::chrono::seconds>(now.time_since_epoch()).count(), time_valid(now) ? "":" (probably invalid)");
|
||||
const auto seconds = std::chrono::floor<std::chrono::seconds>(now.time_since_epoch());
|
||||
|
||||
timeval ts {
|
||||
.tv_sec = (long int)seconds.count(),
|
||||
.tv_usec = (long int)std::chrono::floor<std::chrono::microseconds>(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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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 },
|
||||
|
@ -184,7 +184,6 @@ esp_err_t webserver_root_handler(httpd_req_t *req)
|
||||
#endif
|
||||
|
||||
"<a href=\"/settings\">Settings</a> - "
|
||||
"<a href=\"/stringSettings\">String Settings</a> - "
|
||||
"<a href=\"/newSettings\">New Settings</a> - "
|
||||
"<a href=\"/dumpnvs\">Dump NVS</a>";
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -169,7 +169,6 @@ esp_err_t webserver_newSettings_handler(httpd_req_t *req)
|
||||
"<a href=\"/ota\">Update</a> - "
|
||||
#endif
|
||||
"<a href=\"/settings\">Settings</a> - "
|
||||
"<a href=\"/stringSettings\">String Settings</a> - "
|
||||
"<b>New Settings</b> - "
|
||||
"<a href=\"/dumpnvs\">Dump NVS</a>";
|
||||
}
|
||||
|
@ -209,7 +209,6 @@ esp_err_t webserver_ota_handler(httpd_req_t *req)
|
||||
body += "<a href=\"/\">Display control</a> - "
|
||||
"<b>Update</b> - "
|
||||
"<a href=\"/settings\">Settings</a> - "
|
||||
"<a href=\"/stringSettings\">String Settings</a> - "
|
||||
"<a href=\"/newSettings\">New Settings</a> - "
|
||||
"<a href=\"/dumpnvs\">Dump NVS</a>";
|
||||
}
|
||||
|
@ -146,7 +146,6 @@ esp_err_t webserver_settings_handler(httpd_req_t *req)
|
||||
"<a href=\"/ota\">Update</a> - "
|
||||
#endif
|
||||
"<b>Settings</b> - "
|
||||
"<a href=\"/stringSettings\">String Settings</a> - "
|
||||
"<a href=\"/newSettings\">New Settings</a> - "
|
||||
"<a href=\"/dumpnvs\">Dump NVS</a>";
|
||||
}
|
||||
|
@ -1,191 +0,0 @@
|
||||
#include "webserver_stringsettings.h"
|
||||
|
||||
// esp-idf includes
|
||||
#ifdef FEATURE_WEBSERVER
|
||||
#include <esp_http_server.h>
|
||||
#endif
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <htmlbuilder.h>
|
||||
#include <fmt/core.h>
|
||||
#include <espcppmacros.h>
|
||||
#include <esphttpdutils.h>
|
||||
#include <lockhelper.h>
|
||||
#include <tickchrono.h>
|
||||
|
||||
// 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<espcpputils::ticks>(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 += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\" />";
|
||||
|
||||
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 += "<a href=\"/\">Display control</a> - "
|
||||
#ifdef FEATURE_OTA
|
||||
"<a href=\"/ota\">Update</a> - "
|
||||
#endif
|
||||
"<a href=\"/settings\">Settings</a> - "
|
||||
"<b>String Settings</b> - "
|
||||
"<a href=\"/newSettings\">New Settings</a> - "
|
||||
"<a href=\"/dumpnvs\">Dump NVS</a>";
|
||||
}
|
||||
|
||||
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("<input type=\"text\" name=\"{}\" value=\"{}\" />",
|
||||
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<espcpputils::ticks>(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
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// esp-idf includes
|
||||
#ifdef FEATURE_WEBSERVER
|
||||
#include <esp_http_server.h>
|
||||
#endif
|
||||
#include <esp_err.h>
|
||||
|
||||
#ifdef FEATURE_WEBSERVER
|
||||
esp_err_t webserver_stringSettings_handler(httpd_req_t *req);
|
||||
esp_err_t webserver_saveStringSettings_handler(httpd_req_t *req);
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user