1 Star 0 Fork 1

水滴/mqtt_cpp

forked from aijle/mqtt_cpp 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSL-1.0

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

Version 12.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.67.0 or later.

Add mqtt_cpp/include to your include path. Then, include mqtt_client_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

mqtt_cpp uses std::variant or boost::variant internally. If you define the preprocessor macro MQTT_STD_VARIANT then std::variant is chosen, otherwise boost::variant is chosen.

If you use boost::variant, you need to include mqtt/config.hpp prior to the boost headers inclusion becausse it defines boost configuration macros. When you use mqtt_client_cpp.hpp and/or mqtt_server_cpp.hpp, they include mqtt/config.hpp internally.

Experimental feature

In include/mqtt/broker, there are header files to implement mqtt broker. It is an experimental feature. It would frequently updated. Even if the broker interface would be changed, major version won't be updated.

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.

Boost Software License - Version 1.0 - August 17th, 2003 Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
README
BSL-1.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/dev_gitee/mqtt_cpp.git
git@gitee.com:dev_gitee/mqtt_cpp.git
dev_gitee
mqtt_cpp
mqtt_cpp
master

搜索帮助