MQTT is a protocol designed to allow pieces of hardware to communicate with one another with a simple Pub/Sub(publisher/subscriber) model that consists of 3 basic parts.

  • Broker
  • Publisher(s)
  • Subscriber(s)

The broker is a piece of software that implements the MQTT protocol and runs on a server. This server handles authentication and authorization, management of topics, and QoS(Quality of Service); I use Mosquitto.

The publishers are clients of one form or another that publish messages to one or more MQTT topics. These can be pieces of hardware such as an Arduino, ESP8266 or pieces of software like a command-line client, or a browser plugin. I’ve found MQTTLens to be very useful when testing development of my Horizontal Plantation Blinds system

The subscribers are clients of one form or another that receive notifications when a publisher has added a message to a topic to which they are subscribed. They contact the broker and let it know they would like to receive updates on a topic and the broker fires events when messages are published to the topic.

You can take a look at the code for the NodeMCU for my blinds here and see that it’s publishing to one topic (livingRoom0/status) and subscribing to two (livingRoom0/tilt, livingRoom0/raise). Part of the code that handles the subscription also provides a callback method that the MQTT client invokes whenever a message is published to that topic.