mqttclient

2025-12-07 0 970

中文说明

mqttclient

A highperformance, high-stability, crossplatform MQTT client

A high-performance, high-stability, cross-platform MQTT client, developed based on the socket API, can be used on embedded devices (FreeRTOS/LiteOS/RT-Thread/TencentOS tiny), Linux, Windows, Mac, and has a very concise The API interface realizes the quality of service of QOS2 with very few resources, and seamlessly connects the mbedtls encryption library.

Advantage:

  • Extremely high stability: Whether it is drop and reconnect, packet loss and retransmission, it is strictly abide by the MQTT protocol standard, in addition to The test of large data volume is very stable whether it is receiving or sending, and the high frequency test is also very stable.

  • Lightweight: The entire code project is extremely simple. Without mbedtls, it takes up very few resources. The author used the esp8266 module to communicate with the cloud. The entire project code consumes less than 15k of RAM.

  • Support mbedtls encrypted transmission, make the network transmission more secure, and the interface layer does not require users to care, no matter whether it is encrypted or not, mqttclient is fixed for the API interface provided by the user, which is very compatible A set of codes on behalf of the application layer can be transmitted with or without encryption.

  • Supports multiple clients, compatible with multiple clients running at the same time, one device connected to multiple servers.

  • Supports synchronous and asynchronous processing, applications need not block and wait to waste CPU resources.

  • Support interceptor configuration, on some platforms, the client will automatically subscribe to the system theme by default, and the theme from the server changes every time. In this case, you need to use an interceptor to intercept and separate the theme and data Information and deliver it to users, greatly improving flexibility.

  • With online code generation tool, the code can be generated with extremely simple configuration, address: https://jiejietop.g*i**tee.io/mqtt/index.html

  • Has a very simple API interface, in general, mqttclient configuration has default values, basically can be used without configuration, can also be arbitrarily configured, the configuration has robustness detection, so designed The API interface is also very simple.

  • Multifunctional parameters can be configured and tailored, reconnect time interval, heartbeat period, maximum number of subscriptions, command timeout, read and write buffer size, interceptor processing, etc. Parameters can be tailored and configurable to meet the needs of developers Complex and simple to use in various development environments.

  • Support automatic re-subscription of topics, after automatic reconnection to ensure that the topics will not be lost.

  • Support theme wildcards \”\”#\”, \”+\”`.

  • Subscribed topics are completely separated from message processing, making programming logic easier and easier to use, users don’t have to deal with intricate logical relationships.

  • The keep-alive processing mechanism has been implemented in mqttclient, without the user having to deal with the psychological experience, the user only needs to concentrate on the application function.

  • Has a very good design, designed the recording mechanism with very few resources, and retransmits the message when it is lost to ensure that the qos1 and qos2 service quality levels guarantee its service quality.

  • There are very good code styles and ideas: The whole code adopts a layered design, and the code implementation adopts the idea of ​​asynchronous processing to reduce coupling and improve performance.

  • Developed on top of standard BSD socket, as long as it is compatible with BSD socket system.

  • Seamless connection of salof: It is a synchronous and asynchronous log output framework. It outputs the corresponding log information when it is idle, and it can also write the information into flash to save it, which is convenient for debugging.

  • Use the famous paho mqtt library package.

  • No other dependencies.

Online code generation tool

This project has a code generation tool that only requires online configuration to generate code, which is extremely simple and easy to use. The code generation tool address is: https://jiejietop.g*i**tee.io/mqtt/index.html

occupied resource size

A total of 10857 bytes of ROM, and the overhead of RAM is almost only dependent on dynamic memory. Without using TLS encrypted transmission, the communication dynamic memory that maintains the QOS0 quality of service level requires only about 3694 bytes. Including 1024 read buffer + 1024 write buffer + 1024 internal thread stack size, compared with other MQTT clients, mqttclient requires very little RAM resource overhead.

Code RO Data RW Data ZI Data Object Name
7118 791 0 0 mqttclient.o
546 0 0 0 mqttconnectclient.o
212 0 0 0 mqttdeserializepublish.o
476 0 4 0 mqttpacket.o
236 0 0 0 mqttserializepublish.o
310 0 0 0 mqttsubscribeclient.o
38 0 0 0 mqttunsubscribeclient.o
56 0 0 0 nettype_tcp.o
62 0 0 0 network.o
24 0 0 0 platform_memory.o
40 0 0 0 platform_mutex.o
344 0 0 0 platform_net_socket.o
94 0 0 0 platform_thread.o
70 0 0 0 platform_timer.o
246 0 4 0 random.o
62 0 0 0 mqtt_list.o
10066 791 8 0 total

Overall framework

