Skip to content

Commit

Permalink
Add wifi RPCs to ESP32 all-clusters app
Browse files Browse the repository at this point in the history
Add the ability to optionally include the RPCs into the all-clusters
app for ESP32. This includes the services for Button, Device, and
Wifi.
  • Loading branch information
Rob Oliver committed Jul 26, 2021
1 parent b343408 commit 294c969
Show file tree
Hide file tree
Showing 7 changed files with 524 additions and 2 deletions.
19 changes: 18 additions & 1 deletion examples/all-clusters-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,24 @@ elseif(${IDF_TARGET} STREQUAL "esp32c3")
endif()

project(chip-all-clusters-app)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++14;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" 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)
pw_set_backend(pw_log pw_log_basic)
pw_set_backend(pw_assert pw_assert_log)
pw_set_backend(pw_sys_io pw_sys_io.esp32)

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 INTERFACE_COMPILE_OPTIONS)
list(REMOVE_ITEM _target_cxx_flags $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>)
list(APPEND _target_cxx_flags $<$<COMPILE_LANGUAGE:CXX>:-std=gnu++17>)
set_target_properties(pw_build.cpp17 PROPERTIES INTERFACE_COMPILE_OPTIONS "${_target_cxx_flags}")
endif(CONFIG_ENABLE_PW_RPC)
24 changes: 24 additions & 0 deletions examples/all-clusters-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,27 @@ If you wish to see the actual effect of the commands on `ESP32-DevKitC`,
`ESP32-WROVER-KIT_V4.1`, you will have to connect an external LED to GPIO
`STATUS_LED_GPIO_NUM`. For `ESP32C3-DevKitM`, the on-board LED will show the
actual effect of the commands.

## Using the RPC console

Enable RPCs in the build using menuconfig:

$ idf.py menuconfig

Enable the RPC library:

Component config → CHIP Core → General Options → Enable Pigweed PRC library

After flashing a build with RPCs enabled you can use the rpc console to send
commands to the device.

Build or install the [rpc console](../../common/pigweed/rpc_console/README.md)

Start the console

python -m chip_rpc.console --device /dev/ttyUSB0

From within the console you can then invoke rpcs:

rpcs.chip.rpc.Wifi.Connect(ssid=b"MySSID", secret=b"MyPASSWORD")
rpcs.chip.rpc.Wifi.GetIP6Address()
87 changes: 86 additions & 1 deletion examples/all-clusters-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ set(SRC_DIRS_LIST
#${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ias-zone-client
)

if (CONFIG_ENABLE_PW_RPC)
# Append additional directories for RPC build
set(PRIV_INCLUDE_DIRS_LIST "${PRIV_INCLUDE_DIRS_LIST}"
"${CMAKE_SOURCE_DIR}/../../platform/esp32/pw_sys_io/public"
"${CMAKE_SOURCE_DIR}/../../common/pigweed"
"${CMAKE_SOURCE_DIR}/../../common/pigweed/esp32"
"${CMAKE_SOURCE_DIR}/../../../src/lib/support"
"${IDF_PATH}/components/freertos/include/freertos"
)
set(SRC_DIRS_LIST "${SRC_DIRS_LIST}"
"${CMAKE_SOURCE_DIR}/../../platform/esp32"
"${CMAKE_SOURCE_DIR}/../../common/pigweed"
"${CMAKE_SOURCE_DIR}/../../common/pigweed/esp32"
)
endif (CONFIG_ENABLE_PW_RPC)

if(("${CONFIG_DEVICE_TYPE_ESP32_DEVKITC}" STREQUAL "y") OR ("${CONFIG_DEVICE_TYPE_ESP32_C3_DEVKITM}" STREQUAL "y"))
list(APPEND PRIV_INCLUDE_DIRS_LIST
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/screen-framework/include")
Expand All @@ -89,5 +105,74 @@ idf_component_register(PRIV_INCLUDE_DIRS ${PRIV_INCLUDE_DIRS_LIST}
SRC_DIRS ${SRC_DIRS_LIST}
PRIV_REQUIRES ${PRIV_REQUIRES_LIST})

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 14)
set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DLWIP_IPV6_SCOPES=0" "-DCHIP_HAVE_CONFIG_H")

