MQTT Overview

A lightweight publish/subscribe protocol for real-time, low-bandwidth device communication.

MQTT

MQTT is an Internet of Things connectivity protocol designed as an extremely lightweight publish/subscribe messaging transport. It's ideal for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium.

Why use MQTT?

MQTT is especially useful for pushing data from the cloud to your devices.

Example — a cloud-controlled door lock:

  • With HTTP: the device must continuously poll, making GET requests to check whether the "Door Control" variable changed. This consumes bandwidth, drains battery, and isn't truly real-time.
  • With MQTT: the device "listens" to the cloud and is notified only when the variable changes. The connection stays open, but data travels only when necessary — saving battery and bandwidth, and enabling real-time control.

Quality of Service (QoS)

QoS guarantees message-delivery reliability. There are three levels:

LevelNameDescription
0At most onceBest-effort delivery. No guarantee the message arrives.
1At least onceGuarantees delivery at least once. The receiver sends a puback; if not received, the sender retries.
2Exactly onceGuarantees the message is received exactly once. Slowest (requires two request/response flows).
📘

Surfact supports QoS up to 1 (at least once).

Last Will and Testament (LWT)

LWT messages are sent by the broker when a client connection is interrupted (the client goes offline).

⚠️

LWT is not supported by Surfact.

Persistent sessions

Persistent sessions let the broker save client information if the connection is lost, enabling immediate reconnection.

⚠️

Persistent sessions are not supported. Setting the cleanSession flag to false has no effect. After a disconnection, the client must re-establish its connection settings.

Client ID

The Client ID is a unique identifier for each MQTT client connecting to the broker, used to track the client's state.

To avoid collisions with other Surfact users, your Client ID must be:

  • Alphanumeric
  • At least 20 characters long
  • Random

Retain flag

A retained message is a standard MQTT message with the retained flag set to true. The broker stores the last retained message (and its QoS) for that topic, and new subscribers immediately receive it upon subscription.

By design, every message published to the Surfact broker is marked as retained, regardless of whether the flag is set. This ensures the last value published to a variable is always available via MQTT subscription.

Similarly, when data is posted via HTTP, TCP, or UDP, Surfact publishes the last value to the broker — keeping the value consistent across all protocols.

Next steps


Did this page help you?