Mosquitto MQTT Broker#

ide49 comes with a built-in Mosquitto MQTT broker. By default, the broker is enabled.

The broker listens on the standard 1883 port for unencrypted and 8883 for encrypted messages. For websockets use port 9001 (unencrypted) or 9002 (encrypted).

Unencrypted messages are enabled only for topic public/#.

Encrypted traffic is protected with a password (user and password are both iot49) and certificate stored at /service-config/mosquitto/certs/ca.crt/service-config/mosquitto/certs/ca.crt.

Example#

%%bash

mosquitto_sub -h $HOST_IP -t "testtopic/#" -t "public/#" -u iot49 -P iot49 -p 8883 \
    --cafile /service-config/mosquitto/certs/ca.crt &

mosquitto_pub -h $HOST_IP -t "public/hello" -m " " -p 1883
mosquitto_pub -h $HOST_IP -t "public/hello" -m "START -------- `date`" -p 1883
mosquitto_pub -h $HOST_IP -t "public/hello" -m "1) public Grüezi 1883 no TLS" -p 1883
mosquitto_pub -h $HOST_IP -t "public" -m "2) public Grüezi 1883 no TLS" -p 1883

# this one will be silently ignored by the broker: topic does not match public/#
mosquitto_pub -h $HOST_IP -t "testtopic" -m "3) testtopic Grüezi 1883" -p 1883

mosquitto_pub -h $HOST_IP -t "public/hello" -m "a) public Grüezi 8883 with TLS & cert" -p 8883 \
    --cafile /service-config/mosquitto/certs/ca.crt \
    -u iot49 -P iot49

mosquitto_pub -h $HOST_IP -t "testtopic/hello" -m "b) testtopic Grüezi 8883 with TLS & cert" -p 8883 \
    --cafile /service-config/mosquitto/certs/ca.crt \
    -u iot49 -P iot49

mosquitto_pub -h $HOST_IP -t "public/hello" -m "END ---------- `date`" -p 1883
START -------- Wed 05 Jan 2022 04:38:37 PM PST
1) public Grüezi 1883 no TLS
2) public Grüezi 1883 no TLS
a) public Grüezi 8883 with TLS & cert
b) testtopic Grüezi 8883 with TLS & cert
END ---------- Wed 05 Jan 2022 04:38:38 PM PST
Interrupted

Customize#

The setup can be changed by editing the configuration at /service-config/mosquitto/. To disable the broker, add export MOSQUITTO=off to file /service-config/iot-home/.env49rc.