Skip to content

Commit 704d638

Browse files
authored
Merge pull request #420 from gojimmypi/pr-espressif-component-example-update
Update examples for latest Managed Components
2 parents ecc2ed2 + 8ee033b commit 704d638

33 files changed

Lines changed: 6150 additions & 765 deletions

IDE/Espressif/ESP-IDF/examples/AWS_IoT_MQTT/CMakeLists.txt

Lines changed: 126 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
# wolfSSL Espressif Example Project CMakeLists.txt
1+
# [example]/CMakeLists.txt for Espressif targets
2+
#
3+
# Copyright (C) 2006-2025 wolfSSL Inc.
4+
#
5+
# This file is part of wolfMQTT.
6+
#
7+
# wolfMQTT is free software; you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation; either version 2 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# wolfMQTT is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program; if not, write to the Free Software
19+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
#
221
# v1.0
322
#
423
# The following lines of boilerplate have to be in your project's
@@ -12,13 +31,83 @@ set(WOLFSSL_USER_SETTINGS ON)
1231
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFMQTT_USER_SETTINGS")
1332
set(WOLFMQTT_USER_SETTINGS ON)
1433

34+
# These should typically be set in user_settings.h
1535
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_AWSIOT_EXAMPLE")
1636
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_MQTT_TLS")
1737
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFMQTT_EXTERN_CERT")
1838
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_MAIN_DRIVER")
1939

40+
# Find the user name to search for possible "wolfssl-username"
41+
# Reminder: Windows is %USERNAME%, Linux is $USER
42+
if( "$ENV{USER}" STREQUAL "" ) # the bash user
43+
if( "$ENV{USERNAME}" STREQUAL "" ) # the Windows user
44+
message(STATUS "could not find USER or USERNAME")
45+
else()
46+
# the bash user is not blank, so we'll use it.
47+
set(THIS_USER "$ENV{USERNAME}")
48+
endif()
49+
else()
50+
# the bash user is not blank, so we'll use it.
51+
set(THIS_USER "$ENV{USER}")
52+
endif()
53+
message(STATUS "THIS_USER = ${THIS_USER}")
2054

2155

