Dmytro Larkin

Basic MQTT With Mosquitto

Setup MQTT server

Don’t forget to enable firewall on your Debian distro.

sudo ufw allow 1883

Publish MQTT

Suppose a sensor is publishing temperature value.

Lets identify sensor as a number 1.

Sensor has its own topic sensor/1/t fot a temperature values stream.

To emulate that with mosquitto_pub tool use following command

mosquitto_pub \
  -h 192.168.88.132 \
  -u username \
  -P password \
  -t sensor/1/t \
  -m "1:t:34.4"

Note, message 1:t:34.4 has all the attributes to extract sensor identity and metric name. So that makes data able to be parsed and distinqueshed in a stream of multiple metrics.

Subscribe MQTT

Listen for everything on a server

mosquitto_sub \
  -h 192.168.88.132 \
  -u username \
  -P password \
  -t '#'

Listen for a specific data subset. Filter topics partially, + replaces a single word.

mosquitto_sub \
  -h 192.168.88.132 \
  -u username \
  -P password \
  -t 'sensor/+/t'
#iot #mqtt