Messaging protocols allow devices to communicate with each other. The most common type of messaging protocols is publish-subscribe (pub-sub).

MQTT

MQTT is a lightweight messaging protocol for IoT devices. It is based on the publish-subscribe pattern.

sequenceDiagram
    participant A as Client A
    participant C as Broker
    participant B as Client B

    A->>C: CONNECT
    B->>C: CONNECT
    A->>C: SUBSCRIBE "topic"
    B->>C: PUBLISH "topic" "message"
    C-->>A: "message"

Setup

Broker Status

Broker status information can be queried using the mqtt CLI tool:

  mqtt sub -t '$SYS/#' -h 'test.mosquitto.org'
  

More endpoints can be found in the documentation.

Last Will and Testament

This feature allows to send a message to a topic when the client disconnects. It can be used to detect if a client is still connected or to send one last package.

sequenceDiagram
    participant L as Light
    participant B as Broker
    participant D as Dashboard

    L->>B: CONNECT Will="light/status" "offline"
    D->>B: SUBSCRIBE "light/status"
    note left of B: Light is unplugged and goes offline
    B-->>D: "message"
  
## Protobuf