[IoT] MQTT Basic

Concepts

  • Publish/Subscribe

    1. Device 1 publishes a topic
    2. Device 2 is subscribed to the same topic in which device 1 is publishing in
    3. Device 2 receives the message
  • Messages: command or data

  • Topics
    1. Interest for incoming messages
    2. Specify where you want to publish

Topics are represented with strings separated by slashes “/“
Slashes indicate the topic level
Topics are case sensitive

  • Broker

    1. Receives all the messages
    2. Filters the messages
    3. Publishes the messages to all subscribed clients
  • QoS (Quality of Service)

    1. QoS 0: Fire and Forget ( I said it is enough)
    2. QoS 1: At Least One (A: Hello, … wait till B: Yes I hear you)
    3. QoS 2: Exactly Once (A: Hello, … wait till B: Yes I hear you, A: Good, I won’s say again…B: Wonderful conversation)

QoS only applies to connected clients. If client is not connected, they’ll never receive the message. Retained Message: MQTT broker stores that message and sends it to any new subscribers.