Setting up MQTT

Overview

Enabling MQTT for a Device takes three steps:

  1. Create an MQTT-enabled Device Model in the Partner Portal.
  2. Register the Device via the HTTPS-based Register Device API.
  3. Connect via MQTT using the credentials returned by registration.

Create an MQTT Device Model

In the Partner Portal, open the Add Model dialog and choose MQTT under Communication Protocol.

📘

The communication protocol is fixed at Device Model creation and cannot be changed afterwards.

778

Register the Device

Call the HTTPS-based Register Device API. A successful registration returns:

{
    "id": "11111111-2222...",
    "access_key": "Secret key for this device...",
    "hub_url": "hub-url.com",
    "hub_url_static_cert": "hub-url-static.com",
    "mqtt_hub_url": "mqtt://mqtt-url.com:port"
}

For MQTT, three of these fields matter:

  • id — the unique Device ID.
  • access_key — the credential used to authenticate with the MQTT service.
  • mqtt_hub_url — the MQTT Hub Server assigned to this Device.
📘

Registration credentials are shared between MQTT and HTTPS — the same id and access_key work for both transports.

Connect via MQTT

Connecting to Xyte over MQTT requires an MQTT v5–capable client library for your target language:

📘

A comprehensive list of MQTT client implementations can be found at the official MQTT website.

Example: connecting with MQTT.js

Pass the following options to the client (using values from the Register Device API response):

  • protocolVersion5, to enable MQTT v5.
  • username — the Device's id.
  • password — the Device's access_key.
  • clientId — the Device's id.
📘

Always set the protocol version explicitly. Without it, most clients negotiate down to MQTT v3.1.1 and you lose the v5 features Xyte relies on.

import mqtt from 'mqtt';

const client = mqtt.connect(URL, {
  protocolVersion: 5,
  username: DEVICE_ID,
  password: ACCESS_KEY,
  clientId: DEVICE_ID,
});

Once the client is connected, you can subscribe to any of the available topics.