iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
To publish an MQTT message, a client sends a PUBLISH packet to a broker with a topic name and a payload. Choose QoS according to the delivery guarantee you need, and set the retain flag when new subscribers should receive the topic’s latest state. The payload’s format is up to your application.
What happens when you publish an MQTT message?
MQTT is a client/server publish-subscribe messaging transport. A publisher is an MQTT client; it sends a PUBLISH control packet to an MQTT server, commonly called a broker. The broker forwards the application message to clients with subscriptions matching the published Topic Name. The OASIS MQTT Version 5.0 specification defines the packet flow and required responses.
A PUBLISH packet has a fixed header, a variable header, and a payload. The Topic Name identifies the information channel; the Payload carries application data. MQTT does not prescribe that data’s format, and an empty payload is valid. The fixed header includes the DUP, QoS, and RETAIN controls.
How do you publish a message?
At a practical level, connect an MQTT client to a broker, select a topic and payload, choose a QoS level and retain setting, then send the publish. For example, the Eclipse Paho sample demonstrates publishing a message to a topic at QoS 0; its command syntax depends on the installed Paho version and broker endpoint. See the Eclipse Paho Python sample client and adapt it to your environment.
#1 Best Overall
- Dual-Core Performance Up to 240 MHz: Run sensor processing, wireless communication, automation logic and connected-device tasks on a 32-bit dual-core ESP32 platform designed for responsive embedded and IoT projects
- Built-in Wi-Fi and Bluetooth 4.2: Connect to 2.4 GHz Wi-Fi networks or use Bluetooth Classic and BLE for wireless sensors, smart devices, remote controls, home automation and other connected projects
- Flexible Power-Saving Modes: ESP32 power-management features support dynamic clock scaling and low-power operating modes, helping developers reduce energy use in compatible sensing, monitoring and connected-device applications, suitable for battery-powered Internet of Things (IoT) devices.
- USB-C Programming with CP2102: Connect through USB-C for power, sketch uploads and serial monitoring, while GPIO, UART, SPI and I2C interfaces support sensors, displays, motor drivers and other modules (USB-C cable not included)
- Over-the-Air Update Support: Configure OTA functionality through a compatible ESP-32 software framework to update deployed firmware over Wi-Fi without reconnecting the board by USB for every revision
Before sending, decide what the data represents. Use a topic such as sensors/room1/temperature to identify the channel, and encode the payload in the format expected by subscribers, such as JSON or plain text. MQTT transports the payload; your application defines how to interpret it.
Which MQTT QoS should you choose?
| QoS | Guarantee | What to expect | Typical consideration |
|---|---|---|---|
| 0 | At most once | No acknowledgement packet is expected. | Choose when occasional message loss is acceptable. |
| 1 | At least once | The receiver responds with PUBACK; duplicate delivery is possible. |
Choose when delivery matters and the application can handle duplicates. |
| 2 | Exactly once delivery in the MQTT exchange | The exchange begins with PUBREC and continues through the QoS 2 handshake. |
Use when the protocol-level delivery guarantee is needed; business effects still need suitable application-side design. |
These guarantees describe MQTT delivery behavior, not whether a business operation happens only once. For example, a subscriber that processes a payment or changes device state should still use suitable transaction handling or idempotency. Selecting QoS 2 alone does not make an application operation idempotent.
Rank #2
- This kit comes with NodeMCU micro controller board which is based on ESP8266, an enconimcal and powerful chip which supports wifi and IDE .
- This kit is developed specially for those want to learn and play IoT ( Internet of things). In order to connect Things to Internet, for this kit, we uses a very popular and simple IOT protocol - MQTT which has many free open-source coding resources and mobile APP to help beginners to get started in an easy and economical way. Once you master MQTT, you can also buit a smarter home or something else .
- The kit includes free on-line 17 sample lessons with detailed circuit graph, step-by-step tutorial, fully-tested sample codes and video which can save lots of your time and speed up your learning progress .
- The kit is nicely packed in plastic box. This IOT programming learning starter kit includes more than 22 kinds of different electronic components items .
- The kit can not only help students make many fancy projects in science fair, hackathon and homeworks, but also prepare the necessary knowledge base for their future career path in an interesting way.
When should you set RETAIN?
Set RETAIN=1 when a new matching non-shared subscriber should receive the latest state published for a topic. The broker stores or replaces that topic’s retained application message; this is useful for state that changes irregularly, such as a device’s current status. It is not a history or general-purpose queue of every event.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsTo remove a retained message, publish a zero-byte payload to that topic with RETAIN=1. The broker removes the stored retained message rather than retaining an empty one.
Rank #3
- Working voltage: Wide voltage DC 12-28V
- Working Current : Standby current 15MA, 1 relay open 50MA, 2 relays open 85MA, 3 relays open 120MA, 4 relays open 155MA
What do DUP, topic, and payload mean?
- Topic Name: Identifies the channel used for subscription matching. Subscribers receive messages when their subscriptions match it.
- Payload: Holds the application message. The content and encoding are application-specific; an empty payload is permitted.
- DUP: Indicates that the sender is attempting to re-deliver a PUBLISH packet. It must be 0 for QoS 0. It is not a unique-message identifier and does not mean the application payload has never been seen before.
Which transport and connection details matter?
MQTT requires an underlying transport that provides an ordered, lossless byte stream between client and server. The specification names TCP/IP, TLS, and WebSocket as suitable examples; UDP alone is unsuitable because it can lose or reorder data. Its non-normative transport discussion identifies port 1883 for non-TLS MQTT and 8883 for TLS MQTT. Actual endpoints and security requirements depend on the broker deployment.
For a production connection, verify the broker’s address and port, TLS configuration, authentication and authorization, and any broker limits that apply to message size or retained messages. Protecting the connection with TLS does not replace configuring appropriate access controls.
Rank #4
- Working voltage: Wide voltage DC 12-28V
- Working Current : Standby current 15MA, 1 relay open 50MA, 2 relays open 85MA, 3 relays open 120MA, 4 relays open 155MA
Publishing through a managed service
If you do not want to operate a broker, a managed service may expose publishing through an API. For example, the AWS IoT Publish API provides parameters including qos, retain, contentType, messageExpiry, and responseTopic. This is an AWS IoT service option rather than a change to MQTT’s core publish model.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Quick Recap
Best Value
- COMPATIBLE WITH ARDUINO UNO R4 WIFI: Works seamlessly with Arduino IDE for coding uploading and debugging as a drop in alternative for Uno R4 WiFi projects
- 32 BIT RA4M1 WITH ESP32 S3: Combines RA4M1 ARM Cortex M4 processor with ESP32-S3 coprocessor for powerful performance and built in WiFi and Bluetooth connectivity
- DESIGNED FOR STEM AND IOT PROJECTS: Ideal for students makers engineers and educators to learn electronics embedded systems wireless communication and IoT development
- EASY CONNECTION WITH 3 PIN HEADERS: All GPIOs arranged in 2.54mm VCC GND Signal groups for quick and reliable connection to sensors modules and devices
- READY TO USE WITH USB C: Includes USB Type C connection for stable power and programming with tutorials available for fast learning and project setup
A quick decision checklist
- Choose QoS based on whether loss is acceptable and whether your application can tolerate duplicates.
- Enable retain only when future subscribers need the latest topic state; publish a zero-byte retained message to clear that state.
- Define a topic structure and payload encoding that publishers and subscribers both understand.
- Use an ordered, lossless transport and configure TLS and access controls as required by your deployment.
- Check broker limits and confirm the publish syntax for your client library or managed-service API.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

