LinuxCommandLibrary

mosquitto_pub

publishes messages to an MQTT broker

TLDR

Publish message to topic

$ mosquitto_pub -t [topic] -m "[message]"
copy
Publish to remote broker
$ mosquitto_pub -h [broker.example.com] -t [topic] -m "[message]"
copy
Publish with authentication
$ mosquitto_pub -h [host] -u [user] -P [password] -t [topic] -m "[message]"
copy
Publish file contents
$ mosquitto_pub -t [topic] -f [file.txt]
copy
Publish with QoS
$ mosquitto_pub -t [topic] -m "[message]" -q [1]
copy
Publish retained message
$ mosquitto_pub -t [topic] -m "[message]" -r
copy

SYNOPSIS

mosquitto_pub [options]

DESCRIPTION

mosquitto_pub publishes messages to an MQTT broker. It's part of the Mosquitto package.
The tool sends single messages. Supports authentication, TLS, and various QoS levels.

PARAMETERS

-h HOST

MQTT broker hostname.
-t TOPIC
Topic to publish to.
-m MESSAGE
Message payload.
-u USER
Username.
-P PASSWORD
Password.
-q QOS
Quality of service (0, 1, 2).
-r
Retain message.
--help
Display help information.

CAVEATS

Part of mosquitto-clients. Requires broker access. Default QoS is 0.

HISTORY

mosquitto_pub is the publishing client distributed with the Eclipse Mosquitto MQTT broker.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community