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.
For convenience, we do not make any modifications, but directly open the host computer software and configure the serial port server NB114 for connection.
Among them, "target IP" is the IP address of EMQX
"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.
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."
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.
Next, we open the serial port debugging assistant (XCOM) software, fill in the parameters of NB114, and select connection.
Subsequently, we send any content and the relevant information can be viewed in the subscription list of the WebSocket client.
At this point, we click the "Publish" button behind the publish topic to view the relevant information in the XCOM software.
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.