MQTT (Message Queue Telemetry Transport)

Think of MQTT as a bulletin board in the cloud: your board 'posts' a note under a labeled topic (like home/sensors/temperature), and any other device that's 'subscribed' to that topic…

Connectivity9 blocksMicroPythonC++

Think of MQTT as a bulletin board in the cloud: your board "posts" a note under a labeled topic (like home/sensors/temperature), and any other device that's "subscribed" to that topic instantly gets a copy — no need to know each other's address or be online at the same moment. This publish-subscribe pattern is the standard way real IoT products (smart plugs, thermostats, industrial sensors) talk to the cloud, because it's lightweight enough to work even over a slow or unreliable connection.


1. Real-World Uses

MQTT is the backbone of most "real" IoT products you've heard of:

  • Home automation — connecting a project to Home Assistant, so a DIY sensor or switch shows up alongside your real smart-home devices.
  • Cloud dashboards — publishing sensor readings to AWS IoT Core or Azure IoT Hub so they show up on a live graph, viewable from anywhere.
  • Many-to-many device networks — unlike ESP-NOW (Section 7.2), which is one board talking directly to another, MQTT lets dozens of boards publish and subscribe to shared topics through one central broker — a much better fit for a whole house or building full of sensors.
  • Remote control over the internet — publish a command to a topic like home/lights/set from anywhere in the world, and any subscribed device acts on it instantly.

2. Specifications & Port Standards

  • Compatible Boards: ESP32, ESP8266, Pico W, Pico 2 W.
  • Requires Wi-Fi: this extension needs the Wi-Fi extension (Section 7.1) to already be connected — MQTT rides on top of a normal internet connection, it doesn't have its own radio protocol like ESP-NOW or Bluetooth.
  • Ports: Port 1883 (Standard TCP), Port 8883 (SSL/TLS encrypted for AWS IoT / Azure).
  • Quality of Service (QoS): QoS 0 (At most once — fire and forget), QoS 1 (At least once — the broker confirms receipt).

3. Supported Blockly Blocks (9 Blocks)

Drawing the blocks…

4. Simulator Behavior

[!IMPORTANT] Same inert-but-crash-free category as Wi-Fi, ESP-NOW, and Bluetooth (Sections 7.1–7.4) — with one twist: the failure itself is realistically simulated. OMS's MicroPython umqtt.simple stub deliberately makes connect() raise a real OSError, the same error a genuine device would get trying to reach a broker with no working internet connection:

  • MQTT Connect always lands in its own except branch — MQTT Status reports something like "Failed: [Errno -2]", and Is MQTT Connected? stays false forever.
  • MQTT Publish / MQTT Subscribe are both guarded by "is connected," so they never actually attempt to send anything.
  • On MQTT Message Received never fires — nothing is ever published to trigger it, since there's no real broker to publish through.
  • On the C++ side, this is simply a consequence of the already-documented Wi-Fi gap (Section 7.1) — WiFi.status() never reports connected, so the if (WiFi.status() == WL_CONNECTED) guard around connect_mqtt()/mqtt_client.loop() never runs at all. All blocks generate fully correct, real code for actual hardware — MQTT projects can only be meaningfully tested on real, uploaded hardware with a working internet connection, not through the Simulate button.
MQTT (Message Queue Telemetry Transport) — OMS Parts