Your company here ā€” click to reach over 10,000 unique daily visitors

sub - Man Page

subscribe to MQTT topics


sub [Options]


sub connects to the given MQTT broker and subscribes to all topics specified. Messages received on a topic are printed to stdout, prefixed with the topic the message was received on.

All options can be passed either as command-line arguments or can be specified in a simple config file.



automatically reconnect when connection is lost

-broker URL

broker address (should be in the form of a URL)

-ca-root FILE

path to a FILE containing CA certificates (optional)

-cert-file FILE

authenticate with a certificate


discard any pending messages from the broker (default true)

-client-id STRING

unique identifier for this client (defaults to a semi-random string)


automatically retry initial connection to broker

-connect-retry-interval DURATION

wait DURATION between initial connection attempts (default 30s)

-config FILE

path to FILE containing configuration values (optional)

-header KEY=VALUE

set an HTTP header (in KEY=VALUE form) (can be specified multiple times)

-key-file FILE

authenticate with a private key

-password STRING

authenticate with a password


quality of service for messages

-tls-alpn STRING

ALPN value to include in the TLS handshake (can be specified multiple times)

-topic STRING

topic to publish or subscribe to (can be specified multiple times)

-username STRING

authenticate with a username


increase output


print version


Any option may be specified as a value in a configuration file instead of (or in addition to) a command-line option. Values present on the command-line take precedent over values in the configration file. Thus it is easy to create a base configration file that can be augmented easily at run time.

The configuration file takes the form of a simple space-separated "option value" format (i.e. "broker tcp://test.mosquitto.org:1883").


Connect to a broker anonymously and subscribe to two topics.

sub -broker tcp://test.mosquitto.org:1883 -topic mqttcli/pubtest -topic mqttcli/pubtest1

Connect to a broker using username/password authentication and subscribe to a topic.

sub -broker tcp://test.mosquitto.org:1884 -username ro -password readonly -topic mqttcli/pubtest


Link Dupont <link@sub-pop.net>