
wolfMQTT - MQTT Client Library Encyclopedia
The wolfMQTT library is an MQTT client implementation written in C for embedded use. It supports SSL/TLS via the wolfSSL library. It was built from the ground up to be multi-platform, space conscience and extensible. It supports all Packet Types, all Quality of Service (QoS) levels 0-2 and supports SSL/TLS using the wolfSSL library. This implementation supports the MQTT v3.1.1, MQTT v5.0 and MQTT-SN v1.2 specifications.
Why Use wolfMQTT Client Library?
wolfMQTT | |
---|---|
Language | C |
License | GPL v2 |
Website | wolfssl.com/products/wolfmqtt/ |
API Style | Blocking or Non-Blocking |
Description
The wolfMQTT library was created in October 2015 due to many requests from wolfSSL customers for us to have an MQTT client library with TLS support.
Features
Feature | |
---|---|
MQTT 3.1 | ![]() |
MQTT 3.1.1 | ![]() |
MQTT 5.0 | ![]() |
MQTT-SN v1.2 | ![]() |
LWT | ![]() |
Automatic Reconnect | ![]() |
Feature | |
---|---|
QoS 0 | ![]() |
QoS 1 | ![]() |
QoS 2 | ![]() |
Authentication | ![]() |
Throttling | ![]() |
SSL/TLS | ![]() |
Additional Features
- Built from scratch by wolfSSL engineers
- Supports MQTT v3.1.1 specification
- Support for MQTT v5.0
- Support for MQTT Sensor Network (MQTT-SN) v1.2
- Supports all client side packet types and protocol options
- QoS Levels 0-2 (guarenteed delivery)
- Supports plain TCP or TLS (via the wolfSSL library)
- Single threaded model and single message callback
- Written in Native C89 with portability/compatibility in mind
- Space conscience design (Compiled size is about 3.6KB)
- User manual with build instructions, example overview and API documentation
- Example MQTT client implementations
- Network interface is abstracted via callbacks for extensibility
- Packet parsing encoding/decoding structured for custom use
- Minimal external dependencies (strlen, memcpy, memset) (overridable macros)
- Detailed error checking/handling
- Doxygen style inline documentation
- Less than 1200 lines of well structured C code
- Tested on multiple variants of MQTT broker servers, QoS levels 0-2 with/without TLS.
- Tested on Linux, Mac OS X and Freescale Kinetis K64.
- Inherits wolfSSL library features such as lightweight TLS using ChaCha20/Poly1305 AEAD, small size and portability.
- Open source (GPLv2)
- Support for FreeRTOS+TCP
- Includes an example Arduino IDE project
- IBM Watson IoT example with an IBM developer recipe.
\
Usage
Installation
The most recent version can be downloaded from the GitHub website here:
Either click the “Download ZIP” button or use the command
git clone git@github.com:wolfSSL/wolfMQTT.git
When building on Linux, *BSD, OS X, Solaris, or other *nix-like systems, use the autoconf system. To build wolfMQTT you only need to run three commands:
|
|
When building on Windows there is a Visual Studio 2015 solution included.
For additional help see the wolfMQTT User Manual:
Connect
|
|
Encodes and sends the MQTT Connect packet and waits for the Connect Acknowledgement packet. This is a blocking function that will wait for MqttNet.read data.
Return Values:
|
|
Parameters:
|
|
Example:
|
|
Connect with LWT
See Connect example above.
Connect with Username / Password
See Connect example above.
Publish
|
|
Encodes and sends the MQTT Publish packet and waits for the Publish response (if QoS > 0). This is a blocking function that will wait for MqttNet.read data. If QoS level = 1 then will wait for PUBLISH_ACK. If QoS level = 2 then will wait for PUBLISH_REC then send PUBLISH_REL and wait for PUBLISH_COMP.
Return Values:
|
|
Parameters:
|
|
Example:
|
|
Publish a retained message
See publish example. Set publish.retain = 1.
Subscribe
|
|
Encodes and sends the MQTT Subscribe packet and waits for the Subscribe Acknowledgement packet. This is a blocking function that will wait for MqttNet.read data
Return Values: See
|
|
|
|
|
|
Parameters:
|
|
Example:
|
|
Unsubscribe
|
|
Encodes and sends the MQTT Unsubscribe packet and waits for the Unsubscribe Acknowledgement packet. This is a blocking function that will wait for MqttNet.read data
.
Return Values: See
|
|
|
|
|
|
Parameters:
|
|
Example:
|
|
Disconnect
|
|
Encodes and sends the MQTT Disconnect packet (no response).
Return Values: See enum
|
|
|
|
Parameters:
|
|
Example:
|
|
Using SSL / TLS
|
|
Full example application
|
|
About David Garske
Thanks for this guest blog postDavid Garske works for wolfSSL and has been in IoT embedded software development since 2005. wolfSSL, founded in 2004, is an Open Source Internet security company with products including the wolfSSL embedded SSL/TLS library, wolfCrypt crypto engine, SSL Inspection, and wolfMQTT.