Skip to content
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
This repository was archived by the owner on Jul 22, 2023. It is now read-only.

How to properly "consume" iot-device-sdk-embedded-c  #129

@bojankoce

Description

@bojankoce

I'm running Ubuntu 20.04 machine where I'm trying to develop a ROS2-based application in C/C++.
One of the requirements I have is to create ROS2 node that will establish MQTT connection with the Google Cloud, so my natural choice was to benefit from the iot-device-sdk-embedded-c.
I started reading the SDK documentation and was able to clone the repo, and build it by calling make command from the root directory.
Moreover, trying examples/iot_core_mqtt_client example also went well - I was able to connect to the Cloud and periodically publish data. Sweet!

Now, the trouble comes when I want to use/"consume" iot-device-sdk-embedded-c SDK in my ROS2 development environment. What I did is the following:

  • Cloned the iot-device-sdk-embedded-c repo inside src folder of my ROS2 application.
  • Build the SDK by calling make from SDK's root directory
  • Given the fact that ROS2 is using CMake building approach, I included the following lines in my top-level CMakeLists.txt file:
set(IOTC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/mqtt_client_node/iot-device-sdk-embedded-c)

target_include_directories(mqtt_client_node PRIVATE ${IOTC_PATH}/include)
...
# libiotc
target_link_libraries(mqtt_client_node ${IOTC_PATH}/bin/linux/libiotc.a)

# mbedTLS
set(IOTC_MBEDTLS_LIB_PATH ${IOTC_PATH}/third_party/tls/mbedtls/library)
target_link_libraries(mqtt_client_node  ${IOTC_MBEDTLS_LIB_PATH}/libmbedtls.a)
target_link_libraries(mqtt_client_node  ${IOTC_MBEDTLS_LIB_PATH}/libmbedx509.a)
target_link_libraries(mqtt_client_node  ${IOTC_MBEDTLS_LIB_PATH}/libmbedcrypto.a)

The approach is taken from your examples/zephyr_native_posix example and I was hoping it will be enough to properly build my ROS2-based executable that will, as a first try, behave the same way as your examples/iot_core_mqtt_client example.

The application was compiled successfully (Yay!) but when I started the app and tried to connect to the MQTT server with iotc_connect() I get the following error from on_connection_state_changed() callback function:

ERROR!	Connection has failed reason 20 : 

According to your error dictionary from iotc_error.h file, 20 is the error code for IOTC_TLS_FAILED_LOADING_CERTIFICATE.

Do you have any idea what I am doing wrong or missing? Public/Private keys and generated JWT are completely the same as in my first successful attempt when I just compiled your example.

Thank you very much for your time and efforts. It is really appreaciated.
Looking forward to reading from you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions