MQTT Protocol Reference
Connection parameters, topic structure, payload formats, and quality-of-service details for devices connecting to Beacon Tower via MQTT.
Connection Parameters
| Parameter | Description | Example |
|---|---|---|
| Protocol | MQTT 3.1.1 over TLS | — |
| Host | Broker DNS name from onboarding — connect by this name, never by IP | mqtt.example.com |
| Port | 8883 (TLS) or 8884 (mutual TLS) | — |
| SNI | The broker host name, sent as the TLS server name | mqtt.example.com |
| Keepalive | At most 120 s; 60 s on a cellular link | 60 |
| Username | Device ID | temp-sensor-001 |
| Password | Primary key from provisioning | aB3x... |
| Client ID | Unique per connection (conventionally the device ID) | temp-sensor-001 |
| Clean Session | true (recommended) | — |
Devices receive their host, port, and credentials from the Onboarding Service via GET /get_settings.
TLS, Hostname, and SNI
Every tenant on an environment shares one public IP and the same 8883/8884 ports. The only thing that picks a given tenant's broker out of that shared address is the TLS server name (SNI) the device sends in the ClientHello. A device MUST:
- Connect using the broker's DNS name (
mqtt.<tenant domain>) fromget_settings— never a literal IP address. - Send that same name as the TLS SNI. Any client that connects by hostname and does standard certificate validation does this automatically; do not disable it.
- Verify the broker certificate's hostname against the name it connected to.
A device that sends no SNI, or one naming no tenant on the environment, reaches only the environment's default MQTT tenant — not necessarily its own. In a single-tenant environment that is every device, as today; on a shared environment it is a misrouted connection.
Keepalive
Devices MUST set an MQTT keepalive of at most 120 seconds, or 60 seconds on a cellular link. The platform's load balancer drops a TCP flow that has been idle for 4 minutes, and mosquitto disconnects a client that sends no MQTT packet for 1.5× the keepalive it requested in CONNECT — so a 120 s keepalive disconnects at 180 s, inside the load balancer's window. Home routers and mobile carrier NAT can drop an idle connection sooner than either of those, which is why cellular devices should keep to 60 s.
Authentication
The MQTT broker uses username/password authentication backed by a credentials database:
- Username = device ID
- Password = primary key (or secondary key during rotation)
- Passwords are stored as bcrypt hashes — the broker verifies against the hash at connect time
For certificate-based deployments, the broker authenticates devices via mTLS using Glaze CA-issued X.509 certificates instead of username/password. The device identity and tenant are extracted from the certificate's CN and OU fields. See Onboarding flows for details.
Access Control
Each device is restricted by an ACL to five topics of its own:
| Topic | Device may |
|---|---|
device/{deviceId}/telemetry | Publish |
device/{deviceId}/twin/reported | Publish |
device/{deviceId}/command/+/response/+ | Publish |
device/{deviceId}/twin/desired | Subscribe |
device/{deviceId}/command/+/invoke | Subscribe |
A device cannot publish to or subscribe to another device's topics, nor to any other topic under its own device/{deviceId}/ prefix. The ACL is created automatically during provisioning.
If the broker cannot reach its credential database, it refuses new connections and denies authorisation checks it cannot answer from its cache. A device that is refused during such an outage should retry with backoff, as for any other disconnect.
Reconnection
Devices should implement exponential backoff on disconnection:
| Attempt | Delay |
|---|---|
| 1 | 1 second |
| 2 | 2 seconds |
| 3 | 4 seconds |
| ... | doubles each time |
| Max | 60 seconds |
What a device does when reconnecting keeps failing depends on its onboarding tier:
- Tier 0 — keep retrying the broker with this backoff. The device has no other source of settings.
- Tier 1 and 2 — retry the broker a few times with backoff, then fetch fresh settings from onboarding and connect with what it returns. Do this when the broker stays unreachable and when it refuses the credentials. Retrying the broker first keeps a short outage from sending every device to onboarding at once. See Device Onboarding.
Topic Structure
All device communication uses the device/{deviceId}/ topic prefix.
Telemetry (Device → Cloud)
device/{deviceId}/telemetry
QoS: 1 (At Least Once)
The device publishes JSON payloads containing sensor readings:
{"temperature": 22.5, "humidity": 48.2}
Multi-signal payloads are supported — each key becomes a separate telemetry signal in the platform. The payload format must match what the ingress pipeline expects for the configured parser.
Standard Format (Default Parser)
A flat JSON object where keys are signal names and values are readings:
{"motor_temp": 85.5, "inlet_pressure": 101.3}
With Timestamp
Include a timestamp field (ISO 8601) to set the measurement time. If omitted, the broker receive time is used:
{"motor_temp": 85.5, "timestamp": "2026-02-25T10:30:00Z"}
The timestamp key is consumed by the parser and not forwarded as a signal.
Several Readings in One Message
A JSON array of objects is split, and each object is handled as its own telemetry message:
[
{"motor_temp": 85.5, "timestamp": "2026-02-25T10:30:00Z"},
{"motor_temp": 85.9, "timestamp": "2026-02-25T10:30:10Z"}
]
A device that buffered readings while offline can send them in one publish.
Supported Value Types
| JSON Type | Example | Notes |
|---|---|---|
| Number | 85.5, 42, -10 | Most common for telemetry |
| Boolean | true, false | Binary states |
| String | "running", "idle" | Status codes, enums |
| Object | {"lat": 59.33, "lon": 18.07} | Structured values |
| Array | [1.0, 2.0, 3.0] | Vector/batch values |
Custom Parsers
For non-standard payload formats, the device can be configured with a parser. See Parsers for OBIS, structured metric, and JMESPath options.
Reported Properties (Device → Cloud)
device/{deviceId}/twin/reported
QoS: 1 (At Least Once)
The device publishes its current state as a JSON object:
{
"firmware_version": "2.1.0",
"reporting_interval": 60,
"battery_level": 87
}
Reported properties are:
- Stored in the device twin database with an incremented version counter
- Forwarded to the message queue as a
ProviderClientPropertiesChangedmessage for downstream processing
See Device Twins for the full twin model.
Desired Properties (Cloud → Device)
device/{deviceId}/twin/desired
QoS: 1 (At Least Once)
The device subscribes to this topic to receive configuration updates from the cloud. When an operator sets desired properties (via the platform API), the broker delivers the full desired state on this topic:
{
"reporting_interval": 30,
"alert_threshold": 85.0
}
The device should apply the desired configuration and then publish updated reported properties to confirm.
A zero-length message on this topic means the retained desired state was cleared, which happens when the device is unprovisioned. Do not parse it as JSON.
Commands (Cloud → Device)
Commands use a request/response pattern with correlation IDs:
Invocation (device subscribes):
device/{deviceId}/command/{commandName}/invoke
Response (device publishes):
device/{deviceId}/command/{commandName}/response/{correlationId}
See Commands for the full protocol.
QoS Levels
All Beacon Tower MQTT communication uses QoS 1 (At Least Once):
- The broker acknowledges receipt with a PUBACK
- If no PUBACK is received, the client retransmits
- Duplicate messages are possible — the platform handles idempotency
QoS 0 (fire-and-forget) is not recommended as it provides no delivery guarantee. QoS 2 (exactly once) is supported by MQTT but not required by the platform.
Message Size
The maximum message size is determined by the broker configuration. The platform enforces a 1 MB limit per message. Keep telemetry payloads well under this — typical messages are a few hundred bytes.
Complete Example
A temperature sensor connecting and publishing telemetry:
import paho.mqtt.client as mqtt
import json, time
# Credentials from GET /get_settings
DEVICE_ID = "temp-sensor-001"
BROKER_HOST = "mqtt.example.com"
BROKER_PORT = 8883
PASSWORD = "device-primary-key"
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2,
client_id=DEVICE_ID, clean_session=True)
client.username_pw_set(DEVICE_ID, PASSWORD)
client.tls_set() # connecting by hostname sends SNI and verifies it automatically
client.connect(BROKER_HOST, BROKER_PORT, keepalive=120) # 60 on a cellular link
client.loop_start()
# Subscribe to desired properties and commands
client.subscribe(f"device/{DEVICE_ID}/twin/desired", qos=1)
client.subscribe(f"device/{DEVICE_ID}/command/+/invoke", qos=1)
# Publish telemetry
while True:
payload = json.dumps({"temperature": 22.5, "humidity": 48.2})
client.publish(f"device/{DEVICE_ID}/telemetry", payload, qos=1)
time.sleep(10)
Next Steps
- Device Twins — Managing desired and reported properties
- Commands — Invoking commands on devices
- Telemetry Ingestion — How the platform processes published telemetry
- Device Onboarding — How devices obtain their credentials
- Onboarding flows — How a device gets its credentials, by tier