Important note https://github.com/redboltz/mqtt_cpp/wiki/News.
MQTT v5 is supported since version 4.0.0.
mqtt_cpp is a header only library. It requires C++14 and the Boost Libraries 1.66.0 or later.
Add mqtt_cpp/include to your include path. Then, include mqtt_cpp.hpp
and/or mqtt_server_cpp.hpp
as follows:
For clients:
#include <mqtt_client_cpp.hpp>
For servers:
#include <mqtt_server_cpp.hpp>
You can compile your program as follows:
g++ -std=c++14 -Ipath_to_mqtt_cpp/include -DMQTT_NO_TLS no_tls.cpp -lboost_system -lpthread
g++ -std=c++14 -Ipath_to_mqtt_cpp/include tls.cpp -lboost_system -lssl -lcrypto -lpthread
If you want to use MQTT on WebSocket, you need to define MQTT_USE_WS
macro. mqtt_cpp uses https://github.com/boostorg/beast for WebSocket communication and it requires boost::string_view
, so the boost library need to support boost::string_view
.
- NO TLS
- Client
- TCP
- WebSocket
- Server
- TCP
- WebSocket
- Client and Server
- TCP
- WebSocket
- Client
- TLS
- Client
- TCP
- WebSocket
- Server
- TCP
- WebSocket
- Client and Server
- TCP
- WebSocket
- Client
Add following lines to your CMakeLists.txt
set(LIBNAME "your_project_name")
add_library(${LIBNAME} <your dependencies here>)
find_package(mqtt_cpp REQUIRED)
target_link_libraries(${LIBNAME} LINK_PUBLIC mqtt_cpp::mqtt_cpp)
This uses the mqtt_cpp::mqtt_cpp
target and includes all necessary link dependencies.
You can build tests and examples as follows:
At mqtt_cpp directory
mkdir build
cd build
cmake ..
make
make test
In order to build tests, you need to prepare the Boost Libraries 1.59.0.
https://github.com/redboltz/mqtt_cpp/wiki
You can create html documents using doxygen.
make doxygen
mqtt_cpp is licensed under the Boost Software License, Version 1.0. See
the LICENSE_1_0.txt
file for details.