56+
# CHECK_DUPLICATE_LIBRARIES function
57+
# Parameters:
58+
# RESULT_VAR (output variable)
59+
# KEYWORD (e.g. "wolfssl", "wolfmqtt", etc).
60+
#
61+
# Constructs a list of possible directories based on the keyword.
62+
# Counts the number of existing directories.
63+
# If at least two directories exist, sets RESULT_VAR to TRUE, otherwise FALSE.
64+
# Uses PARENT_SCOPE to return the result to the calling context.
65+
function(CHECK_DUPLICATE_LIBRARIES RESULT_VAR KEYWORD)
66+
set(DIR_LIST
67+
"${CMAKE_CURRENT_LIST_DIR}/components/${KEYWORD}"
68+
"${CMAKE_CURRENT_LIST_DIR}/components/my${KEYWORD}"
69+
"${CMAKE_CURRENT_LIST_DIR}/managed_components/wolfssl__${KEYWORD}"
70+
"${CMAKE_CURRENT_LIST_DIR}/managed_components/gojimmypi__my${KEYWORD}"
71+
"${CMAKE_CURRENT_LIST_DIR}/managed_components/${THIS_USER}__my${KEYWORD}"
72+
"$ENV{IDF_PATH}/components/${KEYWORD}/"
73+
"$ENV{IDF_PATH}/components/esp-${KEYWORD}/"
74+
)
75+
76+
set(EXISTING_COUNT 0)
77+
set(MATCHING_DIRS "") # List to store found directories
78+
79+
foreach(DIR ${DIR_LIST})
80+
file(TO_CMAKE_PATH "${DIR}" DIR) # Normalize paths
81+
message(STATUS "Checking for ${KEYWORD} in ${DIR}")
82+
if(EXISTS "${DIR}")
83+
math(EXPR EXISTING_COUNT "${EXISTING_COUNT} + 1")
84+
list(APPEND MATCHING_DIRS "${DIR}")
85+
message(STATUS "Found: ${DIR}")
86+
endif()
87+
endforeach()
88+
89+
if(EXISTING_COUNT GREATER_EQUAL 2)
90+
set(${RESULT_VAR} TRUE PARENT_SCOPE)
91+
message(STATUS "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
92+
message(STATUS "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
93+
message(STATUS "WARNING: Found duplicate '${KEYWORD}' in")
94+
foreach(DUP_DIR ${MATCHING_DIRS})
95+
message(STATUS " - ${DUP_DIR}")
96+
endforeach()
97+
message(STATUS "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
98+
message(STATUS "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
99+
message(WARNING "WARNING: More than 1 '${KEYWORD}' component directories exist.")
100+
101+
# Append the warning flag to CMAKE_C_FLAGS and propagate it to the parent scope
102+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D${KEYWORD}_MULTI_INSTALL_WARNING")
103+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" PARENT_SCOPE)
104+
else()
105+
set(${RESULT_VAR} FALSE PARENT_SCOPE)
106+
107+
message(STATUS "Confirmed less than two '${KEYWORD}' component directories exist.")
108+
endif()
109+
endfunction()
110+
22111
# The wolfSSL CMake file should be able to find the source code.
23112
# Otherwise, assign an environment variable or set it here:
24113
#
@@ -37,45 +126,53 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_MAIN_DRIVER")
37126
if(WIN32)
38127
# Windows-specific configuration here
39128
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS")
40-
message("Detected Windows")
129+
message(STATUS "Detected Windows")
41130
endif()
42131
if(CMAKE_HOST_UNIX)
43-
message("Detected UNIX")
132+
message(STATUS "Detected UNIX")
44133
endif()
45134
if(APPLE)
46-
message("Detected APPLE")
135+
message(STATUS "Detected APPLE")
47136
endif()
48137
if(CMAKE_HOST_UNIX AND (NOT APPLE) AND EXISTS "/proc/sys/fs/binfmt_misc/WSLInterop")
49138
# Windows-specific configuration here
50139
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WSL")
51-
message("Detected WSL")
140+
message(STATUS "Detected WSL")
52141
endif()
53142
if(CMAKE_HOST_UNIX AND (NOT APPLE) AND (NOT WIN32))
54143
# Windows-specific configuration here
55144
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_LINUX")
56-
message("Detected Linux")
145+
message(STATUS "Detected Linux")
57146
endif()
58147
if(APPLE)
59148
# Windows-specific configuration here
60149
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_APPLE")
61-
message("Detected Apple")
150+
message(STATUS "Detected Apple")
62151
endif()
63152
# End optional WOLFSSL_CMAKE_SYSTEM_NAME
64153

65154
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
66-
set (PROTOCOL_EXAMPLES_DIR $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
155+
# set (PROTOCOL_EXAMPLES_DIR $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
156+
string(REPLACE "\\" "/" PROTOCOL_EXAMPLES_DIR "$ENV{IDF_PATH}/examples/common_components/protocol_examples_common")
67157

68158
if (EXISTS "${PROTOCOL_EXAMPLES_DIR}")
69-
message("Found PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR}")
159+
message(STATUS "Found PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR}")
70160
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
71161
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFOUND_PROTOCOL_EXAMPLES_DIR")
72162
else()
73-
message("NOT FOUND: PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR}")
163+
message(STATUS "NOT FOUND: PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR}")
74164
endif()
75165

76-
# Check that there are not conflicting wolfSSL components
166+
# Check that there are not conflicting wolfSSL components.
77167
# The ESP Registry Component will be in ./managed_components/wolfssl__wolfssl
78168
# The local component wolfSSL directory will be in ./components/wolfssl
169+
message(STATUS "Checking for wolfSSL as Managed Component or not... ${CMAKE_HOME_DIRECTORY}")
170+
message(STATUS "Checking for duplicate components. CMAKE_HOME_DIRECTORY='${CMAKE_HOME_DIRECTORY}'")
171+
CHECK_DUPLICATE_LIBRARIES(DUPE_WOLFSSL_FOUND "wolfssl")
172+
CHECK_DUPLICATE_LIBRARIES(DUPE_WOLFSSL_FOUND "wolfmqtt")
173+
CHECK_DUPLICATE_LIBRARIES(DUPE_WOLFSSL_FOUND "wolfssh")
174+
CHECK_DUPLICATE_LIBRARIES(DUPE_WOLFSSL_FOUND "wolftpm")
175+
79176
if( EXISTS "${CMAKE_HOME_DIRECTORY}/managed_components/wolfssl__wolfssl" AND EXISTS "${CMAKE_HOME_DIRECTORY}/components/wolfssl" )
80177
# These exclude statements don't seem to be honored by the $ENV{IDF_PATH}/tools/cmake/project.cmake'
81178
# add_subdirectory("${CMAKE_HOME_DIRECTORY}/managed_components/wolfssl__wolfssl" EXCLUDE_FROM_ALL)
@@ -90,16 +187,31 @@ if( EXISTS "${CMAKE_HOME_DIRECTORY}/managed_components/wolfssl__wolfssl" AND EXI
90187
message(FATAL_ERROR "\nPlease use either the ESP Registry Managed Component or the wolfSSL component directory but not both.\n"
91188
"If removing the ./managed_components/wolfssl__wolfssl directory, remember to also remove "
92189
"or rename the idf_component.yml file typically found in ./main/")
93-
else()
190+
elseif(EXISTS "${CMAKE_HOME_DIRECTORY}/components/wolfssl")
191+
# A standard project component (not a Managed Component)
94192
message(STATUS "No conflicting wolfSSL components found.")
193+
set(WOLFSSL_PATH "${CMAKE_HOME_DIRECTORY}/components/wolfssl")
194+
elseif(EXISTS "${CMAKE_HOME_DIRECTORY}/managed_components/wolfssl__wolfssl")
195+
# The official Managed Component called wolfssl from the wolfssl user.
196+
message(STATUS "No conflicting wolfSSL components found as a Managed Component.")
197+
set(WOLFSSL_PATH "${CMAKE_HOME_DIRECTORY}/managed_components/wolfssl__wolfssl")
198+
elseif(EXISTS "${CMAKE_HOME_DIRECTORY}/managed_components/gojimmypi__mywolfssl")
199+
# There is a known gojimmypi staging component available for anyone:
200+
message(STATUS "No conflicting wolfSSL components found as a gojimmypi staging Managed Component.")
201+
elseif(EXISTS "${CMAKE_HOME_DIRECTORY}/managed_components/${THIS_USER}__mywolfssl")
202+
# Other users with permissions might publish their own mywolfssl staging Managed Component
203+
message(STATUS "No conflicting wolfSSL components found as a Managed Component.")
204+
set(WOLFSSL_PATH "${CMAKE_HOME_DIRECTORY}/managed_components/${THIS_USER}__mywolfssl")
205+
else()
206+
message(STATUS "WARNING: wolfssl component directory not found.")
95207
endif()
96208

97209

98210
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
99211
set (PROTOCOL_EXAMPLES_DIR $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
100212

101213
if (EXISTS "${PROTOCOL_EXAMPLES_DIR}")
102-
message("Found PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR}")
214+
message(STATUS "Found PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR}")
103215
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
104216
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFOUND_PROTOCOL_EXAMPLES_DIR")
105217
else()
@@ -115,3 +227,4 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
115227
#) # set components
116228

117229
project(wolfssl_mqtt_aws_iot)
230+
message(STATUS "end project")

IDE/Espressif/ESP-IDF/examples/AWS_IoT_MQTT/README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ The latest experimental development version can be found at the staging site:
1313
```bash
1414
#!/bin/bash
1515

16-
. ~/esp/esp-idf/export.sh
16+
WRK_IDF_PATH=/mnt/c/SysGCC/esp32/esp-idf/v5.2
1717

18-
# Needed for Staging site:
18+
echo "Run export.sh from ${WRK_IDF_PATH}"
19+
20+
pushd ${WRK_IDF_PATH}
21+
. ./export.sh
22+
popd
23+
24+
# Needed for Staging site ONLY:
1925
export IDF_COMPONENT_REGISTRY_URL=https://components-staging.espressif.com
2026

2127
idf.py create-project-from-example "gojimmypi/mywolfmqtt^1.0.14-test:AWS_IoT_MQTT"
@@ -52,9 +58,15 @@ set(WOLFSSL_ROOT "~/workspace/wolfssl-other-source")
5258
```
5359

5460

55-
## Getting Started:
61+
## Getting Started with ESP Registry Managed Components:
62+
63+
The quickest way to get started is with wolfMQTT Managed Components.
64+
65+
Coming soon. See [Staging Site](https://components-staging.espressif.com/components/gojimmypi/mywolfmqtt).
5666

57-
Here's an example using the command-line [idf.py](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-py.html).
67+
## Getting Started with ESP-IDF local examples:
68+
69+
Here's an example using the command-line [idf.py](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-py.html):
5870

5971
Edit your `WRK_IDF_PATH`to point to your ESP-IDF install directory.
6072

@@ -80,12 +92,10 @@ Press `Ctrl+]` to exit `idf.py monitor`. See [additional monitor keyboard comman
8092

8193
For examples, see:
8294

83-
- [TLS Client](../wolfssl_client/README.md)
84-
- [TLS Server](../wolfssl_server/README.md)
85-
- [Benchmark](../wolfssl_benchmark/README.md)
86-
- [Test](../wolfssl_test/README.md)
95+
- [wolfSSL template](https://github.com/wolfSSL/wolfssl/tree/master/IDE/Espressif/ESP-IDF/examples/template/README.md)
96+
- [Benchmark](https://github.com/wolfSSL/wolfssl/tree/master/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/README.md)
97+
- [TLS Client](https://github.com/wolfSSL/wolfssl/tree/master/IDE/Espressif/ESP-IDF/examples/wolfssl_client/README.md)
98+
- [TLS Server](https://github.com/wolfSSL/wolfssl/tree/master/IDE/Espressif/ESP-IDF/examples/wolfssl_server/README.md)
99+
- [Test](https://github.com/wolfSSL/wolfssl/tree/master/IDE/Espressif/ESP-IDF/examples/wolfssl_test)
87100
- [wolfssl-examples](https://github.com/wolfSSL/wolfssl-examples/tree/master/ESP32)
88101
- [wolfssh-examples](https://github.com/wolfSSL/wolfssh-examples/tree/main/Espressif)
89-
90-
91-

0 commit comments

Comments
 (0)