diff --git a/components/TFT_eSPI b/components/TFT_eSPI index b6f9d19..5b450e3 160000 --- a/components/TFT_eSPI +++ b/components/TFT_eSPI @@ -1 +1 @@ -Subproject commit b6f9d1934956d9054c0af8d021ef522844a81744 +Subproject commit 5b450e3992c7a36f9789b75e4464d9b434d72375 diff --git a/components/arduino-esp32 b/components/arduino-esp32 index a84e053..8e447f5 160000 --- a/components/arduino-esp32 +++ b/components/arduino-esp32 @@ -1 +1 @@ -Subproject commit a84e0538ff20f1fbcd20fb47c836a67557677d89 +Subproject commit 8e447f5cd5808a07fc94376596c34142e242246e diff --git a/components/cpputils b/components/cpputils index faeacdc..b60122f 160000 --- a/components/cpputils +++ b/components/cpputils @@ -1 +1 @@ -Subproject commit faeacdcfbfcfcf0804d64d839eb5ee14a5d84c35 +Subproject commit b60122ff4a19f821b2ebc2080a9fe7aae3febc83 diff --git a/components/espcpputils b/components/espcpputils index 1ef4a9e..a6ed293 160000 --- a/components/espcpputils +++ b/components/espcpputils @@ -1 +1 @@ -Subproject commit 1ef4a9ea561947fa327c59e54a0cef79f6817c46 +Subproject commit a6ed293eab7540357919c64e9fa1f39b2fa2513c diff --git a/components/esphttpdutils b/components/esphttpdutils index a787113..4ebd651 160000 --- a/components/esphttpdutils +++ b/components/esphttpdutils @@ -1 +1 @@ -Subproject commit a78711317ba4a5d5ee0ebf9e047a3609919ef898 +Subproject commit 4ebd651a70a4fddd40b1bcf2fab5194639629276 diff --git a/components/espwifistack b/components/espwifistack index 717d877..9d134d9 160000 --- a/components/espwifistack +++ b/components/espwifistack @@ -1 +1 @@ -Subproject commit 717d877a44056c51e4a3ab777c4279c3d7a2e220 +Subproject commit 9d134d9f6c90a3ba15a3ac84dd9cc42356af437a diff --git a/config_feedc0de.cmake b/config_feedc0de.cmake index e5c5aa9..7a0382c 100644 --- a/config_feedc0de.cmake +++ b/config_feedc0de.cmake @@ -79,4 +79,5 @@ add_definitions( -DPINS_LEDBACKLIGHT=23 -DLEDBACKLIGHT_INVERTED -DFEATURE_GARAGE + -DFEATURE_NTP ) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 22319d6..710673b 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -35,6 +35,7 @@ set(headers bmsutils.h changevaluedisplay_bluetoothmode.h changevaluedisplay_bool.h + changevaluedisplay_sntp_sync_mode_t.h changevaluedisplay_daylightsavingmode.h changevaluedisplay_larsmmode_mode.h changevaluedisplay_unifiedmodelmode.h diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index bdfebab..5d0115b 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -1,5 +1,6 @@ #pragma once +// local includes #include "globals.h" #include "accessorinterface.h" #include "utils.h" @@ -47,8 +48,21 @@ struct CloudEnabledAccessor : public RefAccessorSaveSettings { bool &getRe struct CloudTransmitTimeoutAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.cloudSettings.cloudTransmitTimeout; } }; #endif -struct TimezoneOffsetAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.timeSettings.timezoneOffset; } }; +struct TimezoneOffsetAccessor : public virtual AccessorInterface +{ + int32_t getValue() const override { return settings.timeSettings.timezoneOffset.count(); } + void setValue(int32_t value) override { settings.timeSettings.timezoneOffset = espchrono::minutes32{value}; saveSettings(); } +}; 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 TimeSyncIntervalAccessor : public virtual AccessorInterface +{ + int32_t getValue() const override { return settings.timeSettings.timeSyncInterval.count(); } + void setValue(int32_t value) override { settings.timeSettings.timeSyncInterval = espchrono::milliseconds32{value}; saveSettings(); } +}; +#endif struct FrontLeftEnabledAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.controllerHardware.enableFrontLeft; } }; struct FrontRightEnabledAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.controllerHardware.enableFrontRight; } }; diff --git a/main/changevaluedisplay.h b/main/changevaluedisplay.h index b36f6f4..2463108 100644 --- a/main/changevaluedisplay.h +++ b/main/changevaluedisplay.h @@ -155,6 +155,9 @@ void ChangeValueDisplay::confirm() #ifdef FEATURE_BLUETOOTH #include "changevaluedisplay_bluetoothmode.h" #endif +#ifdef FEATURE_NTP +#include "changevaluedisplay_sntp_sync_mode_t.h" +#endif #include "changevaluedisplay_controlmode.h" #include "changevaluedisplay_controltype.h" #include "changevaluedisplay_daylightsavingmode.h" diff --git a/main/changevaluedisplay_sntp_sync_mode_t.h b/main/changevaluedisplay_sntp_sync_mode_t.h new file mode 100644 index 0000000..c9925ee --- /dev/null +++ b/main/changevaluedisplay_sntp_sync_mode_t.h @@ -0,0 +1,50 @@ +#pragma once + +// esp-idf includes +#include + +// local includes +#include "changevaluedisplay.h" +#include "menudisplay.h" +#include "utils.h" +#include "actions/setvalueaction.h" +#include "actions/backproxyaction.h" +#include "icons/back.h" +#include "texts.h" + +namespace { +template<> +class ChangeValueDisplay : + public MenuDisplay, + public virtual AccessorInterface, + public virtual ActionInterface +{ + using Base = MenuDisplay; + +public: + ChangeValueDisplay(); + + void start() override; +}; + +ChangeValueDisplay::ChangeValueDisplay() +{ + constructMenuItem, StaticText>>(SNTP_SYNC_MODE_IMMED, *this, *this); + constructMenuItem, StaticText>>(SNTP_SYNC_MODE_SMOOTH, *this, *this); + constructMenuItem, StaticMenuItemIcon<&icons::back>>>(*this); +} + +void ChangeValueDisplay::start() +{ + Base::start(); + + switch (const auto value = getValue()) + { + case SNTP_SYNC_MODE_IMMED: setSelectedIndex(0); break; + case SNTP_SYNC_MODE_SMOOTH: setSelectedIndex(1); break; + default: + ESP_LOGW("BOBBY", "Unknown sntp_sync_mode_t: %i", int(value)); + setSelectedIndex(2); + } +} +} diff --git a/main/displays/menus/timesettingsmenu.h b/main/displays/menus/timesettingsmenu.h index fd81cb4..767f34c 100644 --- a/main/displays/menus/timesettingsmenu.h +++ b/main/displays/menus/timesettingsmenu.h @@ -7,10 +7,13 @@ // local includes #include "menudisplay.h" #include "utils.h" +#include "actions/toggleboolaction.h" #include "actions/switchscreenaction.h" +#include "checkboxicon.h" #include "icons/back.h" #include "texts.h" #include "accessors/settingsaccessors.h" +#include "espstrutils.h" // forward declares namespace { @@ -19,20 +22,14 @@ class TimeSettingsMenu; } // namespace namespace { -class CurrentUtcDateTime : public virtual TextInterface -{ -public: - std::string text() const override { return fmt::format("utc: {}", espchrono::toString(espchrono::toDateTime(espchrono::utc_clock::now()))); } -}; +class CurrentUtcDateTimeText : public virtual TextInterface { public: + std::string text() const override { return fmt::format("utc: {}", espchrono::toString(espchrono::toDateTime(espchrono::utc_clock::now()))); }}; -class CurrentLocalDateTime : public virtual TextInterface -{ -public: - std::string text() const override { return fmt::format("local: {}", espchrono::toString(espchrono::toDateTime(espchrono::local_clock::now()))); } -}; +class CurrentLocalDateTimeText : public virtual TextInterface { public: + std::string text() const override { return fmt::format("local: {}", espchrono::toString(espchrono::toDateTime(espchrono::local_clock::now()))); }}; using TimezoneOffsetChangeDisplay = makeComponent< - ChangeValueDisplay, + ChangeValueDisplay, StaticText, TimezoneOffsetAccessor, BackActionInterface>, @@ -47,6 +44,27 @@ using DaylightSavingModeChangeDisplay = makeComponent< SwitchScreenAction >; +#ifdef FEATURE_NTP +using TimeSyncModeChangeDisplay = makeComponent< + ChangeValueDisplay, + StaticText, + TimeSyncModeAccessor, + BackActionInterface>, + SwitchScreenAction +>; + +using TimeSyncIntervalChangeDisplay = makeComponent< + ChangeValueDisplay, + StaticText, + TimeSyncIntervalAccessor, + BackActionInterface>, + SwitchScreenAction +>; + +class NtpSyncStatusText : public virtual TextInterface { public: + std::string text() const override { return fmt::format("Status: {}", espcpputils::toString(sntp_get_sync_status())); }}; +#endif + class TimeSettingsMenu : public MenuDisplay, public StaticText, @@ -55,10 +73,17 @@ class TimeSettingsMenu : public: TimeSettingsMenu() { - constructMenuItem, DummyAction>>(); - constructMenuItem, DummyAction>>(); + constructMenuItem, DummyAction>>(); + constructMenuItem, DummyAction>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); +#ifdef FEATURE_NTP + constructMenuItem, ToggleBoolAction, CheckboxIcon, TimeServerEnabledAccessor>>(); + constructMenuItem, DummyAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem>(); +#endif constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); } }; diff --git a/main/dpad3wire.h b/main/dpad3wire.h index 1918419..a507729 100644 --- a/main/dpad3wire.h +++ b/main/dpad3wire.h @@ -1,9 +1,13 @@ #pragma once +// Arduino includes #include +// 3rdparty lib includes #include +#include +// local includes #include "dpad.h" #include "buttons.h" #include "types.h" @@ -38,7 +42,7 @@ dpad::State Helper::read() pinMode(IN1, INPUT_PULLUP); pinMode(IN2, INPUT_PULLUP); - delay(1); + vPortYield(); const bool result0 = digitalRead(IN1)==LOW; const bool result1 = digitalRead(IN2)==LOW; @@ -48,7 +52,7 @@ dpad::State Helper::read() pinMode(IN1, INPUT_PULLDOWN); pinMode(IN2, INPUT_PULLDOWN); - delay(1); + vPortYield(); const bool result2 = digitalRead(IN1); const bool result3 = digitalRead(IN2); diff --git a/main/dpad5wire.h b/main/dpad5wire.h index 689a6e9..363bf88 100644 --- a/main/dpad5wire.h +++ b/main/dpad5wire.h @@ -1,11 +1,16 @@ #pragma once +// system includes #include +// Arduino includes #include +// 3rdparty lib includes #include +#include +// local includes #include "buttons.h" #include "types.h" @@ -73,7 +78,7 @@ State Helper::read() pinMode(IN3, INPUT_PULLUP); pinMode(IN4, INPUT_PULLUP); - delay(1); + vPortYield(); result[0] = digitalRead(IN1)==LOW; result[1] = digitalRead(IN2)==LOW; @@ -87,7 +92,7 @@ State Helper::read() pinMode(IN3, INPUT_PULLDOWN); pinMode(IN4, INPUT_PULLDOWN); - delay(1); + vPortYield(); result[4] = digitalRead(IN1); result[5] = digitalRead(IN2); diff --git a/main/main.cpp b/main/main.cpp index 2b960dc..770a915 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -151,6 +151,9 @@ std::optional lastBleUpdate; #ifdef FEATURE_CLOUD std::optional lastCloudUpdate; #endif +#ifdef FEATURE_NTP +std::optional lastNtpUpdate; +#endif } extern "C" void app_main() @@ -297,6 +300,11 @@ extern "C" void app_main() initCloud(); #endif +#ifdef FEATURE_NTP + bootLabel.redraw("time"); + initTime(); +#endif + bootLabel.redraw("switchScreen"); #if defined(FEATURE_DPAD_5WIRESW) && defined(DPAD_5WIRESW_DEBUG) @@ -427,6 +435,15 @@ extern "C" void app_main() } #endif +#ifdef FEATURE_NTP + if (!lastNtpUpdate || now - *lastNtpUpdate >= 100ms) + { + updateTime(); + + lastNtpUpdate = now; + } +#endif + #ifdef FEATURE_WEBSERVER handleWebserver(); #endif diff --git a/main/presets.h b/main/presets.h index 93712d3..8c257b9 100644 --- a/main/presets.h +++ b/main/presets.h @@ -1,5 +1,11 @@ #pragma once +// esp-idf includes +#ifdef FEATURE_NTP +#include +#include +#endif + // 3rdparty lib includes #include @@ -7,6 +13,8 @@ #include "settings.h" #include "stringsettings.h" +using namespace std::chrono_literals; + namespace presets { constexpr Settings::Limits defaultLimits { .iMotMax = DEFAULT_IMOTMAX, @@ -25,8 +33,13 @@ constexpr Settings::Limits kidsLimits { }; constexpr Settings::TimeSettings defaultTimeSettings { - .timezoneOffset = 60, - .daylightSavingMode = espchrono::DayLightSavingMode::EuropeanSummerTime + .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 { @@ -245,7 +258,10 @@ StringSettings makeDefaultStringSettings() .otaUrl = {}, #endif #ifdef FEATURE_GARAGE - .garageUrl = "http://insecure.brunner.ninja/tor.php", + .garageUrl = {}, +#endif +#ifdef FEATURE_NTP + .timeServer = "europe.pool.ntp.org", #endif }; } diff --git a/main/settings.h b/main/settings.h index 0219943..da6d15c 100644 --- a/main/settings.h +++ b/main/settings.h @@ -6,6 +6,13 @@ // esp-idf includes #include +#ifdef FEATURE_NTP +#include +#include +#endif + +// 3rdparty lib includes +#include // local includes #include "bobbycar-common.h" @@ -54,8 +61,14 @@ struct Settings #endif struct TimeSettings { - int16_t timezoneOffset; + espchrono::minutes32 timezoneOffset; espchrono::DayLightSavingMode daylightSavingMode; + +#ifdef FEATURE_NTP + bool timeServerEnabled; + sntp_sync_mode_t timeSyncMode; + espchrono::milliseconds32 timeSyncInterval; +#endif } timeSettings; struct ControllerHardware { @@ -160,6 +173,11 @@ void Settings::executeForEveryCommonSetting(T &&callable) 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); diff --git a/main/settingspersister.h b/main/settingspersister.h index 6e84400..686fc33 100644 --- a/main/settingspersister.h +++ b/main/settingspersister.h @@ -5,9 +5,13 @@ #include // esp-idf includes +#include #include #include -#include +#ifdef FEATURE_NTP +#include +#include +#endif // 3rdparty lib includes #include @@ -230,6 +234,48 @@ template<> struct nvsGetterHelper { static esp_er *out_value = espchrono::DayLightSavingMode(tempValue); return err; }}; +template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_handle handle, const char* key, espchrono::milliseconds32* out_value) +{ + int32_t tempValue; + esp_err_t err = nvs_get_i32(handle, key, &tempValue); + if (err == ESP_OK) + *out_value = espchrono::milliseconds32(tempValue); + return err; +}}; +template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_handle handle, const char* key, espchrono::seconds32* out_value) +{ + int32_t tempValue; + esp_err_t err = nvs_get_i32(handle, key, &tempValue); + if (err == ESP_OK) + *out_value = espchrono::seconds32(tempValue); + return err; +}}; +template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_handle handle, const char* key, espchrono::minutes32* out_value) +{ + int32_t tempValue; + esp_err_t err = nvs_get_i32(handle, key, &tempValue); + if (err == ESP_OK) + *out_value = espchrono::minutes32(tempValue); + return err; +}}; +template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_handle handle, const char* key, espchrono::hours32* out_value) +{ + int32_t tempValue; + esp_err_t err = nvs_get_i32(handle, key, &tempValue); + if (err == ESP_OK) + *out_value = espchrono::hours32(tempValue); + return err; +}}; +#ifdef FEATURE_NTP +template<> struct nvsGetterHelper { static esp_err_t nvs_get(nvs_handle handle, const char* key, sntp_sync_mode_t* out_value) +{ + uint8_t tempValue; + esp_err_t err = nvs_get_u8(handle, key, &tempValue); + if (err == ESP_OK) + *out_value = sntp_sync_mode_t(tempValue); + return err; +}}; +#endif template bool SettingsPersister::load(T &settings) @@ -317,6 +363,28 @@ template<> struct nvsSetterHelper { static esp_er { return nvs_set_u8(handle, key, uint8_t(value)); }}; +template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_handle handle, const char* key, espchrono::milliseconds32 value) +{ + return nvs_set_i32(handle, key, value.count()); +}}; +template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_handle handle, const char* key, espchrono::seconds32 value) +{ + return nvs_set_i32(handle, key, value.count()); +}}; +template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_handle handle, const char* key, espchrono::minutes32 value) +{ + return nvs_set_i32(handle, key, value.count()); +}}; +template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_handle handle, const char* key, espchrono::hours32 value) +{ + return nvs_set_i32(handle, key, value.count()); +}}; +#ifdef FEATURE_NTP +template<> struct nvsSetterHelper { static esp_err_t nvs_set(nvs_handle handle, const char* key, sntp_sync_mode_t value) +{ + return nvs_set_u8(handle, key, uint8_t(value)); +}}; +#endif template bool SettingsPersister::save(T &settings) diff --git a/main/stringsettings.h b/main/stringsettings.h index 4005687..e3ec0f7 100644 --- a/main/stringsettings.h +++ b/main/stringsettings.h @@ -26,6 +26,10 @@ struct StringSettings std::string garageUrl; #endif +#ifdef FEATURE_NTP + std::string timeServer; +#endif + template void executeForEveryCommonSetting(T &&callable); @@ -69,6 +73,9 @@ void StringSettings::executeForEveryCommonSetting(T &&callable) #ifdef FEATURE_GARAGE callable("garageUrl", garageUrl); #endif +#ifdef FEATURE_NTP + callable("timeServer", timeServer); +#endif } template diff --git a/main/texts.h b/main/texts.h index efe1766..f18ba4e 100644 --- a/main/texts.h +++ b/main/texts.h @@ -332,7 +332,11 @@ constexpr char TEXT_CLOUDSENDRATE[] = "Cloud send rate"; //TimeSettingsMenu //constexpr char TEXT_TIME[] = "Time"; constexpr char TEXT_OFFSET[] = "Offset"; -constexpr char TEXT_DAYLIGHTSAVINGMODE[] = "Daylight Saving Mode"; +constexpr char TEXT_DAYLIGHTSAVINGMODE[] = "Daylight Saving"; +constexpr char TEXT_NTPENABLED[] = "NTP Enabled"; +constexpr char TEXT_NTPSERVER[] = "NTP Server"; +constexpr char TEXT_NTPMODE[] = "NTP Mode"; +constexpr char TEXT_NTPINTERVAL[] = "NTP Interval"; //constexpr char TEXT_BACK[] = "Back"; //ChangeValueDisplay @@ -345,6 +349,11 @@ constexpr char TEXT_TRUE[] = "true"; constexpr char TEXT_FALSE[] = "false"; //constexpr char TEXT_BACK[] = "Back"; +//ChangeValueDisplay +constexpr char TEXT_IMMED[] = "IMMED"; +constexpr char TEXT_SMOOTH[] = "SMOOTH"; +//constexpr char TEXT_BACK[] = "Back"; + //ChangeValueDisplay constexpr char TEXT_OPENMODE[] = "Open mode"; constexpr char TEXT_VOLTAGE[] = "Voltage"; diff --git a/main/time_bobbycar.h b/main/time_bobbycar.h index c5e1215..78ece0f 100644 --- a/main/time_bobbycar.h +++ b/main/time_bobbycar.h @@ -1,7 +1,15 @@ #pragma once +// esp-idf includes +#include +#ifdef FEATURE_NTP +#include +#include +#endif + // 3rdparty lib includes #include +#include // local includes #include "globals.h" @@ -10,3 +18,84 @@ auto espchrono::local_clock::timezone() noexcept -> time_zone { return time_zone{minutes32{settings.timeSettings.timezoneOffset}, settings.timeSettings.daylightSavingMode}; } + +namespace { +#ifdef FEATURE_NTP +void time_sync_notification_cb(struct timeval *tv); + +void initTime() +{ + sntp_setoperatingmode(SNTP_OPMODE_POLL); + static_assert(SNTP_MAX_SERVERS >= 1); + sntp_setservername(0, stringSettings.timeServer.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) + { + ESP_LOGI("BOBBY", "sntp_init() ..."); + sntp_init(); + if (!sntp_enabled()) + { + ESP_LOGE("BOBBY", "sntp_init() failed"); + } + } +} + +void updateTime() +{ + if (bool(sntp_enabled()) != settings.timeSettings.timeServerEnabled) + { + if (settings.timeSettings.timeServerEnabled) + { + ESP_LOGD("BOBBY", "calling sntp_init()..."); + sntp_init(); + ESP_LOGI("BOBBY", "sntp_init() finished"); + } + else + { + ESP_LOGD("BOBBY", "calling sntp_stop()..."); + sntp_stop(); + ESP_LOGI("BOBBY", "sntp_stop() finished"); + } + } + + if (stringSettings.timeServer != sntp_getservername(0)) + { + ESP_LOGD("BOBBY", "calling sntp_getservername() with %s...", stringSettings.timeServer.c_str()); + sntp_setservername(0, stringSettings.timeServer.c_str()); + ESP_LOGI("BOBBY", "sntp_getservername() finished"); + } + + if (settings.timeSettings.timeSyncMode != 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_LOGI("BOBBY", "sntp_set_sync_mode() finished"); + } + + if (settings.timeSettings.timeSyncInterval != 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_LOGI("BOBBY", "sntp_set_sync_interval() finished"); + } +} + +tl::expected time_requestSync() +{ + ESP_LOGI("BOBBY", "called"); + if (!sntp_restart()) + return tl::make_unexpected("sntp_restart() failed"); + return {}; +} + +void time_sync_notification_cb(struct timeval *tv) +{ + if (tv) + ESP_LOGI("BOBBY", "%ld", tv->tv_sec); + else + ESP_LOGI("BOBBY", "nullptr"); +} +#endif +} diff --git a/sdkconfig_feedc0de b/sdkconfig_feedc0de index c07bbd3..df0e790 100644 --- a/sdkconfig_feedc0de +++ b/sdkconfig_feedc0de @@ -167,6 +167,18 @@ CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP_INFO=y CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP=3 # end of Simple Async HTTP Request +# +# espcpputils settings +# +# CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL_NONE is not set +# CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL_ERROR is not set +# CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL_WARN is not set +CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL_INFO=y +# CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL_DEBUG is not set +# CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL_VERBOSE is not set +CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL=3 +# end of espcpputils settings + # # Simple WiFi Stack settings #