Command-line reference
mqtt_client_sample [options]
Note
This is not a comprehensive option list. Run mqtt_client_sample --help
to view all options.
Connection options
Flag | Description | Default |
---|---|---|
| Broker host name or IP. | — |
| Broker port. | 1883 |
| Protocol version. | 5 |
| Client identifier (generated UUID if omitted). | — |
| Keep‑alive interval. | 0 (disabled) |
| Select TCP or TLS. | TCP |
| HTTP/HTTPS forward proxy. | — |
| Display payload bytes in hexadecimal. | Off |
| Show built‑in help. | — |
Session control
Flag | Purpose |
---|---|
| Start a new session. |
| Persist the session after disconnect ( |
Subscribe / unsubscribe
Flag | Description |
---|---|
| Add a subscription (repeatable). |
| Send one SUBSCRIBE per filter. |
| Ignore messages published by this client (MQTT 5). |
| Preserve retain flag on incoming messages (MQTT 5). |
| Control retained message delivery (MQTT 5). |
| Remove a subscription (repeatable). |
| Send one UNSUBSCRIBE per filter. |
Publish
Flag | Description | Default |
---|---|---|
| Topic for the next message (repeatable). | — |
| Payload text for the most‑recent topic. | — |
| Payload file for the most‑recent topic. | — |
| QoS for the most‑recent message. | 0 |
| Set the retain flag. | Off |
Last‑will message
Flag | Description |
---|---|
| Will topic. |
| Will payload. |
| Will QoS. |
| Retain the will message. |
Property flags (MQTT 5)
Packet | Flag prefix |
---|---|
CONNECT |
|
PUBLISH |
|
SUBSCRIBE |
|
UNSUBSCRIBE |
|
DISCONNECT |
|
WILL |
|
Example
--mqtt_connect_properties receive_maximum 32 --mqtt_publish_properties topic_alias 3
TLS options
Flag | Description |
---|---|
| CA bundle for server verification. |
| Skip certificate verification (test only). |
| Client certificate (mutual TLS). |
| Private key for |
Example commands
Minimal publish (plain TCP)
mqtt_client_sample \ --mqtt_servername broker.hivemq.com \ --mqtt_port 1883 \ --mqtt_pub_topic sensors/temp \ --mqtt_pub_message 22.5 \ --mqtt_clean_start
TLS subscribe with advanced options
mqtt_client_sample \ --mqtt_servername broker.hivemq.com \ --mqtt_port 8883 \ --mqtt_transport SSL \ --ssl_ca_file /etc/ssl/certs/ca-bundle.crt \ --mqtt_sub_topic alerts/# \ --mqtt_sub_topic_no_local_option \ --mqtt_sub_topic_retain_handling 1 \ --mqtt_clean_start