From 3d47e357d7626103c97d8a9abc3a64ea1f88276a Mon Sep 17 00:00:00 2001 From: Rohit Jadhav <69809379+jadhavrohit924@users.noreply.github.com> Date: Tue, 5 Mar 2024 11:09:37 +0530 Subject: [PATCH] [ESP32] Add sntp support to get real time on esp32 (#32092) * [ESP32] Add sntp support to get real time on esp32 * Address review comments * Did some restructoring to address review comments * Addressed review comments * Again addressed review comments * Restyled by clang-format * Some renaming and error check * Update sntp array to accomodate null terminating charactor --------- Co-authored-by: Restyled.io --- config/esp32/components/chip/Kconfig | 6 ++ .../esp32/main/CMakeLists.txt | 1 + .../energy-management-app/esp32/main/main.cpp | 15 ++- .../esp32/sdkconfig.defaults | 3 + examples/platform/esp32/time/TimeSync.cpp | 102 ++++++++++++++++++ examples/platform/esp32/time/TimeSync.h | 28 +++++ src/platform/ESP32/SystemTimeSupport.cpp | 7 +- 7 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 examples/platform/esp32/time/TimeSync.cpp create mode 100644 examples/platform/esp32/time/TimeSync.h diff --git a/config/esp32/components/chip/Kconfig b/config/esp32/components/chip/Kconfig index b39105d1285fac..589f33b1c70830 100644 --- a/config/esp32/components/chip/Kconfig +++ b/config/esp32/components/chip/Kconfig @@ -271,6 +271,12 @@ menu "CHIP Core" Opens the commissioning window automatically at application boot time if the node is not yet commissioned. + config ENABLE_SNTP_TIME_SYNC + bool "Enable SNTP time synchronization" + default n + help + Enable this option to enable SNTP time synchronization + endmenu # "System Options" menu "Security Options" diff --git a/examples/energy-management-app/esp32/main/CMakeLists.txt b/examples/energy-management-app/esp32/main/CMakeLists.txt index 0c038632b4feab..a38ce499bc1ea5 100644 --- a/examples/energy-management-app/esp32/main/CMakeLists.txt +++ b/examples/energy-management-app/esp32/main/CMakeLists.txt @@ -31,6 +31,7 @@ set(SRC_DIRS_LIST "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/src" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/ota" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/common" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/time" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/shell_extension" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/util" diff --git a/examples/energy-management-app/esp32/main/main.cpp b/examples/energy-management-app/esp32/main/main.cpp index 8132b1ba2f3aff..e61e6cb00cca9b 100644 --- a/examples/energy-management-app/esp32/main/main.cpp +++ b/examples/energy-management-app/esp32/main/main.cpp @@ -22,6 +22,9 @@ #include #include #include +#if CONFIG_ENABLE_SNTP_TIME_SYNC +#include