mosquitto_pub
A simple MQTT version 3.1.1 client that will publish a single message on a topic and exit. tldr-pages
On several platforms
Several platforms
Publish a temperature value of 32 on the topic sensors/temperature to 192.168.1.1 (defaults to localhost) with Quality of Service (QoS) set to 1
mosquitto_pub --host 192.168.1.1 --topic sensors/temperature --message 32 --qos 1IdentifyPublish timestamp and temperature data on the topic sensors/temperature to a remote host on a non-standard port
mosquitto_pub --host 192.168.1.1 --port 1885 --topic sensors/temperature --message "1266193804 32"IdentifyPublish light switch status and retain the message on the topic switches/kitchen_lights/status to a remote host because there may be a long period of time between light switch events
mosquitto_pub --retain --host "iot.eclipse.org" --topic switches/kitchen_lights/status --message "on"IdentifySend the contents of a file (data.txt) as a message and publish it to sensors/temperature topic
mosquitto_pub --topic sensors/temperature --file data.txtIdentifySend the contents of a file (data.txt), by reading from stdin and send the entire input as a message and publish it to sensors/temperature topic
mosquitto_pub <data.txt --topic sensors/temperature --stdin-fileIdentifyRead newline delimited data from stdin as a message and publish it to sensors/temperature topic
echo data.txt | mosquitto_pub --topic sensors/temperature --stdin-lineIdentify