1

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:

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.

MQTT.fx 预览

Each Tab supports drag and drop to become a separate window, as shown in the figure below:

MQTT.fx 独立窗口

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.

MQTT.fx 连接按钮

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.

MQTT.fx 连接配置

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:

MQTT.fx 连接成功

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.

EMQ X Platform

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:

MQTT.fx 主题订阅

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:

MQTT.fx 消息发布

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:

MQTT.fx 消息接收

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:

MQTT.fx 脚本

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.:

MQTT.fx 日志

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:

MQTT.fx SSL/TLS

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.

MQTT.fx 连接日志

MQTT.fx SSL/TLS 状态

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.


EMQX
336 声望436 粉丝

EMQ(杭州映云科技有限公司)是一家开源物联网数据基础设施软件供应商,交付全球领先的开源 MQTT 消息服务器和流处理数据库,提供基于云原生+边缘计算技术的一站式解决方案,实现企业云边端实时数据连接、移动、...