This article will use MQTT.fx as the MQTT client test tool to access the MQTT cloud service-EMQ X Cloud . Through this article, you will be able to quickly understand the basic usage of MQTT.fx and the basic concepts and usage of the MQTT protocol.
Introduction to MQTT.fx
MQTT.fx is currently the most popular MQTT desktop client tool, MQTT.fx 1.0 Major version is developed by Jens Deters using JavaFX technology application. Regrettably, MQTT.fx has now ceased to be maintained, and it has been developed and developed by Softblade, and the commercial version MQTT.fx® 5.0 has been issued, and the software is operated by a fee-based license. MQTT.fx this article refers to version 1.0 without special instructions.
It contains mainstream MQTT client functions:
- Basic subscription/push/connection function
- User Authentication
- SSL/TLS connection support
- Easy-to-use message edit bar
- Support agent
In addition, MQTT.fx also has other excellent features:
- Free software, its open source agreement is Apache 2.0 license
- Support cross-platform
- Support $SYS topic subscription management MQTT Broker
- Complete log console
- Support JavaScript script to process messages
- Support predefined templates
But there are also shortcomings:
- Does not support MQTT 5.0 protocol
- Only one connection can be established at a time, which is not convenient for multi-connection debugging
- Does not support WebSocket protocol and cannot debug MQTT over Webscoket
Introduction to EMQ X Cloud
EMQ X Cloud is EMQ that can connect to massive IoT devices and integrate various databases and business systems. As 's world's first fully managed MQTT 5.0 public cloud service , EMQ X Cloud provides a one-stop O&M hosting and unique message isolation environment.
In the era of the Internet of Everything, EMQ X Cloud can help users quickly build industry applications for the Internet of Things, and easily realize the collection, transmission, calculation and persistence of Internet of Things data.
This article will use the free public MQTT server provided by EMQ X Cloud as the MQTT server address for this test. The server access information is as follows:
- Broker: broker-cn.emqx.io
- TCP Port: 1883
- SSL/TLS Port: 8883
For more details, please visit EMQ X Cloud official website , or check EMQ X Cloud document .
MQTT.fx use
Preview
The main page is shown in the figure below. The top part is the MQTT Broker connection address bar and its connection configuration. The function Tabs below it contains Publish column, Subscribe column, Scripts column, Broker Status status message column, Log log information control column.
Each Tab supports drag and drop to become a separate window, as shown in the figure below:
connect
First, MQTT client and Broker need to establish a connection to communicate. Click the configuration icon on the right side of the input box in the connection address bar to enter the specific connection configuration.
Select the Profile Type as MQTT Broker. Broker Address fill broker-cn.emqx.io
, Port Broker fill 1883
, as shown below:
broker-cn.emqx.io is a domestic server, and broker.emqx.io is a foreign server. Readers can choose one to connect.
Click OK to confirm the configuration, go back to the main interface, click Connect, you can see that the circle on the right turns green, indicating that the current connection is connected, as shown in the following figure:
Subscribe/send message
After completing the connection establishment, you can start subscribing to messages. Because the MQTT protocol uses a subscription/push method, we need to subscribe to the topic after connecting, and then there will be a message on the topic to receive the push from EMQ X Cloud.
Click to enter the Subscribe Tab, enter /testTopic/1
in the subject box, click the Subscribe button, a list of subscribed topics appears on the left, the current number of subscribed topics is 0, as shown in the following figure:
After that, we will push the message to Broker, go back to Publish, and enter the subject /testTopic/1
, and enter "hello world" and other messages in the message input box, as shown in the following figure:
Click Publish to send, return to the Subscribe Tab, and find that the subscribed topic /testTopic/1
received a message, as shown in the following figure:
We use the client /testTopic/1
send the message "hello wolrd" to the topic 06113757b2a53e under EMQ X Cloud. All clients that have subscribed to this topic will receive this message, including the sending client that has just subscribed to the topic.
script
Use scripts to customize the message push logic more flexibly, click Script Tab, click Edit to modify the content of the script, and modify it to the following content:
function execute(action) {
mqttManager.publish("/testTopic/1", "hello world from script");
return action;
}
Among them, mqttManager
is an API open to the MQTT.fx script function, mainly including:
- publish(), push message
- subscribe(), subscribe to topics
- unsubscribe(), cancel topic subscription
- output, output messages to the console
Click Execute to execute, and then go back to Subscribe and find that the message has increased, and its content is "hello world from script". The script sending function is normal, as shown in the figure below:
Log
In the log, we can view the interaction process between MQTT.fx and EMQ X Cloud, such as topic subscription, message push, message reception, etc.:
SSL/TLS connection
Take CA self-signed service as an example to show how to enable SSL protocol to connect to EMQ X Cloud.
Open the settings, fill in the Broker Address and Broker Port ( broker.emqx.io
and 8883
, respectively) like a normal connection, select SSL/TLS
, select the TLSv1.2 protocol, check CA signed server certficate, and then select the application, as shown in the following figure:
Click on the connection, you can see that the lock icon on the right is closed, indicating that SSL is enabled. Check the log and find the relevant words on the port 8883 related to the SSL connection, and the SSL/TLS connection is successful.
The above is a simple example of using MQTT.fx to access EMQ X Cloud. For more details, please visit EMQ X Cloud .
Copyright statement: This article is the EMQ , please indicate the source for reprinting.
Original link: https://www.emqx.com/zh/blog/connecting-to-emqx-cloud-with-mqttfx
Technical support: If you have any questions about this article or EMQ related products, you can visit the EMQ Q&A community https://askemq.com ask questions, we will reply to support in time.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。