sub - Man Page

subscribe to MQTT topics

Synopsis

sub [Options]

Description

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.

Options

-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

-clean

discard any pending messages from the broker (default true)

-client-id STRING

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

-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

-qos INTEGER

quality of service for messages

-topic STRING

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

-username STRING

authenticate with a username

-verbose

increase output

Configuration

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").

Examples

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

Author

Link Dupont <link@sub-pop.net>

Author.

Info

07/21/2022