-
Notifications
You must be signed in to change notification settings - Fork 83
How to properly "consume" iot-device-sdk-embedded-c #129
Description
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
srcfolder of my ROS2 application. - Build the SDK by calling
makefrom SDK's root directory - Given the fact that ROS2 is using
CMakebuilding approach, I included the following lines in my top-levelCMakeLists.txtfile:
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.