|
| 1 | +========================================== |
| 2 | +``paho_mqtt`` Eclipse Paho MQTT C Library |
| 3 | +========================================== |
| 4 | + |
| 5 | +The ``paho_mqtt`` package provides integration of the Eclipse Paho MQTT C |
| 6 | +library into NuttX. This library enables MQTT client functionality, supporting |
| 7 | +MQTT protocol versions 3.1, 3.1.1, and 5.0. The package includes both a library |
| 8 | +for programmatic access and command-line utilities for publishing and |
| 9 | +subscribing to MQTT topics. |
| 10 | + |
| 11 | +Overview |
| 12 | +======== |
| 13 | + |
| 14 | +The Eclipse Paho MQTT C library is a client implementation of the MQTT |
| 15 | +protocol. It provides both synchronous and asynchronous APIs for connecting to |
| 16 | +MQTT brokers, publishing messages, and subscribing to topics. |
| 17 | + |
| 18 | +This NuttX integration includes: |
| 19 | + |
| 20 | +- **MQTT 5.0 Client Library** (``LIB_MQTT5``): A library providing MQTT client |
| 21 | + functionality through C API calls. |
| 22 | + |
| 23 | +- **Command-line Tools** (``UTILS_MQTT5``): |
| 24 | + - ``mqtt_pub``: A utility for publishing messages to MQTT topics |
| 25 | + - ``mqtt_sub``: A utility for subscribing to MQTT topics and receiving messages |
| 26 | + |
| 27 | +The library is automatically downloaded from the Eclipse Paho GitHub repository |
| 28 | +during the build process if not already present. |
| 29 | + |
| 30 | +Configuration |
| 31 | +============= |
| 32 | + |
| 33 | +Library Configuration |
| 34 | +--------------------- |
| 35 | + |
| 36 | +Enable the MQTT 5.0 library: |
| 37 | + |
| 38 | +.. code-block:: kconfig |
| 39 | +
|
| 40 | + CONFIG_LIB_MQTT5=y |
| 41 | +
|
| 42 | +Utility Configuration |
| 43 | +--------------------- |
| 44 | + |
| 45 | +Enable the MQTT command-line utilities: |
| 46 | + |
| 47 | +.. code-block:: kconfig |
| 48 | +
|
| 49 | + CONFIG_UTILS_MQTT5=y |
| 50 | + CONFIG_UTILS_MQTT5_PRIORITY=100 |
| 51 | + CONFIG_UTILS_MQTT5_STACKSIZE=16384 |
| 52 | +
|
| 53 | +Configuration Options |
| 54 | +--------------------- |
| 55 | + |
| 56 | +- ``CONFIG_LIB_MQTT5``: Enable the MQTT 5.0 client library |
| 57 | +- ``CONFIG_UTILS_MQTT5``: Enable MQTT command-line utilities (requires |
| 58 | + ``CONFIG_LIB_MQTT5``) |
| 59 | +- ``CONFIG_UTILS_MQTT5_PRIORITY``: Task priority for MQTT utilities (default: 100) |
| 60 | +- ``CONFIG_UTILS_MQTT5_STACKSIZE``: Stack size for MQTT utilities (default: 16384) |
| 61 | + |
| 62 | +Usage |
| 63 | +===== |
| 64 | + |
| 65 | +mqtt_pub - Publish Messages |
| 66 | +---------------------------- |
| 67 | + |
| 68 | +The ``mqtt_pub`` utility publishes messages to MQTT topics. |
| 69 | + |
| 70 | +mqtt_pub Syntax |
| 71 | +~~~~~~~~~~~~~~~ |
| 72 | + |
| 73 | +.. code-block:: bash |
| 74 | +
|
| 75 | + mqtt_pub [topicname] [options] |
| 76 | +
|
| 77 | +mqtt_pub Options |
| 78 | +~~~~~~~~~~~~~~~~ |
| 79 | + |
| 80 | +Connection Options: |
| 81 | + - ``-h, --host <host>``: MQTT broker hostname (default: localhost) |
| 82 | + - ``-p, --port <port>``: Network port (default: 1883) |
| 83 | + - ``-c, --connection <url>``: Connection string (overrides host/port) |
| 84 | + - ``-i, --clientid <id>``: Client ID (default: paho-c-pub) |
| 85 | + - ``-u, --username <user>``: Username for authentication |
| 86 | + - ``-P, --password <pass>``: Password for authentication |
| 87 | + - ``-k, --keepalive <seconds>``: Keepalive timeout (default: 10) |
| 88 | + |
| 89 | +Message Options: |
| 90 | + - ``-t, --topic <topic>``: MQTT topic to publish to |
| 91 | + - ``-m, --message <message>``: Message payload to send |
| 92 | + - ``-f, --filename <file>``: Read message from file |
| 93 | + - ``-q, --qos <0|1|2>``: Quality of Service level (default: 0) |
| 94 | + - ``-r, --retained``: Set retained message flag |
| 95 | + - ``-n, --null-message``: Send zero-length message |
| 96 | + |
| 97 | +MQTT Version: |
| 98 | + - ``-V, --MQTTversion <31|311|5>``: MQTT protocol version (default: 311) |
| 99 | + |
| 100 | +mqtt_pub Examples |
| 101 | +~~~~~~~~~~~~~~~~~ |
| 102 | + |
| 103 | +Publish a simple message: |
| 104 | + |
| 105 | +.. code-block:: bash |
| 106 | +
|
| 107 | + mqtt_pub -h 192.168.1.100 -t "test/topic" -m "Hello MQTT" |
| 108 | +
|
| 109 | +Publish with QoS 1 and retained flag: |
| 110 | + |
| 111 | +.. code-block:: bash |
| 112 | +
|
| 113 | + mqtt_pub -h 192.168.1.100 -t "test/topic" -m "Retained message" -q 1 -r |
| 114 | +
|
| 115 | +Publish from a file: |
| 116 | + |
| 117 | +.. code-block:: bash |
| 118 | +
|
| 119 | + mqtt_pub -h 192.168.1.100 -t "test/topic" -f message.txt |
| 120 | +
|
| 121 | +mqtt_sub - Subscribe to Topics |
| 122 | +------------------------------- |
| 123 | + |
| 124 | +The ``mqtt_sub`` utility subscribes to MQTT topics and receives messages. |
| 125 | + |
| 126 | +mqtt_sub Syntax |
| 127 | +~~~~~~~~~~~~~~~ |
| 128 | + |
| 129 | +.. code-block:: bash |
| 130 | +
|
| 131 | + mqtt_sub [topicname] [options] |
| 132 | +
|
| 133 | +mqtt_sub Options |
| 134 | +~~~~~~~~~~~~~~~~ |
| 135 | + |
| 136 | +Connection Options: |
| 137 | + - ``-h, --host <host>``: MQTT broker hostname (default: localhost) |
| 138 | + - ``-p, --port <port>``: Network port (default: 1883) |
| 139 | + - ``-c, --connection <url>``: Connection string (overrides host/port) |
| 140 | + - ``-i, --clientid <id>``: Client ID (default: paho-c-sub) |
| 141 | + - ``-u, --username <user>``: Username for authentication |
| 142 | + - ``-P, --password <pass>``: Password for authentication |
| 143 | + - ``-k, --keepalive <seconds>``: Keepalive timeout (default: 10) |
| 144 | + |
| 145 | +Subscription Options: |
| 146 | + - ``-t, --topic <topic>``: MQTT topic to subscribe to (supports wildcards) |
| 147 | + - ``-q, --qos <0|1|2>``: Quality of Service level (default: 0) |
| 148 | + - ``-R, --no-retained``: Do not print retained messages |
| 149 | + - ``--no-delimiter``: Do not use delimiter between messages |
| 150 | + - ``--delimiter <string>``: Custom delimiter (default: \\n) |
| 151 | + |
| 152 | +MQTT Version: |
| 153 | + - ``-V, --MQTTversion <31|311|5>``: MQTT protocol version (default: 311) |
| 154 | + |
| 155 | +Topic Wildcards |
| 156 | +~~~~~~~~~~~~~~~ |
| 157 | + |
| 158 | +- ``+``: Single-level wildcard (matches one topic level) |
| 159 | + - Example: ``sensor/+/temperature`` matches ``sensor/room1/temperature`` |
| 160 | +- ``#``: Multi-level wildcard (matches multiple levels, must be at end) |
| 161 | + - Example: ``sensor/#`` matches all topics under ``sensor/`` |
| 162 | + |
| 163 | +mqtt_sub Examples |
| 164 | +~~~~~~~~~~~~~~~~~ |
| 165 | + |
| 166 | +Subscribe to a topic: |
| 167 | + |
| 168 | +.. code-block:: bash |
| 169 | +
|
| 170 | + mqtt_sub -h 192.168.1.100 -t "test/topic" |
| 171 | +
|
| 172 | +Subscribe with wildcard: |
| 173 | + |
| 174 | +.. code-block:: bash |
| 175 | +
|
| 176 | + mqtt_sub -h 192.168.1.100 -t "sensor/#" |
| 177 | +
|
| 178 | +Subscribe with QoS 1: |
| 179 | + |
| 180 | +.. code-block:: bash |
| 181 | +
|
| 182 | + mqtt_sub -h 192.168.1.100 -t "test/topic" -q 1 |
| 183 | +
|
| 184 | +Library API |
| 185 | +=========== |
| 186 | + |
| 187 | +The MQTT 5.0 library provides both synchronous and asynchronous APIs. The main |
| 188 | +header files are: |
| 189 | + |
| 190 | +- ``MQTTAsync.h``: Asynchronous MQTT client API |
| 191 | +- ``MQTTClient.h``: Synchronous MQTT client API |
| 192 | + |
| 193 | +For detailed API documentation, refer to the Eclipse Paho MQTT C library |
| 194 | +documentation at https://www.eclipse.org/paho/clients/c/. |
0 commit comments