Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
GimmeJob
Sign in
Testing tools: hands-on guides · Chapter 06 / 09

Testing Tools

MQTT tools: MQTT Explorer, MQTTX & Mosquitto CLI

MQTT is the publish/subscribe protocol behind most IoT products: sensors, smart-home devices, vehicle telemetry, industrial equipment. Devices don't call each other. They publish messages to topics on a broker, and anyone subscribed to those topics receives them. To test such a system you need a client that can subscribe and see everything, publish crafted messages, and inspect flags such as QoS, retain and Last Will. This chapter covers three free tools that complement each other: MQTT Explorer for seeing the whole topic tree, MQTTX for precise multi-client scenarios, and mosquitto_pub / mosquitto_sub for scripts and CI.

Key factMQTT ExplorerMQTTXMosquitto CLI
TypeDesktop GUIDesktop GUI, also CLI and webCommand line
PlatformsWindows, macOS, LinuxWindows, macOS, LinuxWindows, macOS, Linux
StrengthTopic tree, history, diffs, retained-message cleanupSeveral connections side by side, MQTT 5, Last WillScriptable, tiny, ideal for CI and reproductions
Installmqtt-explorer.com (stores, .exe, .dmg, AppImage, snap)mqttx.appapt install mosquitto-clients, brew install mosquitto, Windows installer

Public test brokers (no account needed): test.mosquitto.org, broker.hivemq.com and broker.emqx.io, all on port 1883 for plain MQTT.

Device / service ──publish──► Broker ──deliver──► every subscriber of a matching topic
                     ▲                     │
     test client publishes crafted      test client subscribes to # or a prefix
     messages (QoS, retain, LWT)        and checks what arrives, when and how often

MQTT essentials for testers: topics, wildcards, QoS, retain and Last Will

Topics are UTF-8 strings split into levels by /, for example factory/line1/sensor42/temperature. They are case-sensitive and created on first use.

Wildcard (subscribe only)MatchesExample
+Exactly one levelfactory/+/sensor42/temperature
#Any number of levels, must be lastfactory/line1/#
$SYS/#Broker statistics (on brokers that provide them, such as Mosquitto)$SYS/broker/clients/connected

QoS (Quality of Service) is set per publish and per subscription. The delivered level is the lower of the two.

QoSGuaranteePackets on the wire
0At most once. May be lostPUBLISH
1At least once. May be duplicatedPUBLISH → PUBACK
2Exactly oncePUBLISH → PUBREC → PUBREL → PUBCOMP
  • Retained message: a publish with the retain flag is stored by the broker as the topic's "last known value". Every new subscriber receives it immediately. To delete it, publish an empty retained message to the same topic.
  • Last Will and Testament (LWT): when a client connects, it can register a will message. The broker publishes it if the client disappears without a clean DISCONNECT (crash, power loss, network drop). This is the usual way to implement online / offline status.
  • Session: with clean session = false (MQTT 3.1.1) or clean start = false plus a session expiry interval (MQTT 5), the broker keeps subscriptions and queues QoS 1/2 messages while the client is offline, as long as the client reconnects with the same client ID.
  • Client ID: must be unique per broker. A second connection with the same ID kicks the first one off. That's a classic source of "random disconnect" bugs.

MQTT Explorer: browse the topic tree, publish and diff

  1. Download MQTT Explorer from mqtt-explorer.com and start it. The connection dialog opens.
  2. Enter a Name, choose the protocol mqtt://, and enter Host test.mosquitto.org and Port 1883. Add Username / Password and turn on Encryption (tls) if your broker needs them.
  3. Click Advanced to see the subscriptions. By default MQTT Explorer subscribes to # and $SYS/#. On a busy public broker, replace # with your own prefix, for example gimmejob/qa-lab/#. You can also set the Client ID here.
  4. Click Connect. Topics appear as a tree on the left. Numbers show how many sub-topics and messages each branch has, and branches flash when new messages arrive.
  5. Click a topic to see its Value on the right: payload, QoS, retain flag, and the time it was received. JSON is pretty-printed.
  6. Open History under the value to see previous messages. Use the diff view to compare the current payload with the previous one, which is ideal for spotting the one field that changed.
  7. Numeric topics can be plotted as a chart, which is useful for sensors that drift or spike.
  8. In Publish, enter a topic and payload (raw, JSON or XML), choose QoS, tick retain if needed, and click Publish.
  9. To remove a stale retained value, select the topic and click the delete (trash) button. MQTT Explorer can delete a single topic or a whole branch recursively.