Has a very clear layered framework.

  • At the top of the framework is the API function interface, which implements the client\’s application, release, set parameters, connect to the server, disconnect, subscribe topic, unsubscribe topic, publish message and other functional interfaces.

  • The famous paho mqtt library is used as the MQTT message packet library.

  • Asynchronous processing mechanism is used to manage all the acks. It does not need to wait for the server\’s response when sending the message, but only records it. After receiving the server\’s ack, cancel this record, very efficient; and When the mqtt message (QoS1/QoS2) is sent and no response is received from the server, the message will be retransmitted.

  • An mqtt yield thread is implemented internally to handle all content in a unified manner, such as timeout processing, ack message processing, and receiving publish message from the server, at this time the callback function will be called Inform the user of the data received, *post release, post completion message processing, heartbeat message (keep alive), when disconnected from the server, you need to try to reconnect, resubscribe to the topic, resend the message or reply *Wait.

  • Message processing, such as reading and writing messages, decoding mqtt messages, setting messages (dup flag), destroying messages and other operations.

  • network is a network component, which can automatically select a data channel, if it is an encryption method, tls encryption is used for data transmission, and tls can choose mbedtls as the encryption backend; it can also be The tcp direct connection method is ultimately transmitted via tcp.

  • platform is a platform abstraction layer that encapsulates things from different systems, such as socke or AT, thread, time, mutex, memory management**, these are dealing with the system and are also necessary for cross-platform Package.

  • On the far right is the general content, list processing, log library, error handling, software random number generator, etc.

Supported platforms

At present, Linux, TencentOS tiny, FreeRTOS, RT-Thread platforms have been implemented (software package is named kawaii-mqtt`), in addition to TencentOS tiny AT framework can also be used, and the stability is excellent!

Platform Code Location
Linux https://g*i*t*hub.com/jiejieTop/mqttclient
TencentOS tiny https://*githu*b.c*om/Tencent/TencentOS-tiny/tree/master/board/Fire_STM32F429
TencentOS tiny AT framework https://git*h*ub.*com/jiejieTop/gokit3-board-mqttclient
RT-Thread https://gi*thu*b.c*om/jiejieTop/kawaii-mqtt
FreeRTOS https://gith*u*b*.com/jiejieTop/freertos-mqttclient

Version

Release Version Description
[v1.0.0] Initial release, complete basic framework and stability verification
[v1.0.1] Fix the logical processing when actively disconnecting from the server
[v1.0.2] Add a new feature-interceptor, fix some small bugs
[v1.0.3] To avoid global pollution, modify the naming of log and list related functions
[v1.0.4] Network structure and mbedtls data channel readjusted
[v1.1.0] A larger version of the update, refactoring part of the code, optimizing the logic of MQTT processing, improving the overall stability, supporting multiple clients, supporting setting the will, optimizing the API interface, and adding multiple cloud platforms Test code and documentation, add online code generation tool, online cutting configuration tool

question

Welcome to submit issues and bug reports in the form of GitHub Issues

Copyright and License

mqttclient follows the Apache License v2.0 open source agreement. Encourage code sharing and respect the copyright of the original author. You can freely use and modify the source code, or you can publish the modified code as open source or closed source software.

Test and use under Linux platform

Install cmake:

    sudo apt-get install cmake g++

test program

Test Platform Location
emqx (my privately deployed server) ./test/emqx/test.c
Baidu Tiangong ./test/baidu/test.c
onenet ./test/onenet/test.c
Alibaba Cloud Internet of Things ./test/ali/test.c

Compile & Run

    ./build.sh

After running the build.sh script, the executable files emqx, baidu, onenet and other platforms will be generated under the ./build/bin/ directory Executable programs can be run directly.

    ./build/bin/emqx

Compile into a dynamic library libmqttclient.so

    ./make-libmqttclient.sh

After running the make-libmqttclient.sh script, a dynamic library file libmqttclient.so will be generated in the ./libmqttclient/lib directory, and installed into the system’s /usr/lib directory, the relevant header files have been Copy to the ./libmqttclient/include directory and copy it to your project. You only need to link the dynamic library when compiling the application. -lmqttclient -lpthread, the configuration file of the dynamic library is based on ./test/mqtt_config.h configuration.

If you are using a cross-compiler, you should export the corresponding environment variables according to the compiler you are using (the cross-compiler used here is arm-linux-gnueabihf-gcc), and you must also set the dynamic library file libmqttclient .so is copied to the /usr/lib directory of your embedded system:

    export CROSS_COMPILE=arm-linux-gnueabihf-

If you need to uninstall libmqttclient.so, execute the following command:

    ./make-libmqttclient.sh remove

Learn more

Please see the documentation:

  • MQTT Protocol Introduction

  • MQTT protocol communication process

  • mqttclient code generation tool

  • mqttclient configuration and cutting tool

  • mqttclient design and implementation

  • mqttclient connects to Baidu Tiangongwu Access

  • mqttclient connects to OneNET cloud platform

  • mqttclient connects to Alibaba Cloud IoT platform

下载源码

通过命令行克隆项目:

git clone https://github.com/jiejieTop/mqttclient.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 开发教程 mqttclient https://www.zuozi.net/31519.html

JavaStud
上一篇: JavaStud
identityazuretable
下一篇: identityazuretable
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务