MQTT Protocol Testing Tool
Online MQTT client, supports connection testing, message publishing & subscribing, protocol debugging/analysis. Suitable for IoT device testing and MQTT protocol learning.
MQTT Communication Log
[Time]
MQTT testing tool ready. Please enter connection parameters to start.
MQTT Protocol Introduction
MQTT (Message Queuing Telemetry Transport) is a lightweight publish/subscribe messaging protocol designed for low-bandwidth, high-latency, or unreliable networks. It is widely used in the Internet of Things (IoT) field and is a key protocol for device-to-cloud communication.
MQTT Protocol Features
- Lightweight & Efficient: Small header size, low message overhead, suitable for limited bandwidth.
- Publish/Subscribe Pattern: Supports one-to-many message distribution, decouples producers and consumers.
- QoS Support: Provides three Quality of Service levels for reliable message delivery.
- Persistent Sessions: Supports saving session state and messages when client is offline.
- Will Message: Automatically sends a predefined message upon abnormal disconnection.
MQTT Protocol Core Concepts
| Concept |
Description |
| Broker |
MQTT server, responsible for receiving, filtering, and forwarding messages. |
| Client |
MQTT client, can be a publisher, subscriber, or both. |
| Topic |
Message topic for categorizing and routing messages, supports wildcards. |
| Publish |
Publish a message to a specified topic. |
| Subscribe |
Subscribe to one or more topics to receive relevant messages. |
| QoS |
Quality of Service level (0-2), determines message delivery reliability. |
MQTT Quality of Service (QoS) Levels
MQTT provides three Quality of Service levels to ensure message delivery reliability for different scenarios:
| QoS Level |
Name |
Description |
Applicable Scenario |
| 0 |
At most once |
Message sent without confirmation, may be lost. |
Non-critical data, e.g., periodic sensor reports. |
| 1 |
At least once |
Ensures message is delivered at least once, may be duplicated. |
Important data that cannot be lost. |
| 2 |
Exactly once |
Ensures message is delivered exactly once, no duplication. |
Critical business data, e.g., payment commands. |
MQTT Testing Tool User Guide
Connect to MQTT Broker
- Enter Broker URL (supports WebSocket protocol)
- Set Client ID (recommend using a unique identifier)
- Fill in Username and Password if authentication is required
- Click the "Connect" button to establish connection
Subscribe to Topic
- Enter topic name in the "Subscribe Topic" input
- Click the "Subscribe" button to subscribe
- After successful subscription, all messages for that topic will be received
Publish Message
- Enter target topic in the "Publish Topic" input
- Enter the message to send in the "Message" text box
- Click the "Publish Message" button to send
Testing Tips:You can use public MQTT Brokers for testing, such as broker.emqx.io, test.mosquitto.org, etc. These public servers are available without registration and are suitable for learning and testing.
MQTT Topic Design Best Practices
Topic Hierarchy Structure
A well-designed topic structure improves system maintainability and scalability:
- Multi-level topics: Use "/" to separate levels, e.g.,
home/living-room/temperature
- Device identifiers: Include device ID in topic, e.g.,
devices/device-001/status
- Functional categorization: Categorize topics by function, e.g.,
sensors/temperature, actuators/switch
Topic Wildcards
MQTT supports two wildcards for subscribing to multiple related topics:
- + (Single-level wildcard): Matches one level, e.g.,
home/+/temperature
- # (Multi-level wildcard): Matches multiple levels, must be placed at the end, e.g.,
home/#
Frequently Asked Questions
Why does the connection fail?
Possible reasons for connection failure:
- Incorrect Broker URL or service unavailable
- Network connectivity issue
- Incorrect authentication credentials
- Client ID conflict
How to choose the appropriate QoS level?
Choose based on business requirements:
- QoS 0: Suitable for scenarios tolerant of data loss, e.g., periodic sensor data.
- QoS 1: Suitable for scenarios where data cannot be lost but duplication is tolerable.
- QoS 2: Suitable for critical business data where neither loss nor duplication is allowed.
Difference between MQTT over WebSocket and TCP?
MQTT over WebSocket enables MQTT protocol usage in browser environments, while standard MQTT is based on TCP. The WebSocket version is more suitable for web applications and frontend-backend communication.
MQTT Application Scenarios
- IoT Device Communication: Sensor data collection, device status monitoring
- Mobile App Push Notifications: Real-time message push, chat applications
- Smart Home: Device control, status synchronization
- Connected Vehicles: Vehicle status reporting, remote control
- Industrial IoT: Equipment monitoring, production data collection