mosquitto_pub 1 Mosquitto Project Commands
mosquitto_pub an MQTT version 5/3.1.1/3.1 client for publishing simple messages
`mosquitto_pub` options `-t` topic payload-options `options:`
auth-options connection-options misc-options mqtt-options output-options publish-options tls-certificate-options tls-psk-options `auth-options:`
`-u` username `-P` password `connection-options`
`-h` hostname `--unix` socket path `-p` port-number `-L` URL
`-A` bind-address `--nodelay` `-S` `--ws`
`--proxy` socks-url `misc-options:`
`-o` config-file `mqtt-options:`
`-c` `-D` command identifier value `-i` client-id `-I` client-id-prefix `-k` keepalive-time `-x` session-expiry-interval `-V` protocol-version
`output-options:`
`-d` `--quiet` `payload-options:`
`-f` file `-l` `-m` message `-n` `-s` `publish-options:`
`-q` message-QoS `-r` `--repeat` count `--repeat-delay` seconds `mosquitto_pub` `--help`

## Description

`mosquitto_pub` is a simple MQTT version 5/3.1.1 client that will publish a single message on a topic and exit.

## Options

&options-intro;

### The options

`-l`
`--stdin-line`

  Send messages read from stdin, splitting separate lines into separate messages.

`-q`
`--qos`

  Specify the quality of service to use for the message, from 0, 1 and 2. Defaults to 0.

`-r`
`--retain`

  If retain is given, the message will be retained as a "last known good" value on the broker. See mqtt 7 for more information. Note that zero length payloads are never retained. If you send a zero length payload retained message it will clear any retained message on the topic.

`--repeat`

  If the publish mode is`-m`, `-f`, or `-s` (i.e. the modes where only a single message is sent), then `--repeat` can be used to specify that the message will be published multiple times.

  See also `--repeat-delay`.

`--repeat-delay`

  If using `--repeat`, then the default behaviour is to publish repeated messages as soon as the previous message is delivered. Use `--repeat-delay` to specify the number of seconds to wait after the previous message was delivered before publishing the next. Does not need to be an integer number of seconds.

  Note that there is no guarantee as to the actual interval between messages, this option simply defines the minimum time from delivery of one message to the start of the publish of the next.

`-t`
`--topic`

  The MQTT topic on which to publish the message. See mqtt 7 for more information on MQTT topics.

## Properties

The `-D` / `--property` option allows adding properties to different stages of the mosquitto_pub run. The properties supported for each command are as follows:

## Examples

Publish temperature information to localhost with QoS 1:

- mosquitto_pub `-t` sensors/temperature `-m` 32 `-q` 1

Publish timestamp and temperature information to a remote host on a non-standard port and QoS 0:

- mosquitto_pub `-h` 192.168.1.1 `-p` 1885 `-t` sensors/temperature `-m` "1266193804 32"

Publish light switch status. Message is set to retained because there may be a long period of time between light switch events:

- mosquitto_pub `-r` `-t` switches/kitchen_lights/status `-m` "on"

Send the contents of a file in two ways:

- mosquitto_pub `-t` my/topic `-f` ./data

- mosquitto_pub `-t` my/topic `-s` < ./data

Send parsed electricity usage data from a Current Cost meter, reading from stdin with one line/reading as one message:

- read_cc128.pl | mosquitto_pub `-t` sensors/cc128 `-l`

Power on an appliance using zigbee2mqtt and an appropriately configured power socket:

- mosquitto_pub `-t` zigbee2mqtt/power-microwave/set `-m` '{"state":"ON"}'

## Files

`$XDG_CONFIG_HOME/mosquitto_pub`
`$HOME/.config/mosquitto_pub`
`$HOME/snap/mosquitto/current/.config/mosquitto_pub` (for snap installs)

  Configuration file for default options.

## See Also

- mosquitto 7
- mqtt 7
- mosquitto_rr 1
- mosquitto_sub 1
- mosquitto 8
- libmosquitto 3
- mosquitto-tls 7

## Author

Roger Light roger@atchoo.org