Skip to content

alanb-sony/mqtt_cpp

 
 

Repository files navigation

MQTT client/server for C++14 based on Boost.Asio

Version 8.0.0 Actions StatusBuild Statuscodecov

Important note https://github.com/redboltz/mqtt_cpp/wiki/News.

MQTT v5 is supported since version 4.0.0.

Overview

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>
#include <mqtt/setup_log.hpp> // if you want to use typical logging setup

For servers:

#include <mqtt_server_cpp.hpp>
#include <mqtt/setup_log.hpp> // if you want to use typical logging setup

You can compile your code as follows:

g++ -std=c++14 -Ipath_to_mqtt_cpp/include your_program.cpp -pthread additional_options

additional_options

what you want required option
TLS support -DMQTT_USE_TLS -pthread -lssl -lcrypto
Logging support -DMQTT_USE_LOG -DBOOST_LOG_DYN_LINK -lboost_log -lboost_filesystem -lboost_thread
WebSocket support -DMQTT_USE_WS

You can see more detail at https://github.com/redboltz/mqtt_cpp/wiki/Config

Example

Usage in cmake project

Add following lines to your CMakeLists.txt

set(LIBNAME "your_project_name")
add_library(${LIBNAME} <your dependencies here>)

find_package(mqtt_cpp_iface REQUIRED)
target_link_libraries(${LIBNAME} LINK_PUBLIC mqtt_cpp_iface::mqtt_cpp_iface)

This uses the mqtt_cpp_iface::mqtt_cpp_iface target and includes all necessary link dependencies.

Test

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.

Documents

https://github.com/redboltz/mqtt_cpp/wiki

You can create html documents using doxygen.

make doxygen

License

mqtt_cpp is licensed under the Boost Software License, Version 1.0. See the LICENSE_1_0.txt file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 99.2%
  • CMake 0.8%