MQTT: Publish topics from command line

Hi,

the mosquitto MQTT broker also consists of some command line tools to publish or subscribe topics from a shell.

Pubishing a topic by using mosquitto_pub

mosquitto_pub --topic myRootTopic/subTopic/Value  -u mqttiuser -P 'mqtt_password' -h 10.10.254.10 -p 1883 -m "0"

and with the retain flag set

mosquitto_pub --topic myRootTopic/subTopic/Value --retain -u mqttiuser -P 'mqtt_password' -h 10.10.254.10 -p 1883 -m "0"

Subscribing a topic is straightforward with the same options as mosquitto_pub expect -m. This starts mosquitto_sub in an loop. Multiple –topic options are possible

mosquitto_sub --topic myRootTopic/subTopic/Value -u mqttiuser -P 'mqtt_password' -h 10.10.254.10 -p 1883 

Michael

Advertisment to support michlstechblog.info

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.