mqtt-cli(1)
A command-line interface for interacting with MQTT brokers, allowing publish/subscribe operations and broker management.
Synopsis
mqtt-cli [OPTION]... COMMAND [ARGS]...Description
mqtt-cli is a versatile command-line tool for working with MQTT message brokers. It supports both MQTT 3.1.1 and MQTT 5.0 protocols, enabling users to publish messages, subscribe to topics, inspect broker information, and manage client connections without writing code.
Common operations include connecting to a broker, publishing test messages to verify connectivity, subscribing to topics for monitoring, and debugging MQTT-based systems. It supports secure connections via TLS/SSL and authentication with username/password or client certificates.
Common options
| Flag | What it does |
|---|---|
-h, --help | Show help message and exit |
-v, --version | Display version information |
-b, --broker | Specify broker address (e.g., tcp://localhost:1883) |
-u, --username | Set username for broker authentication |
-pw, --password | Set password for broker authentication |
--cafile | Path to CA certificate file for TLS verification |
--cert | Path to client certificate file for mutual TLS |
--key | Path to client private key file for mutual TLS |
-i, --identifier | Set MQTT client identifier/ID |
-q, --qos | Set Quality of Service level (0, 1, or 2) |
-r, --retained | Publish message as retained |
-t, --topic | Specify MQTT topic |
Examples
Publish a temperature reading to a topic on the specified broker
mqtt-cli pub -b tcp://broker.example.com:1883 -t 'home/temperature' -m '22.5'Subscribe to all sensor data using wildcard pattern, displaying received messages
mqtt-cli sub -b tcp://localhost:1883 -t 'sensors/+/data'Publish a message using broker credentials for authentication
mqtt-cli pub -b tcp://localhost:1883 -u user -pw password -t 'test' -m 'Hello MQTT'Subscribe to alerts over secure TLS connection with CA certificate verification
mqtt-cli sub -b mqtts://broker.example.com:8883 -t 'alerts/#' --cafile /etc/ssl/certs/ca.pemPublish a retained message so new subscribers immediately receive the current value
mqtt-cli pub -b tcp://localhost:1883 -t 'config/mode' -m 'auto' -rSubscribe to system topic showing connected clients with QoS 1
mqtt-cli sub -b tcp://localhost:1883 -t '$SYS/broker/clients/+' -q 1