MQTT Explorer topic tree, message value and publish panel
MQTT Explorer project screenshot: the topic tree with message details and history.
Caveat: Subscribing to # on a large production broker can flood the app and the network. Always narrow the subscription to the part of the tree you're testing.

MQTTX: connections, subscriptions, Last Will and MQTT 5

MQTTX (by EMQ) keeps several connections open in one window. You can be "the device" in one tab and "the backend" in another.

  1. Start MQTTX and click New Connection (Ctrl/Cmd+N) or + in the left sidebar. Try public broker creates a ready connection to broker.emqx.io:1883.
  2. Fill in Name, Client ID (click refresh to generate one), Host with a protocol (mqtt://, mqtts://, ws://, wss://) and Port (1883 plain, 8883 TLS, 8083 WebSocket, 8084 secure WebSocket on EMQX).
  3. Open Advanced to set MQTT Version (5.0 by default, or 3.1.1 / 3.1), Keep Alive, Clean Start (MQTT 5) or Clean Session (MQTT 3.x), and automatic reconnect.
  4. In Last Will and Testament, enter Last-Will-Topic (for example gimmejob/qa-lab/device1/status), Last-Will-Payload (offline), and the QoS and retain values. QoS defaults to 0 and retain to false.
  5. Click Connect in the upper right corner.
  6. Click New Subscription, enter a topic such as gimmejob/qa-lab/#, and pick a color. Separate several topics with commas.
  7. In the publish area at the bottom, enter the topic, choose QoS and Retain, choose a payload format (JSON, Plaintext, Base64, Hex...), type the payload, and press Send or Ctrl/Cmd+Enter.
  8. Received messages appear on the left and sent messages on the right. Click a subscription to filter the list to that topic.
MQTTX Last Will and Testament settings
Official MQTTX documentation screenshot: Last Will and Testament settings in a new connection.
MQTTX main window with subscriptions and messages
Official MQTTX documentation screenshot: the main window with subscriptions, received and published messages.
QA tip: Create two connections with different client IDs: device-sim with a Last Will, and backend-observer subscribed to the status topic. Then disconnect device-sim in different ways and watch what the observer receives.

Mosquitto CLI: mosquitto_sub and mosquitto_pub

# Subscribe to a whole branch and print the topic in front of each message (-v)
mosquitto_sub -h test.mosquitto.org -t 'gimmejob/qa-lab/#' -v

# Publish one message with QoS 1
mosquitto_pub -h test.mosquitto.org -t 'gimmejob/qa-lab/device1/temp' -m '21.5' -q 1

# Publish a retained status, then clear it again with an empty retained message (-n)
mosquitto_pub -h test.mosquitto.org -t 'gimmejob/qa-lab/device1/status' -m 'online' -r
mosquitto_pub -h test.mosquitto.org -t 'gimmejob/qa-lab/device1/status' -r -n

# Receive exactly one message, or give up after 10 seconds: perfect for test scripts
mosquitto_sub -h test.mosquitto.org -t 'gimmejob/qa-lab/device1/temp' -C 1 -W 10

# Hide old retained messages (-R) and show a timestamp, topic and payload for each message
mosquitto_sub -h test.mosquitto.org -t 'gimmejob/qa-lab/#' -R -F '%I %t %p'

# Register a Last Will while subscribing
mosquitto_sub -h test.mosquitto.org -t 'gimmejob/qa-lab/cmd' -i device1 \
  --will-topic 'gimmejob/qa-lab/device1/status' --will-payload 'offline' --will-retain

# Publish a JSON file, use MQTT 5, show every protocol packet (-d)
mosquitto_pub -h test.mosquitto.org -t 'gimmejob/qa-lab/device1/config' -f config.json -V mqttv5 -d

# Broker statistics (Mosquitto brokers)
mosquitto_sub -h test.mosquitto.org -t '$SYS/broker/clients/connected' -C 1 -v
OptionMeaning
-h, -pBroker host and port (default port 1883)
-tTopic. Repeat it to subscribe to several
-m, -f, -nPayload from text, from a file, or empty
-qQoS 0, 1 or 2
-rRetain flag (pub)
-vPrint the topic with each message (sub)
-C n / -W sExit after n messages / after s seconds (sub)
-RDon't print stale retained messages (sub)
-iClient ID
-u, -PUsername and password
--cafileCA certificate for TLS. With -p 8883 and no CA options, Mosquitto 2.x clients load the OS certificates automatically
-V mqttv5Use MQTT 5
-dDebug: print CONNECT, CONNACK, PUBLISH and other packets
Caveat: Ctrl+C makes mosquitto_sub disconnect cleanly, so its Last Will is not sent. To simulate a crash, kill the process (kill -9 <pid>) or cut the network.

MQTT test scenarios you should run

ScenarioHow to testExpected
QoS 1 deliveryPublish with -q 1 while a subscriber with QoS 1 is connected; watch with -dPUBACK received; duplicates handled idempotently by the consumer
Retained state for late joinersPublish a retained status, then start a new subscriberNew subscriber gets the last value at once
Clearing retained statePublish an empty retained message (-r -n)New subscribers receive nothing
Device goes offlineConnect with a Last Will, then kill the processObservers receive the will (offline)
Clean disconnectDisconnect normallyWill is not sent; app must publish offline itself if needed
Offline queueSubscriber with a fixed client ID and persistent session goes offline; publish QoS 1; reconnectQueued messages arrive after reconnect
Duplicate client IDConnect two clients with the same -iBroker disconnects the older one; app should report it, not loop forever
Authorization (ACL)Subscribe to # or another tenant's topic with a restricted userSubscription refused (SUBACK failure), no data leak
Bad credentialsWrong passwordCONNACK "not authorized" and a clear error in the app
Payload robustnessInvalid JSON, empty payload, 1 MB payload, Unicode, wrong typesConsumer rejects or logs safely; no crash
Topic validationPublishing to a topic containing + or #Rejected by the client or broker
Reconnect behaviourRestart the broker or drop Wi-FiClient reconnects with backoff and resubscribes

Debugging MQTT: Wireshark filters, $SYS topics and Postman

  • Wireshark decodes MQTT on port 1883 automatically. Useful display filters: mqtt, mqtt.msgtype == 1 (CONNECT), mqtt.msgtype == 3 (PUBLISH), mqtt.msgtype == 14 (DISCONNECT), mqtt.topic contains "qa-lab", mqtt.qos == 1. For port 8883 (TLS) you need the decryption steps from the Wireshark chapter, or a test broker without TLS.
  • `$SYS` topics on Mosquitto show connected clients, message rates and retained message counts. A sudden jump in $SYS/broker/clients/connected during a test often means a reconnect loop.
  • Postman has an MQTT request type (Add → MQTT). It's convenient when the same collection also holds the REST API that triggers device actions.
  • mosquitto_sub -d prints every MQTT control packet. It's the quickest way to see whether a CONNACK came back with an error code.
  • Exit codes: when the broker refuses a connection, mosquitto_pub and mosquitto_sub exit with the CONNACK reason code. For MQTT 3.1.1 that's 4 for a bad username or password and 5 for not authorized; for MQTT 5 it's 134 and 135. Scripts can assert on $?.
  • TLS traffic: Mosquitto 2.1+ clients accept --tls-keylog keys.log. Point Wireshark's TLS (Pre)-Master-Secret log filename at that file to read MQTT over port 8883 in clear text. Use this for debugging only.

Cheat sheet

TaskHow
See everything under a prefixmosquitto_sub -h HOST -t 'prefix/#' -v
Publish oncemosquitto_pub -h HOST -t topic -m 'payload' -q 1
Set a retained valuemosquitto_pub ... -r
Clear a retained valuemosquitto_pub -t topic -r -n
Wait for one message in a scriptmosquitto_sub -t topic -C 1 -W 10
See protocol packetsadd -d
Visual topic tree and historyMQTT Explorer
Remove retained topics in bulkMQTT Explorer → delete branch
Device plus observer side by sideMQTTX with two connections
Configure a Last WillMQTTX → Last Will and Testament, or --will-topic
Inspect on the wireWireshark filter mqtt
Hands-on lab: online/offline status with retained messages and Last Will

Pick a unique prefix so you don't collide with other people on the public broker, for example gimmejob/qa-lab/<your-name>. Below it is shortened to P.

  1. Observer: in terminal 1 run mosquitto_sub -h test.mosquitto.org -t 'P/#' -v, or connect MQTT Explorer with the subscription P/#.
  2. Device: in terminal 2, start a client with a Last Will and a fixed client ID. Use the first command after this list.
  3. Device announces itself: in terminal 3, publish a retained status with the second command. The observer prints P/device1/status online.
  4. Late joiner: in terminal 4, start a new subscriber: mosquitto_sub -h test.mosquitto.org -t 'P/device1/status' -v. It immediately receives online, because the message is retained.
  5. Crash: find the device's process ID (pgrep -f device1) and kill it with kill -9 <pid>. After the keep-alive period (up to about 1.5× the default 60 s) the observer receives P/device1/status offline. That is the Last Will.
  6. Clean exit: start the device again and stop it with Ctrl+C instead. Confirm that no offline message arrives this time.
  7. Duplicate client ID: start the device command in two terminals at once. The broker disconnects the older connection each time the other one connects, so they keep kicking each other off. That's what a duplicate client ID looks like in production logs.
  8. Clean up the retained value with the last command after this list. In MQTT Explorer you can also delete the topic.
mosquitto_sub -h test.mosquitto.org -i device1 -t 'P/device1/cmd' \
  --will-topic 'P/device1/status' --will-payload 'offline' --will-retain
mosquitto_pub -h test.mosquitto.org -t 'P/device1/status' -m 'online' -r
mosquitto_pub -h test.mosquitto.org -t 'P/device1/status' -r -n

Repeat in MQTTX: create connection device-sim with a Last Will, plus connection observer. Disconnect device-sim by turning off Wi-Fi rather than clicking Disconnect.

Official MQTTX getting started · mosquitto_sub manual

Summary

  • Know the protocol rules you're testing: topic wildcards, QoS 0/1/2, retained messages, Last Will, persistent sessions and unique client IDs.
  • Use MQTT Explorer to see the whole topic tree, history and diffs. Use MQTTX for multi-client scenarios and MQTT 5 options. Use mosquitto_pub / mosquitto_sub for scripts and reproducible bug reports.
  • Test the failure paths: crashes that should trigger a Last Will, clean disconnects that shouldn't, duplicate client IDs, ACL violations and bad payloads.
  • Use unique topic prefixes and never real data on public brokers. When behaviour is unclear, look at the packets with -d or Wireshark.

Source registry

Verified 22 Nov 2026
MQTT Explorer

Topic tree, history, diff, publishing and retained-topic deletion in MQTT Explorer

Thomas Nordquist · verified
Source ↗
MQTTX: Getting started

Connection settings, MQTT versions, Last Will, subscriptions and publishing in MQTTX

EMQ · verified
Source ↗
mosquitto_sub manual

Subscribing, output formatting, message counts, timeouts, retained handling and wills

Eclipse Mosquitto · verified
Source ↗
mosquitto_pub manual

Publishing with QoS, retain, files and empty payloads; TLS key logging and CONNACK exit codes

Eclipse Mosquitto · verified
Source ↗
MQTT Version 5.0 (OASIS Standard)

Normative rules for topics, wildcards, QoS flows, retained messages, wills and sessions

OASIS · verified
Source ↗
Postman: Create your first MQTT request

Connecting to a broker, subscribing to topics and publishing messages from Postman

Postman · verified
Source ↗