Skip to content

ESP32 MQTT Subscribe Not Receiving Messages

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about ESP32 MQTT Subscribe Not Receiving Messages. We cover key concepts, practical examples, and best practices.

The Problem

ESP32 subscribes to an MQTT topic but never receives published messages.

Quick Fix

Wrong

client.subscribe("sensor/cmd");
// No callback registered
Messages published to sensor/cmd are never received by ESP32.
client.setCallback([](char* topic, byte* payload, unsigned int len) {
  Serial.printf("Topic: %s", topic);
});
client.subscribe("sensor/cmd");
Topic: sensor/cmd
Payload: led_on

Prevention

Register the callback with setCallback before subscribing. Check the return value of subscribe(). Ensure the broker allows the subscription (ACL rules). Use exact topic match for testing.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### What is the subscribe return value?

subscribe() returns true if the SUBSCRIBE packet was sent. It does not confirm broker acceptance. Use QoS 1 to get SUBACK confirmation.

Can I subscribe to multiple topics?

Yes. Call subscribe() multiple times. Each subscription counts against the broker per-client limit.

Why does unsubscribe not work?

Call client.unsubscribe(topic) with the exact same topic string used in subscribe. Wildcards must match exactly.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro