MQTT Basics

Overview

MQTT is a publish/subscribe protocol. Unlike HTTPS, where the Device must poll the server, with MQTT the Device subscribes once and the broker pushes updates as they happen.

Once the connection is established (see Authenticating with MQTT), the Device subscribes to the topics it cares about.

Subscribing

The Device subscribes to one or more topics and processes messages as they arrive:

client.subscribe(`v1/device/${DEVICE_ID}/commands`)

client.on('message', function (topic, message) {
    console.log(topic, JSON.parse(message.toString()))
})

The HTTPS equivalent is to poll the server for pending Commands — which means deciding when to poll. The standard pattern is to call Send Telemetry periodically and check the command flag in the response:

fetch(`https://${SERVER_ENDPOINT}/v1/devices/${DEVICE_ID}/command`)

Because Telemetry runs on an interval (5–100+ seconds), there can be a noticeable delay between a user issuing a Command and the Device picking it up. With MQTT, the broker pushes the Command almost immediately — same end-to-end behavior, dramatically better latency, no polling overhead.

Topics and payloads

Xyte's MQTT topics and payloads mirror the HTTPS APIs one-to-one. Refer to the API Endpoints section for the field-level schema of each topic.