Skip to main content
Publish to the MQTT topic <topic ID>. To receive the topic’s messages, subscribe to <topic ID>/out instead, see Read messages. You can authenticate with an access token or with the topic’s producer SCRAM credential.

With an access token

Use an account token or a producer subaccount token as the password:
The token is checked when the client connects. Get a fresh token for every new connection.

With SCRAM

The producer credential uses MQTT 5 enhanced authentication with SCRAM-SHA-512. Use a client library that supports the MQTT 5 AUTH packet, for example the handleAuth hook in MQTT.js.

Before you start

Reveal the Producer credential for MQTT on the topic card and note:

Connection settings

Premium endpoints use their own hostnames. Copy the exact URL from the topic card.

The exchange

Authentication data is the raw UTF-8 SCRAM message, not base64.
1

CONNECT

Protocol version 5, a client ID that is unique for every session, username = producer SCRAM username, no password.Properties: Authentication Method = SCRAM-SHA-512, Authentication Data = n,,n=<username>,r=<client-nonce>.
2

AUTH from the broker

Reason code 0x18 (continue). Authentication Data = server-first (r=…,s=…,i=…).
3

AUTH from the client

Reason code 0x18, Authentication Method = SCRAM-SHA-512, Authentication Data = client-final (c=biws,r=<server-nonce>,p=<proof>).Compute the proof as in the SCRAM-SHA-256 reference, but with SHA-512 and a 64-byte PBKDF2 key.
4

CONNACK

The broker replies with reason code 0x00. If it includes a server signature, verify it.
5

PUBLISH

Publish a JSON payload with QoS 1 to the topic ID and wait for PUBACK.
Two sessions with the same client ID disconnect each other. Give every session its own client ID.