---
updatedAt: 2026-05-07T19:52:13.000Z
agentTools:
  projectIndex: https://dev.xyte.io/llms.txt
---

# 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](https://dev.xyte.io/reference/authentication)), the Device subscribes to the topics it cares about.

## Subscribing

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

```typescript Subscribe to incoming commands with MQTT
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](https://dev.xyte.io/reference/send-telemetry) periodically and check the `command` flag in the response:

```typescript Get pending command (if available) with HTTP
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](https://dev.xyte.io/reference/overview-1) section for the field-level schema of each topic.