Open law-ko opened 1 year ago
By default, the components directory will be automatically registered as a place to find components. Place the esp-aws-iot library right into your components directory.
In your main directory (another component by default) be sure to correctly apply your REQUIRES variables to include all of the items that you need from esp-aws-iot. It will look a it like this inside your CMakeLists.txt...
//Exposes components to both source and header files. set(REQUIRES coreMQTT nvs_flash backoffAlgorithm ota-for-aws-iot-embedded-sdk )
//Anything that must be exposed to the sources files, but may remain hidden from the header files. set(PRIV_REQUIRES cbor coreHTTP coreJSON posix_compat device-shadow-for-aws-iot-embedded-sdk )
idf_component_register(SRCS ${SOURCES} INCLUDE_DIRS ${COMPONENT_ADD_INCLUDEDIRS} REQUIRES ${REQUIRES}
(the declaration for SOURCES is not shown here)
Once you have the structure of your project correct, and you apply the "requires" items, you then include the header files that your source needs as normal.
You should be able to avoid using set(EXTRA_COMPONENT_DIRS directive as all your components are naturally all in the default areas that are by design.
Look at project examples and dig into the CMake docs a bit to get up to a minimum understanding and you'll find that everything will just work nicely.
I am facing the same issue too. My folder structure is as follows.
components/
esp-aws-iot/
main/
CMakeLists.txt
CMakeLists.txt
The root CMakeLists.txt is as follows.
cmake_minimum_required(VERSION 3.5)
set(AWS_IOT_PATH "components/esp-aws-iot")
set(EXTRA_COMPONENT_DIRS
"${AWS_IOT_PATH}/libraries"
)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project("MyProject")
My main CMakeLists.txt is as follows.
set(MAIN_REQUIRES
wifi_provisioning
coreMQTT
coreMQTT-Agent
corePKCS11
coreJSON
backoffAlgorithm
ota-for-aws-iot-embedded-sdk
Device-Shadow-for-AWS-IoT-embedded-sdk
unity
)
idf_component_register(
SRCS
"main.c"
INCLUDE_DIRS
"main"
REQUIRES
${MAIN_REQUIRES}
)
target_add_binary_data(${COMPONENT_TARGET} "certs/aws-root-ca.pem" TEXT)
These are my errors.
components/esp-aws-iot/libraries/corePKCS11/corePKCS11/source/portable/mbedtls/core_pkcs11_mbedtls.c:275:5: error: unknown type name 'mbedtls_threading_mutex_t'
mbedtls_threading_mutex_t xMutex; /**< @brief Mutex that protects write operations to the xObjects array. */
^~~~~~~~~~~~~~~~~~~~~~~~~
components/esp-aws-iot/libraries/corePKCS11/corePKCS11/source/portable/mbedtls/core_pkcs11_mbedtls.c:288:5: error: unknown type name 'mbedtls_threading_mutex_t'
mbedtls_threading_mutex_t xSessionMutex; /**< @brief Mutex that protects write operations to the pxSession array. */
^~~~~~~~~~~~~~~~~~~~~~~~~
components/esp-aws-iot/libraries/corePKCS11/corePKCS11/source/portable/mbedtls/core_pkcs11_mbedtls.c:306:5: error: unknown type name 'mbedtls_threading_mutex_t'
mbedtls_threading_mutex_t xVerifyMutex; /**< @brief Protects the verification key from being modified while in use. */
^~~~~~~~~~~~~~~~~~~~~~~~~
components/esp-aws-iot/libraries/corePKCS11/corePKCS11/source/portable/mbedtls/core_pkcs11_mbedtls.c:310:5: error: unknown type name 'mbedtls_threading_mutex_t'
mbedtls_threading_mutex_t xSignMutex; /**< @brief Protects the signing key from being modified while in use. */
^~~~~~~~~~~~~~~~~~~~~~~~~
components/esp-aws-iot/libraries/corePKCS11/corePKCS11/source/portable/mbedtls/core_pkcs11_mbedtls.c: In function 'prvMbedTLS_Initialize':
components/esp-aws-iot/libraries/corePKCS11/corePKCS11/source/portable/mbedtls/core_pkcs11_mbedtls.c:459:5: error: implicit declaration of function 'mbedtls_mutex_init'; did you mean 'mbedtls_mpi_init'? [-Werror=implicit-function-declaration]
mbedtls_mutex_init( &xP11Context.xObjectList.xMutex );
^~~~~~~~~~~~~~~~~~
mbedtls_mpi_init
components/esp-aws-iot/libraries/corePKCS11/corePKCS11/source/portable/mbedtls/core_pkcs11_mbedtls.c: In function 'prvDeleteObjectFromList':
components/esp-aws-iot/libraries/corePKCS11/corePKCS11/source/portable/mbedtls/core_pkcs11_mbedtls.c:1148:21: error: implicit declaration of function 'mbedtls_mutex_lock'; did you mean 'mbedtls_calloc'? [-Werror=implicit-function-declaration]
lGotSemaphore = mbedtls_mutex_lock( &xP11Context.xObjectList.xMutex );
^~~~~~~~~~~~~~~~~~
mbedtls_calloc
components/esp-aws-iot/libraries/corePKCS11/corePKCS11/source/portable/mbedtls/core_pkcs11_mbedtls.c:1162:18: error: implicit declaration of function 'mbedtls_mutex_unlock'; did you mean 'mbedtls_md_clone'? [-Werror=implicit-function-declaration]
( void ) mbedtls_mutex_unlock( &xP11Context.xObjectList.xMutex );
^~~~~~~~~~~~~~~~~~~~
mbedtls_md_clone
components/esp-aws-iot/libraries/corePKCS11/corePKCS11/source/portable/mbedtls/core_pkcs11_mbedtls.c: In function 'C_Finalize':
components/esp-aws-iot/libraries/corePKCS11/corePKCS11/source/portable/mbedtls/core_pkcs11_mbedtls.c:1490:9: error: implicit declaration of function 'mbedtls_mutex_free'; did you mean 'mbedtls_mpi_free'? [-Werror=implicit-function-declaration]
mbedtls_mutex_free( &xP11Context.xObjectList.xMutex );
^~~~~~~~~~~~~~~~~~
mbedtls_mpi_free
cc1: some warnings being treated as errors
ninja: build stopped: subcommand failed.
ninja failed with exit code 1
I've tried looking at https://github.com/FreeRTOS/iot-reference-esp32c3 for reference when setting up the CMakeLists.txt files, but I'm not sure what's causing this problem. I want to keep this folder structure (I don't want to copy the esp-aws-iot folder to the esp-idf/components directory). How could I fix this problem?
You may have several errors.... one that I see immediately is:
I don't think this is necessary:
set(AWS_IOT_PATH "components/esp-aws-iot")
set(EXTRA_COMPONENT_DIRS "${AWS_IOT_PATH}/libraries" )
You just drop the esp-aws-iot into the components directory and it is by default a locatable component.
Anything inside main and the components directories are consider a components by default.
Look one of my current projects:
I have my project set up a bit differently -- my iot component includes this CMakeLists. Notice the items from the esp-awt-iot component that I include:
The only unusual thing you see here are 3 sets of certs. These are simple client credentials which can be used for fleet provisioning. The final sets of credentials are stored in NVS only.
Another issue that seems to be going on is some kind of incompatibility between esp-aws-iot and the compiler? You'll need to make sure that the esp-aws-iot version and your IDF version will work together. I'm still on 4.4.1 and an esp-aws-iot snapshot from last year.
I still had to add the AWS_IOT_PATH to my EXTRA_COMPONENT_DIRS, otherwise it failed. Luckily, I did find a solution and that was to add the following to my sdkconfig.defaults (or sdkconfig) (found from sdkconfig.defaults at https://github.com/FreeRTOS/iot-reference-esp32c3/tree/v202212.00) which resolved the error about mbedtls.
CONFIG_MBEDTLS_THREADING_C=y
CONFIG_MBEDTLS_THREADING_ALT=n
CONFIG_MBEDTLS_THREADING_PTHREAD=y
I should also note that I'm using the following:
You got it. Good going. These things are hard.
K.
From: Toby Loki @.> Sent: Wednesday, March 8, 2023 10:22 AM To: espressif/esp-aws-iot @.> Cc: keith ssledlighting.com @.>; Comment @.> Subject: Re: [espressif/esp-aws-iot] Unable to compile when adding esp-aws-iot as component library (CA-276) (Issue #168)
I still had to add the AWS_IOT_PATH to my EXTRA_COMPONENT_DIRS, otherwise it failed. Luckily, I did find a solution and that was to add the following to my sdkconfig.defaults (or sdkconfig) (found from sdkconfig.defaults at https://github.com/FreeRTOS/iot-reference-esp32c3/tree/v202212.00) which resolved the error about mbedtls.
CONFIG_MBEDTLS_THREADING_C=y CONFIG_MBEDTLS_THREADING_ALT=n CONFIG_MBEDTLS_THREADING_PTHREAD=y
I should also note that I'm using the following:
— Reply to this email directly, view it on GitHubhttps://github.com/espressif/esp-aws-iot/issues/168#issuecomment-1459174578, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGGOKE52GZATQXNSJJGGE5DW27UNBANCNFSM6AAAAAAUSWQLAU. You are receiving this because you commented.Message ID: @.***>
I still had to add the AWS_IOT_PATH to my EXTRA_COMPONENT_DIRS, otherwise it failed. Luckily, I did find a solution and that was to add the following to my sdkconfig.defaults (or sdkconfig) (found from sdkconfig.defaults at https://github.com/FreeRTOS/iot-reference-esp32c3/tree/v202212.00) which resolved the error about mbedtls.
CONFIG_MBEDTLS_THREADING_C=y CONFIG_MBEDTLS_THREADING_ALT=n CONFIG_MBEDTLS_THREADING_PTHREAD=y
I should also note that I'm using the following:
* esp-idf: v4.4.3 * esp-aws-iot: tag 202210.01-LTS-release
You are a saviour been trying to trouble shoot for days now
It is nice of you to send me some happy feedback. We are up to v4.4.5 now, but no further.
I am also getting the same error and I am using:
esp-idf: v5.1
esp-aws-iot: master branch
The new 5.1 is supposed to accept the newest release of the esp-aws-iot library. They have made a few organizational changes. I have not tried moving to 5.1 with this library yet. You best way forward is to sure you understand CMake as best you can and follow any examples you can find.
@SolidStateLEDLighting I am abe to resolve mbledtls issues by following to defconfig:
CONFIG_MBEDTLS_THREADING_C=y CONFIG_MBEDTLS_THREADING_ALT=n CONFIG_MBEDTLS_THREADING_PTHREAD=y
I encountered the same issue working with
You absolutely do have to explicitly set
list(APPEND EXTRA_COMPONENT_DIRS
${CMAKE_CURRENT_LIST_DIR}/components/esp-aws-iot/libraries
)
the actual code modules are located in subdirectories, and for me, CMake had no idea there was anything in there til I told to go and look.
I had to specifically make the changes to config_mbedtls_threading in menuconfig. It wasn't enough to fiddle the values in the sdkconfig.defaults file.
Hope this is helpful.
Just want to second what @monkeytronics said. Also, shouldn't there be a CMakeLists.txt file in the main esp-aws-iot directory?
Each subdirectory inside the esp-aws-iot library is a component and each has their own CMakeLists.txt files. You should be able to clone that entire library without modification and just use it.
However, you will need to add those libraries as EXTRA_COMPONENT_DIRS in the project's root CMakeLists.txt file. This is a working example. It is possible that the other example above which includes only the root "../libraries" directory may also work. I just explicitly included them all one by one. Each of those library names also need to be added inside other CMakeLists files where the library is consumed -- so it is nice to have those names handy.
An example of consuming the libraries is in the picture above. (March 8th posting) where I create and "iot" component and consume all the esp-aws-iot libraries. You could also consume this in "main". I use another component to wrap up all the iot functionality that way that I want to consume it (the equivalent of the espressif examples which consume the library).
Notice that muy list above (March 8th posting) doesn't include Jobs -- but I definitely do use Jobs -- so another library must include it for me. And my root file includes a few things that I don't use (like device-defender).
I believe that CBOR inclusion has changed for the newest release of the esp-aws-iot library -- so this may need to be included differently than shown here.
Hello,
We are trying to add
esp-aws-iot
components by adding the repo as a submodule. However, we are getting build errors even with the clean project..gitmodules:
CMakeLists.txt:
build error log:
None of the project codes are being edited. How to fix this?
Thank you.