01 Overview
MQTT is the de facto standard for IoT telemetry and remote commands. This example demonstrates an ESP32 connecting to a broker over TCP, subscribing and publishing.
It solves bidirectional messaging: sensor data upstream, control commands downstream. Compared to HTTP polling, MQTT's persistent connection gives lower latency and less server load.
Typical use: temperature/humidity reporting, remote switches, alert push. Ideal for always-on or frequent small data exchanges.
Not for: LAN-only web pages (use HTTP), BLE-only communication (use BLE), or public internet without TLS (use the SSL example).
The official TCP example is plaintext — data can be sniffed. For production, switch to the SSL example or use a cloud SDK with TLS.
This is an ESP-IDF official example showing the MQTT event-driven model, a good starting point for understanding the ESP-MQTT library.