Skip to content

Commit

Permalink
Minor wolfMQTT Espressif examples polish
Browse files Browse the repository at this point in the history
  • Loading branch information
gojimmypi committed Jan 3, 2024
1 parent 2fe5676 commit 4a3a5f2
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ cmake_minimum_required(VERSION 3.5)
#
# When editing component CMake files, consider the following :
#
# NO Managed Componenets: Normal stand-alone app, "as cloned" from github.
# NO Managed Components: Normal stand-alone app, "as cloned" from github.
# There's no notion of staging names (e.g. mywolfmqtt) regardless of environment settings.
# All of the component source is locall. See settings such s WOLFSSL_ROOT=[your path]
# All of the component source is local. See settings such s WOLFSSL_ROOT=[your path]
#
# Partially Managed Components. This one is tricky. When publishing a component with examples,
# those examples will have a chicken-and-egg problem: the required component is not yet published.
Expand All @@ -34,7 +34,7 @@ cmake_minimum_required(VERSION 3.5)
#
# idf.py add-dependency "wolfssl/wolfssh^1.4.15-stable"
#
# Fully Managaged Componenets. This is the typical example as created from the Component Registry:
# Fully Managed Components. This is the typical example as created from the Component Registry:
# For example:
#
# idf.py create-project-from-example "wolfssl/wolfssh^1.4.15-stable:wolfssh_server"
Expand Down
27 changes: 26 additions & 1 deletion IDE/Espressif/ESP-IDF/examples/AWS_IoT_MQTT/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
#
message(STATUS "main cmake found WOLFSSL_COMPONENT_NAME = ${WOLFSSL_COMPONENT_NAME}")

# find the user name to search for possible "wolfssl-username"
message(STATUS "USERNAME = $ENV{USERNAME}")
if( "$ENV{USER}" STREQUAL "" ) # the bash user
if( "$ENV{USERNAME}" STREQUAL "" ) # the Windows user
message(STATUS "could not find USER or USERNAME")
else()
# the bash user is not blank, so we'll use it.
set(THIS_USER "$ENV{USERNAME}")
endif()
else()
# the bash user is not blank, so we'll use it.
set(THIS_USER "$ENV{USER}")
endif()
message(STATUS "THIS_USER (main) = ${THIS_USER}")

if(WIN32)
# Windows-specific configuration here
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS")
Expand Down Expand Up @@ -42,6 +57,16 @@ if( EXISTS "${CMAKE_HOME_DIRECTORY}/components/wolfssl/" AND EXISTS "$ENV{IDF_PA
endif()

if( "$ENV{IDF_COMPONENT_REGISTRY_URL}" STREQUAL "https://components-staging.espressif.com" )
# Currently the only staging namespace is the gojimmypi developer, but allow for override.
# See https://components-staging.espressif.com/components?q=namespace:gojimmypi
#
if( "$ENV{WOLFSSL_STAGING_NAMESPACE}" STREQUAL "" )
set(WOLFSSL_STAGING_NAMESPACE "gojimmypi")
else()
set(WOLFSSL_STAGING_NAMESPACE "$ENV{WOLFSSL_STAGING_NAMESPACE}")
endif()
message(STATUS "Using namespace: ${WOLFSSL_STAGING_NAMESPACE}")

if( ("${managed_components}" STREQUAL "") AND ("${component_manager_interface_version}" STREQUAL "") )
# We've found a staging component, but did not detect the component manager
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/../components/mywolfmqtt/CMakeLists.txt)
Expand All @@ -50,7 +75,7 @@ if( "$ENV{IDF_COMPONENT_REGISTRY_URL}" STREQUAL "https://components-staging.espr
set(WOLFSSL_COMPONENT_NAME "mywolfssl")
set(WOLFMQTT_COMPONENT_NAME "mywolfmqtt")
else()
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/../managed_components/gojimmypi__mywolfmqtt/CMakeLists.txt)
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../managed_components/${WOLFSSL_STAGING_NAMESPACE}__mywolfmqtt/CMakeLists.txt")
# This is typically upon creating a project from managed component examples
message(STATUS "Set name mywolfmqtt (2)")
set(WOLFSSL_COMPONENT_NAME "mywolfssl")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* config.h - dummy
*
* Copyright (C) 2006-2023 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/

#ifndef _CONFIG_H_
#define _CONFIG_H_
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)