if (CONFIG_ENABLE_PW_RPC)

idf_component_get_property(chip_lib chip COMPONENT_LIB)

set(WRAP_FUNCTIONS esp_log_write)
target_link_libraries(${chip_lib} INTERFACE "-Wl,--wrap=${WRAP_FUNCTIONS}")

get_filename_component(CHIP_ROOT ../third_party/connectedhomeip REALPATH)

set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")
include(${PIGWEED_ROOT}/pw_build/pigweed.cmake)
include(${PIGWEED_ROOT}/pw_protobuf_compiler/proto.cmake)
set(dir_pw_third_party_nanopb "${CHIP_ROOT}/third_party/nanopb/repo" CACHE STRING "" FORCE)

pw_proto_library(button_service
SOURCES
${CHIP_ROOT}/examples/common/pigweed/protos/button_service.proto
PREFIX
button_service
STRIP_PREFIX
${CHIP_ROOT}/examples/common/pigweed/protos
DEPS
pw_protobuf.common_protos
)

pw_proto_library(device_service
SOURCES
${CHIP_ROOT}/examples/common/pigweed/protos/device_service.proto
INPUTS
${CHIP_ROOT}/examples/common/pigweed/protos/device_service.options
PREFIX
device_service
STRIP_PREFIX
${CHIP_ROOT}/examples/common/pigweed/protos
DEPS
pw_protobuf.common_protos
)

pw_proto_library(wifi_service
SOURCES
${CHIP_ROOT}/examples/ipv6only-app/common/wifi_service/wifi_service.proto
INPUTS
${CHIP_ROOT}/examples/ipv6only-app/common/wifi_service/wifi_service.options
PREFIX
wifi_service
DEPS
pw_protobuf.common_protos
STRIP_PREFIX
${CHIP_ROOT}/examples/ipv6only-app/common/wifi_service
)

target_link_libraries(${COMPONENT_LIB} PUBLIC
button_service.nanopb_rpc
device_service.nanopb_rpc
wifi_service.nanopb_rpc
pw_checksum
pw_hdlc
pw_log
pw_rpc.server
)

set_property(TARGET ${chip_lib} APPEND PROPERTY LINK_LIBRARIES ${COMPONENT_LIB})
target_include_directories(${chip_lib} PUBLIC
"$<TARGET_FILE_DIR:${chip_lib}>/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/nanopb_rpc"
"$<TARGET_FILE_DIR:${chip_lib}>/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/nanopb"
"$<TARGET_FILE_DIR:${chip_lib}>/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/pwpb")

endif (CONFIG_ENABLE_PW_RPC)
34 changes: 34 additions & 0 deletions examples/all-clusters-app/esp32/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,37 @@ menu "Demo"


endmenu

menu "PW RPC Debug channel"
config EXAMPLE_UART_PORT_NUM
int "UART port number"
range 0 2 if IDF_TARGET_ESP32
default 0 if IDF_TARGET_ESP32
help
UART communication port number for the example.
See UART documentation for available port numbers.

config EXAMPLE_UART_BAUD_RATE
int "UART communication speed"
range 1200 115200
default 115200
help
UART communication speed for Modbus example.

config EXAMPLE_UART_RXD
int "UART RXD pin number"
range 0 34 if IDF_TARGET_ESP32
default 3
help
GPIO number for UART RX pin. See UART documentation for more information
about available pin numbers for UART.

config EXAMPLE_UART_TXD
int "UART TXD pin number"
range 0 34 if IDF_TARGET_ESP32
default 1
help
GPIO number for UART TX pin. See UART documentation for more information
about available pin numbers for UART.

endmenu
Loading

0 comments on commit 294c969

Please sign in to comment.