Categories

MQTT Basics

WIKI:

What is MQTT?

Message Queuing Telemetry Transport is a publish/subscribe messaging protocol that works on top of the standard network TCP/IP protocol. The MQTT protocol was first developed by Andy Stanford-Clark of IBM and Arlen Nipper of Cirrus Link (then Eurotech), way back in 1999.

What makes MQTT attractive on the communications front is the very small messages (can be as small as 2 bytes), whereas other message protocol headers used on the internet requires (such as HTTP), contains a lot more information.  This makes it a great and efficient way to provide communications from machine-to-machine or “Internet of Things”.

The other super feature is that with MQTT, when a server (broker), receives information from one client (light switch or door bell for example) , it will automatically, and quickly, distribute that information to each of the interested clients (such as your light bulb or door ringer).  This makes the process appear seamless and almost instant.

The Basics

Learning how to build a MQTT network will help to understand some of the jargon that’s used and how each piece fits together to create your network.

  • Broker – The broker is the server that distributes the information to the interested clients connected to the server.
  • Client – The device that connects to broker to send or receive information.
  • Topic – The name that the message is about. Clients publish, subscribe, or do both to a topic.
  • Publish – Clients that send information to the broker to distribute to interested clients based on the topic name.
  • Subscribe – Clients tell the broker which topic(s) they’re interested in. When a client subscribes to a topic, any message published to the broker is distributed to the subscribers of that topic. Clients can also unsubscribe to stop receiving messages from the broker about that topic.
  • QoS – Quality of Service. Each connection can specify a quality of service to the broker with an integer value ranging from 0-2. The QoS does not affect the handling of the TCP data transmissions, only between the MQTT clients. Note: In the examples later on, we’ll only be using QoS 0.
    • 0 specifies at most once, or once and only once without requiring an acknowledgement of delivery. This is often referred to as fire and forget.
    • 1 specifies at least once. The message is sent multiple times until an acknowledgement is received, known otherwise as acknowledged delivery.
    • 2 specifies exactly once. The sender and receiver clients use a two level handshake to ensure only one copy of the message is received, known as assured delivery.

MQTT

As previously mentioned, MQTT is a publish/subscribe messaging protocol.

Clients will connect to the network, which can subscribe, or publish, to a topic. When a client publishes to a topic, the data is sent to a MQTT broker, which then is automatically distributed to all the other clients that are subscribed to that topic.

Where does WREN fit into MQTT?

WREN is both a publisher and subscriber to MQTT.  It can send (publish), MQTT messages when it receives an input (such as pressing the up/down buttons), and receive (subscribe), MQTT messages, which could turn on/off the recliner motor output.

Leave a Reply