diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24d364b..c437994 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,20 +70,23 @@ jobs: - name: Install dependencies run: | brew install openssl - # Install CMake 3.31.6 from Kitware - curl -L https://github.com/Kitware/CMake/releases/download/v3.31.6/cmake-3.31.6-macos-universal.dmg -o cmake.dmg + # Install CMake 3.26.4 from Kitware + curl -L https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-macos-universal.dmg -o cmake.dmg hdiutil attach cmake.dmg - sudo cp -R /Volumes/cmake-3.31.6-macos-universal/CMake.app /Applications/ + sudo cp -R /Volumes/cmake-3.26.4-macos-universal/CMake.app /Applications/ sudo /Applications/CMake.app/Contents/bin/cmake-gui --install - hdiutil detach /Volumes/cmake-3.31.6-macos-universal + hdiutil detach /Volumes/cmake-3.26.4-macos-universal rm cmake.dmg + echo "CMAKE_PATH=/Applications/CMake.app/Contents/bin" >> $GITHUB_ENV - name: Configure and build env: OPENSSL_ROOT_DIR: /opt/homebrew/opt/openssl@3 OPENSSL_LIBRARIES: /opt/homebrew/opt/openssl@3/lib OPENSSL_INCLUDE_DIR: /opt/homebrew/opt/openssl@3/include + CMAKE_PATH: /Applications/CMake.app/Contents/bin run: | + export PATH="/Applications/CMake.app/Contents/bin:$PATH" ./build.sh -DCMAKE_BUILD_TYPE=debug -DONESDK_WITH_TEST=ON - name: Run tests diff --git a/build.sh b/build.sh index 0e89944..159c101 100755 --- a/build.sh +++ b/build.sh @@ -3,12 +3,19 @@ set -e # Exit on any error # Function to check CMake version check_cmake_version() { - if ! command -v cmake &> /dev/null; then - echo "Error: CMake is not installed!" + # Use CMAKE_PATH if provided, otherwise use default cmake command + if [ -n "$CMAKE_PATH" ]; then + CMAKE_CMD="$CMAKE_PATH/cmake" + else + CMAKE_CMD="cmake" + fi + + if ! command -v $CMAKE_CMD &> /dev/null; then + echo "Error: CMake is not installed at $CMAKE_CMD!" exit 1 fi - cmake_version=$(cmake --version | head -n1 | cut -d' ' -f3) + cmake_version=$($CMAKE_CMD --version | head -n1 | cut -d' ' -f3) cmake_major=$(echo $cmake_version | cut -d'.' -f1) cmake_minor=$(echo $cmake_version | cut -d'.' -f2) @@ -48,8 +55,15 @@ fi mkdir -p build cd build +# Use CMAKE_PATH if provided, otherwise use default cmake command +if [ -n "$CMAKE_PATH" ]; then + CMAKE_CMD="$CMAKE_PATH/cmake" +else + CMAKE_CMD="cmake" +fi + echo "Running cmake with arguments: $@" -cmake $@ .. +$CMAKE_CMD $@ .. if [ $? -ne 0 ]; then echo "CMake configuration failed!" exit 1 diff --git a/examples/onesdk_esp32/main/CMakeLists.txt b/examples/onesdk_esp32/main/CMakeLists.txt index b3ec5b2..80fc9a8 100644 --- a/examples/onesdk_esp32/main/CMakeLists.txt +++ b/examples/onesdk_esp32/main/CMakeLists.txt @@ -13,7 +13,7 @@ message(STATUS "onesdk_esp32 srcs: ${ONESDK_ESP32_SRCS}") set(ONESDK_ESP32_DEPS onesdk) message(STATUS "onesdk_esp32 deps: ${ONESDK_ESP32_DEPS}") idf_component_register(SRCS "${ONESDK_ESP32_SRCS}" - PRIV_REQUIRES ${ONESDK_ESP32_DEPS} + PRIV_REQUIRES ${ONESDK_ESP32_DEPS} wpa_supplicant # INCLUDE_DIRS "../libwebsockets/include;${IDF_PATH}/components/spi_flash/include;${IDF_PATH}/components/nvs_flash/include") INCLUDE_DIRS ".;${IDF_PATH}/components/spi_flash/include;${IDF_PATH}/components/nvs_flash/include") diff --git a/src/iot/iot_mqtt.c b/src/iot/iot_mqtt.c index 1dd6de2..50f6a8c 100644 --- a/src/iot/iot_mqtt.c +++ b/src/iot/iot_mqtt.c @@ -38,7 +38,6 @@ static int callback_mqtt(struct lws *wsi, enum lws_callback_reasons reason, */ struct lws_context *context = lws_get_context(wsi); iot_mqtt_ctx_t *ctx = (iot_mqtt_ctx_t *)lws_context_user(context); - ctx->wsi = wsi; switch (reason) { case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: @@ -62,7 +61,8 @@ static int callback_mqtt(struct lws *wsi, enum lws_callback_reasons reason, ctx->waiting_for_suback = 0; lws_callback_on_writable(wsi); lws_set_timer_usecs(wsi, ctx->config->ping_interval*1000000); - + ctx->wsi = wsi; + return 0; case LWS_CALLBACK_MQTT_SUBSCRIBED: @@ -452,7 +452,12 @@ int iot_mqtt_init(iot_mqtt_ctx_t *ctx, iot_mqtt_config_t *config) { // info.register_notifier_list = na; info.retry_and_idle_policy = &retry; info.user = (void*)ctx; - // info.client_ssl_ca_filepath = NULL; + if (config->enable_mqtts && config->basic_config->ssl_ca_cert) { + info.server_ssl_ca_mem = config->basic_config->ssl_ca_cert; + info.server_ssl_ca_mem_len = strlen(config->basic_config->ssl_ca_cert); + + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + } struct lws_context *context = lws_create_context(&info); if (context == NULL) { lwsl_err("lws init failed\n");