MQTT X CLI: A Powerful and Easy-to-Use MQTT CLI

Recently, MQTT X, the cross-platform desktop client for MQTT 5.0, was released in version 1.8.0. MQTT X is designed to connect to MQTT brokers such as EMQX. It makes it easy and quick to create multiple simultaneous online MQTT client connections and test the connection, publishing, and subscription functions of MQTT/TCP, MQTT/TLS, MQTT/WebSocket as well as other MQTT protocol features.

The latest release of v1.8.0 not only optimizes the experience with a quick connection duplication feature but also supports new use cases by adding two new interaction methods, namely CLI (command line) and browser. This makes MQTT X 1.8.0 the most complete MQTT test client in terms of supported scenarios. Depending on your needs, you can choose to download the desktop client, use the terminal command line, or quickly test MQTT connections in your web browser.

MQTT X CLI: Rapidly develop and debug MQTT services and applications in the terminal

With the widespread use of the MQTT protocol in the IoT industry, more developers are choosing to use MQTT X for connectivity testing.

In order to provide more choices and convenience for users to implement MQTT connection tests, MQTT X v1.8.0 adds the command line as a form of interaction - the MQTT X CLI, a fully open source MQTT 5.0 command line client tool. This allows developers to develop and debug MQTT services and applications faster using the command line without the graphical interface. This enables the following usage goals:

  • Test deployed MQTT services in the server terminal
  • Quickly test MQTT services by editing and using command line scripts
  • Use command line scripts to perform simple stress tests or automated tests

MQTT X CLI website: https://mqttx.app/cli

MQTT X CLI 1.8.0 download: https://github.com/emqx/MQTTX/releases/tag/v1.8.0

MQTT X CLI GitHub repository: https://github.com/emqx/MQTTX/tree/main/cli

MQTT X CLI

Dependency-free: Get up and running with no prerequisites required

Installation

The MQTT X CLI can be quickly downloaded and installed on macOS, Linux, and Windows systems without any environmental dependencies, simply by executing commands in a terminal.

For macOS and Linux users, we provide a quick installation method using the command line to quickly download the binaries and install the latest stable version of MQTT X CLI on the operating system. Windows users can go to the MQTT X release page to find the exe package for the corresponding system architecture and manually download it for use.

Note: When downloading and installing, please be careful to distinguish the CPU architecture of the current system environment

macOS

  • Homebrew

    macOS users can quickly install and use the MQTT X CLI via Homebrew

     brew install emqx/mqttx/mqttx-cli
    
  • Intel Chip

     curl -LO https://www.emqx.com/zh/downloads/MQTTX/v1.8.0/mqttx-cli-macos-x64
     sudo install ./mqttx-cli-macos-x64 /usr/local/bin/mqttx
    
  • Apple Silicon

     curl -LO https://www.emqx.com/zh/downloads/MQTTX/v1.8.0/mqttx-cli-macos-arm64
     sudo install ./mqttx-cli-macos-arm64 /usr/local/bin/mqttx
    

Linux

  • x86-64

     curl -LO https://www.emqx.com/zh/downloads/MQTTX/v1.8.0/mqttx-cli-linux-x64
     sudo install ./mqttx-cli-linux-x64 /usr/local/bin/mqttx
    
  • ARM64

     curl -LO https://www.emqx.com/zh/downloads/MQTTX/v1.8.0/mqttx-cli-linux-arm64
     sudo install ./mqttx-cli-linux-arm64 /usr/local/bin/mqttx
    

Windows

Windows users should manually download the corresponding exe file from the MQTT X download page at: https://github.com/emqx/MQTTX/releases/tag/v1.8.0

MQTT X CLI Windows

NPM

In addition to the above, we also provide an installation method using npm, so that you can quickly install and use it no matter what your current operating system environment is, as long as you have a Node.js environment on your system.

npm install mqttx-cli -g

Quick Start

Once you have completed the download and installation, you can run and use the mqttx command by typing it directly into the terminal. You can verify that the MQTT X CLI has been installed successfully by adding the -V parameter, and when a version number is an output, the MQTT X CLI has been successfully installed.

$ mqttx -V
1.8.0

To test operation of the MQTT X CLI, you first need to connect to an MQTT server. In this article, we will use EMQ’s free public MQTT broker, which runs on the fully managed MQTT cloud, EMQX Cloud, with the following access information:

  • Broker: broker.emqx.io
  • TCP Port: 1883
  • WebSocket Port: 8083

We can use the command line to connect to the MQTT server and publish or subscribe to messages from within the terminal. We start by editing the command to subscribe to a topic within a terminal window.

Subscribe

mqttx sub -t 'mqttx/cli' -h 'broker.emqx.io' -p 1883

Next, let’s try publishing a message to the topic we just subscribed to. Leave the listening subscriber running and create a new terminal window, then enter the command below.

Publish

mqttx pub -t 'mqttx/cli' -h 'broker.emqx.io' -p 1883 -m 'hello from MQTTX CLI!'

At this point, we can see a message that was just posted in the window of the Subscribe to Topic command.

MQTT X CLI Publish

Publishing multiple messages

The MQTT X CLI also supports a pub command to publish multiple messages, just add an -M parameter and an -s parameter to the command in the editor and separate each entry with a newline.

mqttx pub -t 'mqttx/cli' -h 'broker.emqx.io' -p 1883 -s -M

Publishing multiple messages

Finally, we test and verify the functionality of the MQTT X CLI by using the MQTT X desktop client to connect to the same MQTT service as the MQTT X CLI. We use the MQTT X CLI to publish a message, receive it through the MQTT X desktop client, and then reverse the process by using the MQTT X desktop client to send a message to the MQTT X CLI. At this point, we can see that both sides have received their respective incoming and outgoing messages.

MQTT X desktop client

MQTT X desktop client

MQTT X CLI

MQTT X CLI

Summary

This concludes our testing and verification of the MQTT message publish-subscribe feature using the MQTT X CLI. In addition to the common features mentioned above, the MQTT X CLI also supports setting up last will messages, using SSL/TLS to test mqtts connections, and more. MQTT 5.0 connectivity will also be supported in the future.

The release of the MQTT X CLI provides a new option for IoT developers to test MQTT connections. With complete support for command line calls, desktop client downloads, and online browsers, MQTT X 1.8.0 helps users with different use cases to complete the development and debugging of MQTT services or applications, improving their own business capabilities and stability. The easy-to-use test client tool, MQTT X, combined with the efficient, reliable MQTT broker, EMQX, will help IoT developers build competitive IoT platforms and applications.

Appendix: User Help

You can enter the --help parameter on the command line to get help or check the usage parameter table below to use the MQTT X CLI.

# Get help for the mqttx command
mqttx --help

# Get help for the sub command
mqttx sub --help

# Get help for the pub command
mqttx pub --help

Table of options

Options Description
-V, --version output the version number
-h, --help display help for command
Command Description
pub publish a message to a topic
sub subscribes to a topic

Subscribe

Options Description
-h, --hostname the broker host (default: "localhost")
-p, --port the broker port
-i, --client-id the client id
-q, --qos <0/1/2> the QoS of the message (default: 0)
--clean discard any pending message for the given id (default: true)
-t, --topic the message topic
-k, --keepalive send a ping every SEC seconds (default: 30)
-u, --username the username
-P, --password the password
-l, --protocol the protocol to use, mqtt, mqtts, ws or wss
--key path to the key file
--cert path to the cert file
--ca path to the ca certificate
--insecure do not verify the server certificate
--will-topic the will topic
--will-message the will message
--will-qos <0/1/2> the will qos
--will-retain send a will retained message (default: false)
-v, --verbose print the topic before the message
--help display help for sub command

Publish

Options Description
-h, --hostname the broker host (default: "localhost")
-p, --port the broker port
-i, --client-id the client id
-q, --qos <0/1/2> the QoS of the message (default: 0)
-t, --topic the message topic
-m, --message the message body (default: "Hello From MQTT X CLI")
-r, --retain send a retained message (default: false)
-s, --stdin read the message body from stdin
-M, --multiline read lines from stdin as multiple messages
-u, --username the username
-P, --password the password
-l, --protocol the protocol to use, mqtt, mqtts, ws or wss
--key path to the key file
--cert path to the cert file
--ca path to the ca certificate
--insecure do not verify the server certificate
--will-topic the will topic
--will-message the will message
--will-qos <0/1/2> the will qos (default: 0)
--will-retain send a will retained message (default: false)
--help display help for pub command
Try MQTT X
Download Now →

Related Posts

MQTT.js tutorial

This article introduces the use of some common APIs of MQTT.js and some experience in the use process to help users quickly use MQTT in JavaScript projects.

Shifan Yu 2021-09-14
Connect to MQTT broker with Websocket

This article will demonstrate how to use WebSocket to connect to MQTT broker and introduce technical points of interest to developers and solutions to common errors.

Shifan Yu 2020-11-05
Use MQTT with Raspberry Pi

This article introduces how to use Python to write a simple MQTT client on Raspberry Pi to implement the connection, subscribe, messaging, etc.

Saiteng You 2020-08-12