# enable wolfssl user_settings.h project-wide
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS")
set(WOLFSSL_USER_SETTINGS ON)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,13 @@ else()
message(STATUS "Remove either the local project component: ${WOLFSSL_PROJECT_DIR} ")
message(STATUS "or the Espressif shared component installed at: $ENV{IDF_PATH}/components/wolfssl/ ")
message(STATUS "")
message(FATAL_ERROR "Please use wolfSSL in either local project or Espressif components, but not both.")
message(STATUS "")
message(STATUS "**************************************************************************************")
message(STATUS "")

message(FATAL_ERROR "Please use wolfSSL in either local project or Espressif components, but not both.")
# Abort CMake after fatal error.

# Optional: if you change the above FATAL_ERROR to STATUS you can warn at runtime with this macro definition:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_MULTI_INSTALL_WARNING")

Expand Down Expand Up @@ -284,6 +286,7 @@ else()
message(FATAL_ERROR "Found stray wolfSSL user_settings.h in "
"${WOLFSSL_ROOT}/include/user_settings.h "
" (please move it to ${WOLFSSL_PROJECT_DIR}/include/user_settings.h )")
# Abort CMake after fatal error.
else()
# we won't overwrite an existing user settings file, just note that we already have one:
if( EXISTS "${WOLFSSL_PROJECT_DIR}/include/user_settings.h" )
Expand Down Expand Up @@ -354,16 +357,17 @@ else()
endif()
endif()


# wolfSSL-specific include directories
set(COMPONENT_ADD_INCLUDEDIRS
"./include" # this is the location of wolfssl user_settings.h
"./include" # this is the location of local project wolfssl user_settings.h
"\"${WOLFSSL_ROOT}/\""
"\"${WOLFSSL_ROOT}/wolfssl/\""
"\"${WOLFSSL_ROOT}/wolfssl/wolfcrypt/\""
"\"${WOLFSSL_ROOT}/wolfssl/wolfcrypt/port/Espressif\""
"\"${RTOS_IDF_PATH}/\""
)


# Optionally include cryptoauthlib if present
if(IS_DIRECTORY ${IDF_PATH}/components/cryptoauthlib)
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../cryptoauthlib/lib")
endif()
Expand All @@ -372,7 +376,7 @@ else()
list(APPEND COMPONENT_ADD_INCLUDEDIRS "\"${WOLFSSL_ROOT}/wolfssl/wolfcrypt/\"")



# Some files are known to be included elsewhere, or not used for Espressif
set(COMPONENT_SRCEXCLUDE
"\"${WOLFSSL_ROOT}/src/bio.c\""
"\"${WOLFSSL_ROOT}/src/conf.c\""
Expand Down Expand Up @@ -431,7 +435,21 @@ else()
message(STATUS "ALL VARIABLES BEGIN")
message(STATUS "")
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
if ( ("${_variableName}" STREQUAL "bootloader_binary_files")
OR ("${_variableName}" STREQUAL "Component paths")
OR ("${_variableName}" STREQUAL "component_targets")
OR ("${_variableName}" STREQUAL "__COMPONENT_TARGETS")
OR ("${_variableName}" STREQUAL "CONFIGS_LIST")
OR ("${_variableName}" STREQUAL "__CONFIG_VARIABLES")
OR ("${_variableName}" STREQUAL "val")
OR ("${_variableName}" MATCHES "^__idf_")
)
# Truncate the displayed value:
string(SUBSTRING "${${_variableName}}" 0 70 truncatedValue)
message(STATUS "${_variableName} = ${truncatedValue} ... (truncated)")
else()
message(STATUS "${_variableName}=${${_variableName}}")
endif()
endforeach()
message(STATUS "")
message(STATUS "ALL VARIABLES END")
Expand Down Expand Up @@ -518,6 +536,8 @@ if(NOT CMAKE_BUILD_EARLY_EXPANSION)
execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "show" "--no-patch" "--no-notes" "--pretty=\'\%cd\'" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES )
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH_DATE "${TMP_OUT}" "${TMP_RES}")

LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_WOLFSSL_ROOT "${WOLFSSL_ROOT}" "${TMP_RES}")

message(STATUS "************************************************************************************************")
message(STATUS "wolfssl component config complete!")
message(STATUS "************************************************************************************************")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,12 @@
/* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */

/* These are defined automatically in esp32-crypt.h, here for clarity: */
#define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA224 /* no SHA224 HW on ESP32 */
/* no SHA224 HW on ESP32 */
#define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA224

/* TODO add compile-time warning for appropriate size: */
#undef ESP_RSA_MULM_BITS
#define ESP_RSA_MULM_BITS 16 /* TODO add compile-time warning */
#define ESP_RSA_MULM_BITS 16
/***** END CONFIG_IDF_TARGET_ESP32 *****/

#elif defined(CONFIG_IDF_TARGET_ESP32S2)
Expand Down Expand Up @@ -277,8 +279,10 @@
/* #define NO_WOLFSSL_ESP32_CRYPT_HASH */ /* to disable all SHA HW */

/* These are defined automatically in esp32-crypt.h, here for clarity: */
#define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA384 /* no SHA384 HW on C6 */
#define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA512 /* no SHA512 HW on C6 */
/* no SHA384 HW on C3 */
#define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA384
/* no SHA512 HW on C3 */
#define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA512

/* #define NO_WOLFSSL_ESP32_CRYPT_AES */
/* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
Expand All @@ -293,8 +297,10 @@
/* #define NO_ESP32_CRYPT */
/* #define NO_WOLFSSL_ESP32_CRYPT_HASH */
/* These are defined automatically in esp32-crypt.h, here for clarity: */
#define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA384 /* no SHA384 HW on C6 */
#define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA512 /* no SHA512 HW on C6 */
/* no SHA384 HW on C6 */
#define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA384
/* no SHA512 HW on C6 */
#define NO_WOLFSSL_ESP32_CRYPT_HASH_SHA512

/* #define NO_WOLFSSL_ESP32_CRYPT_AES */
/* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
Expand All @@ -312,7 +318,7 @@
/***** END CONFIG_IDF_TARGET_ESP32H2 *****/

#elif defined(CONFIG_IDF_TARGET_ESP8266)
/* TODO: Revisit ESP8266 */
/* There's no hardware accleration on the ESP8266 */
#define NO_ESP32_CRYPT
#define NO_WOLFSSL_ESP32_CRYPT_HASH
#define NO_WOLFSSL_ESP32_CRYPT_AES
Expand Down Expand Up @@ -435,60 +441,62 @@
#if defined(HAVE_CONFIG_H)
#warning "Unexpected use of config.h"
#else
/* TLS Support */
#undef ENABLE_MQTT_TLS
#define ENABLE_MQTT_TLS

/* MQTT-SN Support */
#undef WOLFMQTT_SN
#define WOLFMQTT_SN

/* MQTT v5.0 support */
#undef WOLFMQTT_V5
#define WOLFMQTT_V5

/* Enable property callback support */
#ifdef WOLFMQTT_V5
#undef WOLFMQTT_PROPERTY_CB
#define WOLFMQTT_PROPERTY_CB
#endif
/* TLS Support */
#undef ENABLE_MQTT_TLS
#define ENABLE_MQTT_TLS

/* Non-blocking support */
#undef WOLFMQTT_NONBLOCK
#define WOLFMQTT_NONBLOCK
/* MQTT-SN Support */
#undef WOLFMQTT_SN
#define WOLFMQTT_SN

/* Disable socket timeout code */
//#undef WOLFMQTT_NO_TIMEOUT
//#define WOLFMQTT_NO_TIMEOUT
/* MQTT v5.0 support */
#undef WOLFMQTT_V5
#define WOLFMQTT_V5

/* Disconnect callback support */
#undef WOLFMQTT_DISCONNECT_CB
#define WOLFMQTT_DISCONNECT_CB
/* Enable property callback support */
#ifdef WOLFMQTT_V5
#undef WOLFMQTT_PROPERTY_CB
#define WOLFMQTT_PROPERTY_CB
#endif

/* Multi-threading */
#undef WOLFMQTT_MULTITHREAD
#define WOLFMQTT_MULTITHREAD
/* Non-blocking support */
#undef WOLFMQTT_NONBLOCK
#define WOLFMQTT_NONBLOCK

/* Debugging */
/*
#undef DEBUG_WOLFMQTT
#define DEBUG_WOLFMQTT
/* Disable socket timeout code */
/*
#undef WOLFMQTT_NO_TIMEOUT
#define WOLFMQTT_NO_TIMEOUT
*/

#undef WOLFMQTT_DEBUG_CLIENT
#define WOLFMQTT_DEBUG_CLIENT
/* Disconnect callback support */
#undef WOLFMQTT_DISCONNECT_CB
#define WOLFMQTT_DISCONNECT_CB

#undef WOLFMQTT_DEBUG_SOCKET
#define WOLFMQTT_DEBUG_SOCKET
/* Multi-threading */
#undef WOLFMQTT_MULTITHREAD
#define WOLFMQTT_MULTITHREAD

#undef WOLFMQTT_DEBUG_THREAD
#define WOLFMQTT_DEBUG_THREAD
*/
/* Debugging */
/*
#undef DEBUG_WOLFMQTT
#define DEBUG_WOLFMQTT
/* Disable error strings */
/*
#undef WOLFMQTT_NO_ERROR_STRINGS
#define WOLFMQTT_NO_ERROR_STRINGS
*/
#undef WOLFMQTT_DEBUG_CLIENT
#define WOLFMQTT_DEBUG_CLIENT
#undef WOLFMQTT_DEBUG_SOCKET
#define WOLFMQTT_DEBUG_SOCKET
#undef WOLFMQTT_DEBUG_THREAD
#define WOLFMQTT_DEBUG_THREAD
*/

/* Disable error strings */
/*
#undef WOLFMQTT_NO_ERROR_STRINGS
#define WOLFMQTT_NO_ERROR_STRINGS
*/

#endif /* !HAVE_CONFIG_H */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
#
message(STATUS "main cmake found WOLFSSL_COMPONENT_NAME = ${WOLFSSL_COMPONENT_NAME}")

# find the user name to search for possible "wolfssl-username"
message(STATUS "USERNAME = $ENV{USERNAME}")
if( "$ENV{USER}" STREQUAL "" ) # the bash user
if( "$ENV{USERNAME}" STREQUAL "" ) # the Windows user
message(STATUS "could not find USER or USERNAME")
else()
# the bash user is not blank, so we'll use it.
set(THIS_USER "$ENV{USERNAME}")
endif()
else()
# the bash user is not blank, so we'll use it.
set(THIS_USER "$ENV{USER}")
endif()
message(STATUS "THIS_USER (main) = ${THIS_USER}")

if(WIN32)
# Windows-specific configuration here
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS")
Expand Down Expand Up @@ -42,6 +57,16 @@ if( EXISTS "${CMAKE_HOME_DIRECTORY}/components/wolfssl/" AND EXISTS "$ENV{IDF_PA
endif()

if( "$ENV{IDF_COMPONENT_REGISTRY_URL}" STREQUAL "https://components-staging.espressif.com" )
# Currently the only staging namespace is the gojimmypi developer, but allow for override.
# See https://components-staging.espressif.com/components?q=namespace:gojimmypi
#
if( "$ENV{WOLFSSL_STAGING_NAMESPACE}" STREQUAL "" )
set(WOLFSSL_STAGING_NAMESPACE "gojimmypi")
else()
set(WOLFSSL_STAGING_NAMESPACE "$ENV{WOLFSSL_STAGING_NAMESPACE}")
endif()
message(STATUS "Using namespace: ${WOLFSSL_STAGING_NAMESPACE}")

if( ("${managed_components}" STREQUAL "") AND ("${component_manager_interface_version}" STREQUAL "") )
# We've found a staging component, but did not detect the component manager
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/../components/mywolfmqtt/CMakeLists.txt)
Expand All @@ -50,7 +75,7 @@ if( "$ENV{IDF_COMPONENT_REGISTRY_URL}" STREQUAL "https://components-staging.espr
set(WOLFSSL_COMPONENT_NAME "mywolfssl")
set(WOLFMQTT_COMPONENT_NAME "mywolfmqtt")
else()
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/../managed_components/gojimmypi__mywolfmqtt/CMakeLists.txt)
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../managed_components/${WOLFSSL_STAGING_NAMESPACE}__mywolfmqtt/CMakeLists.txt")
# This is typically upon creating a project from managed component examples
message(STATUS "Set name mywolfmqtt (2)")
set(WOLFSSL_COMPONENT_NAME "mywolfssl")
Expand Down

0 comments on commit 4a3a5f2

Please sign in to comment.