Python MQTT for IoT — ELI5

Imagine a bulletin board in the middle of a town square. Anyone can pin a note to the board, and anyone who is interested can walk over and read it. You do not need to know who will read your note, and readers do not need to know who wrote it. The board handles everything.

MQTT works exactly like that bulletin board, but for smart devices and computers. A temperature sensor in your garden pins a note saying “it is 22 degrees outside.” Your phone, your smart display in the kitchen, and your automated sprinkler system are all watching that section of the board. They each see the message and react in their own way.

The bulletin board has a name — it is called a broker. The broker is just a computer that receives messages and delivers them to everyone who is interested. Devices that send messages are called publishers. Devices that read messages are called subscribers. One device can be both.

The clever part is the board is organized into topics, like sections in a newspaper. Your garden sensor posts to “garden/temperature.” Your living room sensor posts to “livingroom/temperature.” Your phone subscribes only to the topics it cares about, so it is not overwhelmed by messages from every gadget in the house.

MQTT was invented for situations where devices have weak internet connections or very little power. The messages are tiny — just a few bytes — so even a sensor running on a watch battery can participate.

One thing to remember: MQTT is a bulletin board system that lets devices post and read tiny messages organized by topic, without needing to know about each other directly.

pythonmqttiotnetworking

See Also

  • Python Behavior Trees Robotics How robots make decisions using a tree-shaped rulebook that keeps them organized, like a flowchart that tells a robot what to do in every situation.
  • Python Bluetooth Ble How Python connects to fitness trackers, smart locks, and wireless sensors using the invisible radio signals all around you.
  • Python Circuitpython Hardware Why CircuitPython makes wiring up LEDs, sensors, and motors as easy as plugging in a USB drive.
  • Python Computer Vision Autonomous How self-driving cars use cameras and Python to see the road, spot pedestrians, read signs, and understand traffic — like giving a car human eyes and a brain.
  • Python Home Assistant Automation How Python turns your home into a smart home that reacts to you automatically, like a helpful invisible butler.