From 10126469f1d69a25814337b410c8d5a1cb2591ec Mon Sep 17 00:00:00 2001 From: PSONALl <77670766+PSONALl@users.noreply.github.com> Date: Thu, 4 Jan 2024 21:37:09 +0530 Subject: [PATCH] Create EVSE app with ESP32 (#30949) * EVSE app on esp32 * Restyled by clang-format * Restyled by autopep8 * spelcheck * Address review comments --------- Co-authored-by: PSONALl Co-authored-by: Restyled.io Co-authored-by: Rohit Jadhav Co-authored-by: jamesharrow <93921463+jamesharrow@users.noreply.github.com> --- .../energy-management-app/esp32/.gitignore | 4 + .../esp32/CMakeLists.txt | 87 ++++++ .../energy-management-app/esp32/README.md | 49 ++++ .../esp32/main/CMakeLists.txt | 247 ++++++++++++++++++ .../esp32/main/DeviceCallbacks.cpp | 42 +++ .../esp32/main/Kconfig.projbuild | 187 +++++++++++++ .../esp32/main/idf_component.yml | 2 + .../esp32/main/include/CHIPProjectConfig.h | 47 ++++ .../esp32/main/include/DeviceCallbacks.h | 33 +++ .../energy-management-app/esp32/main/main.cpp | 238 +++++++++++++++++ .../esp32/partitions.csv | 10 + .../esp32/partitions_encrypted.csv | 8 + .../esp32/sdkconfig.defaults | 66 +++++ .../esp32/sdkconfig.defaults.esp32c2 | 22 ++ .../esp32/sdkconfig.defaults.esp32c6 | 67 +++++ .../esp32/sdkconfig.defaults.esp32h2 | 81 ++++++ .../esp32/sdkconfig.optimize.defaults | 95 +++++++ .../esp32/sdkconfig_m5stack.defaults | 71 +++++ .../esp32/sdkconfig_rpc.defaults | 57 ++++ .../esp32/third_party/connectedhomeip | 1 + 20 files changed, 1414 insertions(+) create mode 100644 examples/energy-management-app/esp32/.gitignore create mode 100644 examples/energy-management-app/esp32/CMakeLists.txt create mode 100644 examples/energy-management-app/esp32/README.md create mode 100644 examples/energy-management-app/esp32/main/CMakeLists.txt create mode 100644 examples/energy-management-app/esp32/main/DeviceCallbacks.cpp create mode 100644 examples/energy-management-app/esp32/main/Kconfig.projbuild create mode 100644 examples/energy-management-app/esp32/main/idf_component.yml create mode 100644 examples/energy-management-app/esp32/main/include/CHIPProjectConfig.h create mode 100644 examples/energy-management-app/esp32/main/include/DeviceCallbacks.h create mode 100644 examples/energy-management-app/esp32/main/main.cpp create mode 100644 examples/energy-management-app/esp32/partitions.csv create mode 100644 examples/energy-management-app/esp32/partitions_encrypted.csv create mode 100644 examples/energy-management-app/esp32/sdkconfig.defaults create mode 100644 examples/energy-management-app/esp32/sdkconfig.defaults.esp32c2 create mode 100644 examples/energy-management-app/esp32/sdkconfig.defaults.esp32c6 create mode 100644 examples/energy-management-app/esp32/sdkconfig.defaults.esp32h2 create mode 100644 examples/energy-management-app/esp32/sdkconfig.optimize.defaults create mode 100644 examples/energy-management-app/esp32/sdkconfig_m5stack.defaults create mode 100644 examples/energy-management-app/esp32/sdkconfig_rpc.defaults create mode 120000 examples/energy-management-app/esp32/third_party/connectedhomeip diff --git a/examples/energy-management-app/esp32/.gitignore b/examples/energy-management-app/esp32/.gitignore new file mode 100644 index 00000000000000..601ff1b8e9e01e --- /dev/null +++ b/examples/energy-management-app/esp32/.gitignore @@ -0,0 +1,4 @@ +/build/ +/sdkconfig +/sdkconfig.old +main/insights_auth_key.txt diff --git a/examples/energy-management-app/esp32/CMakeLists.txt b/examples/energy-management-app/esp32/CMakeLists.txt new file mode 100644 index 00000000000000..c9944ab9a39e46 --- /dev/null +++ b/examples/energy-management-app/esp32/CMakeLists.txt @@ -0,0 +1,87 @@ +# +# Copyright (c) 2021-2023 Project CHIP Authors +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# The following lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +set(PROJECT_VER "v1.0") +set(PROJECT_VER_NUMBER 1) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake) + +set(EXTRA_COMPONENT_DIRS + "${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/config/esp32/components" + "${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common" +) + +if(${IDF_TARGET} STREQUAL "esp32") + list(APPEND EXTRA_COMPONENT_DIRS "${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/m5stack-tft/repo/components") +endif() + + +project(chip-energy-management-app) + +# WARNING: This is just an example for using key for decrypting the encrypted OTA image +# Please do not use it as is. +if(CONFIG_ENABLE_ENCRYPTED_OTA) + target_add_binary_data(chip-energy-management-app.elf "esp_image_encryption_key.pem" TEXT) +endif() + +# C++17 is required for RPC build. +idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DCHIP_HAVE_CONFIG_H" APPEND) +idf_build_set_property(C_COMPILE_OPTIONS "-Os" APPEND) +# For the C3, project_include.cmake sets -Wno-format, but does not clear various +# flags that depend on -Wformat +idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security" APPEND) + +# -Wmaybe-uninitialized has too many false positives, including on std::optional +# and chip::Optional. Make it nonfatal. +# +# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635 +idf_build_set_property(COMPILE_OPTIONS "-Wno-error=maybe-uninitialized" APPEND) + +#For the H2, -Werror=uninitialized will cause an error in "src/lib/support/LambdaBridge.h" +idf_build_set_property(COMPILE_OPTIONS "-Wno-error=uninitialized" APPEND) + +flashing_script() + +if (CONFIG_ENABLE_PW_RPC) +get_filename_component(CHIP_ROOT ./third_party/connectedhomeip REALPATH) +include(third_party/connectedhomeip/third_party/pigweed/repo/pw_build/pigweed.cmake) +include($ENV{PW_ROOT}/pw_assert/backend.cmake) +include($ENV{PW_ROOT}/pw_log/backend.cmake) +include($ENV{PW_ROOT}/pw_sys_io/backend.cmake) +include($ENV{PW_ROOT}/pw_trace/backend.cmake) + +pw_set_module_config(pw_rpc_CONFIG pw_rpc.disable_global_mutex_config) + +pw_set_backend(pw_log pw_log_basic) +pw_set_backend(pw_assert.check pw_assert_log.check_backend) +pw_set_backend(pw_assert.assert pw_assert.assert_compatibility_backend) +pw_set_backend(pw_sys_io pw_sys_io.esp32) +pw_set_backend(pw_trace pw_trace_tokenized) + +add_subdirectory(third_party/connectedhomeip/third_party/pigweed/repo) +add_subdirectory(third_party/connectedhomeip/third_party/nanopb/repo) +add_subdirectory(third_party/connectedhomeip/examples/platform/esp32/pw_sys_io) + +get_target_property(_target_cxx_flags pw_build.cpp17._public_config INTERFACE_COMPILE_OPTIONS) +list(REMOVE_ITEM _target_cxx_flags $<$:-std=c++17>) +list(APPEND _target_cxx_flags $<$:-std=gnu++17>) +set_target_properties(pw_build.cpp17._public_config PROPERTIES INTERFACE_COMPILE_OPTIONS "${_target_cxx_flags}") +endif(CONFIG_ENABLE_PW_RPC) diff --git a/examples/energy-management-app/esp32/README.md b/examples/energy-management-app/esp32/README.md new file mode 100644 index 00000000000000..c2fb2bc7a1f63c --- /dev/null +++ b/examples/energy-management-app/esp32/README.md @@ -0,0 +1,49 @@ +# Matter ESP32 Energy Management Example + +This example demonstrates the Matter Electric Vehicle Supply Equipment +application on ESP platforms. + +Please +[setup ESP-IDF and CHIP Environment](../../../docs/guides/esp32/setup_idf_chip.md) +and refer +[building and commissioning](../../../docs/guides/esp32/build_app_and_commission.md) +guides to get started. + +### Enabling ESP-Insights: + +- Before building the app, enable the option: ESP_INSIGHTS_ENABLED through + menuconfig. + +- Create a file named insights_auth_key.txt in the main directory of the + example. + +- Follow the steps + present[here](https://github.com/espressif/esp-insights/blob/main/examples/README.md#set-up-esp-insights-account) + to set up an insights_account and the auth key created while setting it up + will be used in the example. + +- Download the auth key and copy Auth Key to the example + +``` +cp /path/to/auth/key.txt path/to/connectedhomeip/examples/energy-management-app/esp32/main/insights_auth_key.txt +``` + +--- + +- [Cluster Control](#cluster-control) +- [Matter OTA guide](../../../docs/guides/esp32/ota.md) + +--- + +### Cluster Control + +- After successful commissioning, use the Energy Electric Vehicle Supply + Equipment cluster command to disable/enable charging and discharging. + +``` + $./out/debug/chip-tool energyevse disable 1 +``` + +``` + $ ./out/debug/chip-tool energyevse enable-charging 0xFFFFFFFF 6000 32000 1 --timedInteractionTimeoutMs