• Stars
    star
    625
  • Rank 71,862 (Top 2 %)
  • Language
    C
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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, with a very concise The API interface realizes the quality of service of QOS2 with very few resources, and seamlessly connects the mbedtls encryption library.

license

中文说明

mqttclient

A high-performance, high-stability, cross-platform 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.gitee.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.gitee.io/mqtt/index.html

Online code generation tool

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.

Overall Frame

  • 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://github.com/jiejieTop/mqttclient
TencentOS tiny https://github.com/Tencent/TencentOS-tiny/tree/master/board/Fire_STM32F429
TencentOS tiny AT framework https://github.com/jiejieTop/gokit3-board-mqttclient
RT-Thread https://github.com/jiejieTop/kawaii-mqtt
FreeRTOS https://github.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:

More Repositories

1

ButtonDrive

纯C语言实现的一个按键驱动,可移植性强,支持单双击、连按、连按释放、长按;采用回调处理按键事件(自定义消抖时间),使用只需3步,1:创建按键,2:按键事件与回调处理函数链接映射。然后周期检查按键。
C
325
star
2

cmd-parser

一个非常简单好用的命令解析器,占用资源极少极少,采用哈希算法超快匹配命令!
C
306
star
3

http-client

A high-performance, high-stability, cross-platform HTTP client.
C
176
star
4

DoraOS

DoraOS 是我个人所写的RTOS内核,结合FreeRTOS、uCOS, RT-Thread, LiteOS 的特性所写,取其精华,去其糟粕,本项目将持续维护,欢迎大家fork与star。
C
142
star
5

TencentOS-Demo

这是在野火stm32f103开发板上移植的TencentOS tiny 例程,带图文教程与视频教程
C
106
star
6

kawaii-mqtt

基于socket API的MQTT客户端,以极少的资源实现qos2服务质量,并且实现mbedtls支持,此仓库是专门为RT-Thread做的软件包,原始仓库位于:https://github.com/jiejieTop/mqttclient
C
64
star
7

libuv-learning-code

libuv系列教程的配套代码,从0到深度了解libuv的框架与使用。
C
28
star
8

stm32_kfifo

基于Linux的kfifo移植到STM32
C
26
star
9

salof

Synchronous Asynchronous Log Output Framework(同步异步日志输出框架)
C
19
star
10

wx-mqtt

MQTT客户端-微信小程序源码,使用ColorUI!
JavaScript
17
star
11

freertos-mqttclient

a demo of mqttclient on freertos platform,https://github.com/jiejieTop/mqttclient
C
17
star
12

STM32F1_Demo

STM32F1_DEMO is a project demo based on the EmbedFire stm32Ba Dao development version.
C
16
star
13

LwIP_2.1.2_Comment

LwIP 2.1.2 版本的源码中文注释
C
14
star
14

xiexiren_ppt

谢希仁老师的计算机网络PPT讲义
13
star
15

Serial

基于C#的串口调试助手
C#
7
star
16

rtpkg_button

rtt packages button drive
C
6
star
17

online-mqtt-tool

一个在线mqtt代码生成工具,https://jiejietop.github.io/online-mqtt-tool
JavaScript
5
star
18

doralib

Easy to use C++ library
C++
5
star
19

i.mx6ul_board

This is an linux demo code for the i.mx6ul development board.
C
5
star
20

LwIP_Demo

LwIP-Demo
C
4
star
21

linux_learn

This is my repository for learning Linux.
C
4
star
22

RT-Thread_Demo

RT-Thread在STM32F1的移植Demo
C
3
star
23

Qt-Demo

This is my demo of learning Qt 5.12
C++
3
star
24

book

这是一个存放计算机相关书籍的仓库
3
star
25

mqttclient-demo

多个开发板中的MQTT客户端demo程序,支持多个平台。
Batchfile
3
star
26

http_server

my http server source!
C
2
star
27

c-plus-plus

record my c++ learning
C++
2
star
28

linux-script-tools

some linux script tools
Shell
2
star
29

WeChat_APP

WeChat APP learning
JavaScript
2
star
30

cross-compiling-scripts

some scripts tocross-compiling the base library.
Shell
2
star
31

Fire_LiteOS

华为LiteOS在野火开发板上的移植实验
C
2
star
32

cmake

学习cmake
CMake
2
star
33

RT_Thread_PPT

RT_Thread_PPT
1
star
34

LiteOS_Demo

LiteOS_Demo
C
1
star
35

linux-network

this is the network programming code under linux
Makefile
1
star
36

kawaii-http

C
1
star
37

gokit3-board-mqttclient

机智云gokit3开发板的mqttclient demo,使用TencentOS tiny的AT框架,RAM占用不足15k。
C
1
star
38

Balance-car

平衡直立车设计
1
star
39

pyqt5

这是一个pyqt5的终端监控小工程
Python
1
star
40

FreeRTOS-Demo

FreeRTOS在野火stm32上的移植
C
1
star