MQTT Setup

Reader support any MQTT V3.1.1 Broker with TCP, TCP/TLS, Websocket, Websocket/TLS connections. For this demo an EMQX Test Broker is used.

Installing MQTT broker on windows

This section will describe how to install MQTT broker on windows and verify the installation. The method used in this document is to install the MQTT broker as a docker container.

In order to install MQTT broker as a docker container, Docker Desktop must be installed. To install Docker Desktop, follow the instructions provided here.

Once Docker Desktop is installed and started, in the windows command prompt pull the docker image for emqx as shown below.

../../_images/MQTT_docker.png

To start the emqx broker run the command:

docker run -d --name emqx -e EMQX_LISTENER__TCP__EXTERNAL=1883 -p 18083:18083 -p 1883:1883 emqx/emqx:latest

If the EMQX broker is started successfully, then in the docker desktop the emqx container should be listed in the containers section as running.

../../_images/emqx_container.png

Testing the broker installation

To test that the EMQX docker container is working properly an MQTT client app like MQTTX can used. Install the MQTTX Client by following steps in the link.

Once installed, open MQTTX app and create a new connection, by clicking on the + icon on the left menu bar and enter the details as below and click on Connect.

../../_images/mqttx_connection.png

To subscribe to a topic click on New Subscription and enter the topic name as shown below and click on Confirm.

../../_images/mqttx_subscription.png

Now publish a test message on the test topic and check if the message is received back on the subscription.

../../_images/mqttx_pub_sub.png

Network Considerations

The default ports that are used by the various protocol for MQTT is as listed in the table below. User must ensure that these ports are open and not blocked by firewall to ensure connections.

Ports

Protocol

Port

MQTT

1883

Secure MQTT

8883

MQTT over Websockets

80

MQTT over Secure Websockets

443