In our tutorial on how to build a serial port server based on the EMQX platform and realize efficient communication between devices, we recommend using the Docker construction method in order to avoid errors caused by different environments. We also introduced the installation of Docker in the server and the use of Docker in Docker. Deploy EMQX service tutorial, (for specific tutorials, please refer to: Self-built MQTT server based on EMQX platform to implement communication tutorial), this article continues the above, focusing on using the serial port server to demonstrate how the serial port server uses MQTT to connect to the EMQX server. The specific tutorial steps are as follows:

Connect device to EMQX server using MQTT
Next, we will use the serial port server NB114 to simulate the actual device and demonstrate how the device uses the MQTT protocol to connect to the EMQX server. During the connection process, we will use the host computer software and serial port debugging assistant software (XCOM). These software can be downloaded from the product related pages. If you are not familiar with the product’s connection and communication methods, you can refer to the product’s quick start tutorial. Here, we assume that you have successfully connected the device.

Here, we will not introduce the configuration of EMQX in detail. You can refer to the official manual for configuration. We will focus on how to connect and communicate.

By default, EMQX can connect directly through the MQTT protocol without additional settings. In the "Access Control→Client Authorization" page, you can configure the client's access rules.
EMQX configuration

For convenience, we do not make any modifications, but directly open the host computer software and configure the serial port server NB114 for connection.
Configure the serial port server NB114

Among them, "target IP" is the IP address of EMQX
EMQX configuration

"Destination port" is the MQTT port number (1883). Select "Standard MQTT 3.1.1" in "Platform" and fill in "ClientID", "UserName", "PassWord", "Subscription and Publishing Topic". Since EMQX does not configure access rules, we can fill in this information arbitrarily without affecting the device connection. After completing the configuration, click "Save" and restart the device. Wait a moment and you will see that the device has successfully connected to the server. We can view the connection status of the device on the "Monitor → Client" page in the EMQX server.
EMQX server configuration

Next, we test whether publishing and subscribing to the topic is normal. First, we need to open the "Problem Analysis → WebSocket Client" page in the EMQX platform and set the protocol version to 3.1.1. The rest of the content can remain unchanged. When finished, click "Connect."
EMQX server configuration

Next, we need to set up the subscription and publishing topics, and set them to the subscription and publishing topics just filled in the NB114 serial port server configuration. Note that the subscription and publishing topics filled in here need to be filled in crossly (subscription fills in the published content, and publishing fills in the subscribed content). After completion, in the subscription topic, you need to click "Subscribe" first to ensure that the WebSocket client can receive the message.
EMQX server configuration

Next, we open the serial port debugging assistant (XCOM) software, fill in the parameters of NB114, and select connection.
 Serial Server Debugging Assistant

Subsequently, we send any content and the relevant information can be viewed in the subscription list of the WebSocket client.
WebSocket client serial port server configuration

At this point, we click the "Publish" button behind the publish topic to view the relevant information in the XCOM software.
XCOM configuration
Realized the communication between NB114 serial port server and EMQX server

So far, we have successfully implemented communication between the NB114 serial port server and the EMQX server.

So far, all tutorial-related content has been explained. In this tutorial, we will explain everything from the establishment of the EMQX server to the final realization of the basic communication between the device and the server. Of course, the content of this tutorial is quite basic, and the device connection does not set any relevant restrictions, which is quite unsafe and a waste of resources. If you need to apply these contents to actual projects, you can refer to the relevant contents in the EMQX manual for configuration.