Server Lesson: Install Mosquitto MQTT

Mosquitto adalah MQTT broker yang popular digunakan. Sebelum melakukan lesson ini, perlu mewujudkan satu domain seperti mqtt.shahrulnizam.com. Bagi install Mosquitto menggunakan command terminal di bawah.

$ sudo apt install mosquitto mosquitto-clients

Selepas itu sudah boleh melakukan MQTT Subcribe dan MQTT Publish. Buka dua terminal supaya terminal pertama melakukan subcribe manakala satu lagi terminal melakukan publish.

Command subcribe di bawah.

$ mosquitto_sub -h localhost -t "Example Topic"

Command publish di bawah.

$ mosquitto_pub -h localhost -t "Example Topic" -m "Example Message"

Command menghasilkan username. Selepas itu akan diminta memasukkan password.

$ sudo mosquitto_passwd -c /etc/mosquitto/passwd ExampleUser
$ sudo nano /etc/mosquitto/conf.d/default.conf
allow_anonymous false
password_file /etc/mosquitto/passwd
listener 1883
$ sudo systemctl restart mosquitto

Setelah restart mosquitto, command bagi subcribe dan publish beserta username dan password adalah di bawah.

$ mosquitto_sub -h localhost -t "Example Topic" -u "Example User" -P "Example Password"
$ mosquitto_pub -h localhost -t "Example Topic" -m "Example Message" -u "Example User" -P "Example Password"

Rujukan lain:

  1. https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-the-mosquitto-mqtt-messaging-broker-on-debian-10

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.