MQTT

From ElectroDragon
Jump to: navigation, search

Demo server

  • server 139.59.102.70 (Singarpore)
  • normal port 1883, websocket port 1884

(The server is anonymous allowed now, the following info is no needed)

  • user ed
  • password dragon

MQTT Server Setup

Run simple test

  • mosquitto_sub -h localhost -t test
  • mosquitto_pub -h localhost -t test -m "hello world"

Set password

  • sudo mosquitto_passwd -c /etc/mosquitto/passwd ed
  • sudo nano /etc/mosquitto/conf.d/default.conf
  • allow_anonymous false
  • password_file /etc/mosquitto/passwd
  • restart -> sudo systemctl restart mosquitto

Test again

  • mosquitto_sub -h localhost -t test -u "ed" -P "dragon"

ufw port setup

  • ufw allow 22

Conf Setup list

allow_anonymous false // not allow anonymous password_file /etc/mosquitto/passwd // set password

listener 1883 // set port 1883 public, or listener 1883 localhost for localhost only

listener 1884 // set 1884 for wss protocol websockets

Test tool

Log file

  • cat /var/log/mosquitto/mosquitto.log

Reference