Integrate Paho MQTT C library into project. Updated CMakeLists.txt to find PahoMqttC package and added fallback for manual linking. Refactored mqtt.hpp and mqtt.cpp to utilize Paho MQTT C API, replacing previous async client implementation. Added Windows setup guide for MQTT library installation.

This commit is contained in:
2025-09-08 19:53:39 +08:00
parent c655cd8c91
commit 7a9a31afd4
4 changed files with 254 additions and 156 deletions

View File

@@ -9,13 +9,21 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(PkgConfig REQUIRED)
find_package(Threads REQUIRED)
# Find installed unitree_sdk2
# Try to find PahoMqttC, fallback to manual linking if not found
find_package(PahoMqttC QUIET)
if(NOT PahoMqttC_FOUND)
message(STATUS "PahoMqttC package not found, using manual library linking")
find_library(PAHO_MQTT_C_LIBRARY NAMES paho-mqtt3c REQUIRED)
find_path(PAHO_MQTT_C_INCLUDE_DIR NAMES MQTTClient.h REQUIRED)
endif()
find_package(unitree_sdk2 REQUIRED)
# Include directories
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include/nlohmann
$<$<NOT:$<BOOL:${PahoMqttC_FOUND}>>:${PAHO_MQTT_C_INCLUDE_DIR}>
)
# Source files
@@ -25,7 +33,7 @@ set(SOURCES
src/custom_robot.cpp
src/config.cpp
src/logger.cpp
# src/mqtt.cpp # Disabled MQTT for now
src/mqtt.cpp
)
# Create executable with simple name
@@ -35,6 +43,8 @@ add_executable(main ${SOURCES})
target_link_libraries(main
unitree_sdk2
Threads::Threads
$<$<BOOL:${PahoMqttC_FOUND}>:PahoMqttC::PahoMqttC>
$<$<NOT:$<BOOL:${PahoMqttC_FOUND}>>:${PAHO_MQTT_C_LIBRARY}>
)
# Set output directory