Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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 encryp…

License

NotificationsYou must be signed in to change notification settings

jiejieTop/mqttclient

Repository files navigation

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 isdrop and reconnect,packet loss and retransmission, it isstrictly abide by the MQTT protocol standard, in addition to The test oflarge data volume is very stable whether it is receiving or sending, and thehigh 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 isfixed 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 therecording 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 of10857 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 about3694 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.

CodeRO DataRW DataZI DataObject Name
711879100mqttclient.o
546000mqttconnectclient.o
212000mqttdeserializepublish.o
476040mqttpacket.o
236000mqttserializepublish.o
310000mqttsubscribeclient.o
38000mqttunsubscribeclient.o
56000nettype_tcp.o
62000network.o
24000platform_memory.o
40000platform_mutex.o
344000platform_net_socket.o
94000platform_thread.o
70000platform_timer.o
246040random.o
62000mqtt_list.o
-----
1006679180total

Overall framework

Has a very clear layered framework.

Overall Frame

  • At the top of the framework is theAPI function interface, which implements the client'sapplication, release, set parameters, connect to the server, disconnect, subscribe topic, unsubscribe topic, publish message and other functional interfaces.

  • The famouspaho 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 beretransmitted.

  • Anmqtt yield thread is implemented internally to handle all content in a unified manner, such astimeout 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 asreading and writing messages, decoding mqtt messages, setting messages (dup flag), destroying messages and other operations.

  • network is a network component, which canautomatically 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 Thetcp 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!

PlatformCode Location
Linuxhttps://github.com/jiejieTop/mqttclient
TencentOS tinyhttps://github.com/Tencent/TencentOS-tiny/tree/master/board/Fire_STM32F429
TencentOS tiny AT frameworkhttps://github.com/jiejieTop/gokit3-board-mqttclient
RT-Threadhttps://github.com/jiejieTop/kawaii-mqtt
FreeRTOShttps://github.com/jiejieTop/freertos-mqttclient

Version

Release VersionDescription
[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 ofGitHub Issues

Copyright and License

mqttclient follows theApache 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 PlatformLocation
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 thebuild.sh script, the executable filesemqx,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 themake-libmqttclient.sh script, a dynamic library filelibmqttclient.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 filelibmqttclient .so is copied to the/usr/lib directory of your embedded system:

export CROSS_COMPILE=arm-linux-gnueabihf-

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

    ./make-libmqttclient.sh remove

Learn more

Please see the documentation:

About

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 encryp…

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp