Skip to content
BENIBIX Learn

MQTT Protocol

Development🔌 Embedded & IoTDevice Communication

Also known as MQTT, MQTT Broker, Mosquitto, MQTT Topic

A small way for devices to send messages. They post to a topic on a broker.

Think of it like

It is like a notice board. Devices pin notes under a topic. All who follow it get a copy.

Example

Lucy's greenhouse sensor publishes to the topic greenhouse/temp. Her phone app and the fan both subscribe, so both get each reading.

Why it matters

Its messages are tiny, so it works on weak links and small chips. Adding a new listener needs no change to the sensor.

Definition

MQTT is a light messaging protocol made for small devices on the Internet of Things. Devices do not talk to each other straight. They send messages to a server called a broker, under a name called a topic. This is called publishing. Any device or app that subscribes to that topic gets the message. It is an OASIS standard.

Example code

console
$ mosquitto_pub -h localhost -t greenhouse/temp -m 24.5
$ mosquitto_sub -h localhost -t greenhouse/temp
24.5
One command publishes a reading to a topic. Anyone subscribed to it gets 24.5.
The sensor posts to the broker. Each app that subscribed gets a copy.

Common mistake

Running a broker on the open internet with no password. Anyone can then read your sensors and send your devices orders.

Key takeaways

  1. 1
    Broker in the middle. Devices never talk straight.
  2. 2
    Topics. Messages go under a name.
  3. 3
    Small messages. Built for weak links.