Skip to content

Instantly share code, notes, and snippets.

@7wells
Last active October 1, 2022 14:27
Show Gist options
  • Save 7wells/aaaaeb53ed688edbd5625419347f54bc to your computer and use it in GitHub Desktop.
Save 7wells/aaaaeb53ed688edbd5625419347f54bc to your computer and use it in GitHub Desktop.
Testing mosquitto broker and client on Raspberry Pi OS
# How to test mosquitto broker and client on Raspberry Pi OS
#
# Source: https://randomnerdtutorials.com/testing-mosquitto-broker-and-client-on-raspbbery-pi/
#
# Install mosquitto clients (if not already installed together with mosquitto broker)
#
sudo apt install mosquitto-clients
# Subscribe to topic "testTopic"
# To subscribe to a mosquitto topic with mosquitto client enter below command
# Note to replace localhost (default) by IP/hostname of Raspberry Pi where mosquitto message is published
# Note also that some passwords (with special characters?) might need to be placed inside double quotation marks
# Replace <mosquitto broker username> and <mosquitto broker user's password>
#
mosquitto_sub -d -h localhost -t testTopic -u <mosquitto broker username> -P "<mosquitto broker user's password>"
# Publish message to topic "testTopic" from another terminal/console on the same(*) Raspberry Pi or from another device with mosquitto broker
# Note to replace localhost (default) by IP/hostname of Raspberry Pi where mosquitto client subscribed from
# Note also that some passwords (with special characters?) might need to be placed inside double quotation marks
# Replace <mosquitto broker username> and <mosquitto broker user's password>
#
mosquitto_pub -d -h localhost -t testTopic -m "Hello world!" -u <mosquitto broker username> -P "<mosquitto broker user's password>"
# Username and more password are transmitted in clear text, AFAIK.
# If the connection is not secured by e.g. SSL or VPN(?), the password can be captured.
# Please be careful when using mosquitto outside your private network!
#
# Further reading (in German):
# https://gridscale.io/community/tutorials/eclipse-mosquitto-mqtt-broker-ubuntu-16-04-18-04-installieren-einrichten/#installiere-und-fhre-certbot-fr-lets-encrypt-zertifikate-aus
# An IMO great mosquitto client is MQTT-Explorer (available for Linux, Windows, and MacOS) from Thomas Nordquist:
# https://github.com/thomasnordquist/MQTT-Explorer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment