MQTT Authentication
Connect to the Surfact MQTT broker using your API token as the username.
MQTT Authentication
To connect to the Surfact MQTT broker you need a token — a unique key that authorizes your device to interact with the Surfact API.
Connection credentials
When establishing a connection with the MQTT broker, use the following credentials:
| Parameter | Value |
|---|---|
| Username | Your Surfact token |
| Password | Any character (not required) |
The password field can be left empty or set to any value — it is not validated.
Getting your token
See the Authentication guide for details on retrieving your token from your account and generating tokens programmatically.
Example connection
Python (paho-mqtt):
import paho.mqtt.client as mqtt
# Your Surfact token
token = "your-surfact-token"
client = mqtt.Client(client_id="my-device-12345678901234567890")
client.username_pw_set(username=token, password="")
client.connect("api.surfact.com", 8883)JavaScript (mqtt.js):
const mqtt = require('mqtt');
// Your Surfact token
const token = 'your-surfact-token';
const client = mqtt.connect('mqtts://api.surfact.com:8883', {
username: token,
password: '',
clientId: 'my-device-12345678901234567890'
});
Remember the Client ID requirements: alphanumeric, at least 20 characters, and random.
Updated 3 months ago
Did this page help you?