Before you start
To connect to MQTT One you need a broker address, a username and a password. These are created for you automatically when you start a project on the iotBind platform.
- Create a free account or log in on iotBind.
- Create a new project (or open an existing one).
- Open the project details to find your broker address, credentials and the topics assigned to it.
Connection details
Use the values below with any MQTT client. In the examples on this page, your-broker.mqtt.one is a placeholder: replace it with the broker address shown in your project.
| Setting | Value |
|---|---|
| Broker address | your-broker.mqtt.one (from your project) |
| MQTT (TCP) | 1883 |
| MQTT over TLS | 8883 |
| WebSocket | 8083, path /mqtt |
| Secure WebSocket | 8084, path /mqtt |
| Username / password | Your broker credentials from the project |
| Client ID | Any unique value per device, e.g. esp32-kitchen-01 |
| Protocol version | MQTT 3.1 / 3.1.1 |
Several brokers are available, and each project uses its own broker address. Always copy the exact address from your project.
Code examples
Pick your platform. Replace YOUR_USERNAME, YOUR_PASSWORD, the broker address and your/topic with the values from your project.
# Subscribe to a topic (keeps listening)
mosquitto_sub -h your-broker.mqtt.one -p 1883 \
-u "YOUR_USERNAME" -P "YOUR_PASSWORD" \
-t "your/topic" -q 1 -v
# Publish a message from another terminal
mosquitto_pub -h your-broker.mqtt.one -p 1883 \
-u "YOUR_USERNAME" -P "YOUR_PASSWORD" \
-t "your/topic" -m "hello from MQTT One" -q 1
# Encrypted connection over TLS
mosquitto_sub -h your-broker.mqtt.one -p 8883 --capath /etc/ssl/certs \
-u "YOUR_USERNAME" -P "YOUR_PASSWORD" -t "your/topic"# pip install paho-mqtt
import paho.mqtt.client as mqtt
BROKER = "your-broker.mqtt.one"
TOPIC = "your/topic"
def on_connect(client, userdata, flags, reason_code, properties):
print("Connected:", reason_code)
client.subscribe(TOPIC, qos=1)
def on_message(client, userdata, msg):
print(msg.topic, msg.payload.decode())
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
client.username_pw_set("YOUR_USERNAME", "YOUR_PASSWORD")
client.on_connect = on_connect
client.on_message = on_message
client.connect(BROKER, 1883, keepalive=60)
client.publish(TOPIC, "22.5", qos=1)
client.loop_forever()// ESP32 / ESP8266 with the PubSubClient library
#include <WiFi.h> // use <ESP8266WiFi.h> on ESP8266
#include <PubSubClient.h>
const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
const char* BROKER = "your-broker.mqtt.one";
const char* MQTT_USER = "YOUR_USERNAME";
const char* MQTT_PASS = "YOUR_PASSWORD";
const char* TOPIC = "your/topic";
WiFiClient net;
PubSubClient mqtt(net);
void onMessage(char* topic, byte* payload, unsigned int length) {
Serial.printf("%s: %.*s\n", topic, (int)length, (char*)payload);
}
void reconnect() {
while (!mqtt.connected()) {
String id = "esp32-" + String((uint32_t)ESP.getEfuseMac(), HEX);
if (mqtt.connect(id.c_str(), MQTT_USER, MQTT_PASS)) {
mqtt.subscribe(TOPIC);
} else {
delay(3000);
}
}
}
void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) delay(500);
mqtt.setServer(BROKER, 1883);
mqtt.setCallback(onMessage);
}
void loop() {
if (!mqtt.connected()) reconnect();
mqtt.loop();
static unsigned long last = 0;
if (millis() - last > 10000) {
last = millis();
mqtt.publish(TOPIC, String(analogRead(34)).c_str());
}
}// npm install mqtt
import mqtt from "mqtt";
const client = mqtt.connect("mqtt://your-broker.mqtt.one:1883", {
username: "YOUR_USERNAME",
password: "YOUR_PASSWORD",
clientId: "node-" + Math.random().toString(16).slice(2, 10),
});
client.on("connect", () => {
client.subscribe("your/topic", { qos: 1 });
client.publish("your/topic", JSON.stringify({ temp: 22.5 }), { qos: 1 });
});
client.on("message", (topic, payload) => {
console.log(topic, payload.toString());
});<!-- MQTT over secure WebSocket, directly from the browser -->
<script src="https://unpkg.com/mqtt/dist/mqtt.min.js"></script>
<script>
const client = mqtt.connect("wss://your-broker.mqtt.one:8084/mqtt", {
username: "YOUR_USERNAME",
password: "YOUR_PASSWORD",
});
client.on("connect", () => client.subscribe("your/topic"));
client.on("message", (topic, payload) => {
document.body.insertAdjacentText("beforeend", topic + ": " + payload + "\n");
});
// Plain WebSocket is also available: ws://your-broker.mqtt.one:8083/mqtt
</script>Topics and access rules
Each broker user can only publish or subscribe to the topics it has been granted. Your project lists the topics you can use and whether each one allows publishing, subscribing or both.
- Use the exact topic names shown in your project — topic names are case-sensitive.
- Use levels separated by
/to organize data, for exampleyour/topic/temperature. - Use letters, numbers, dashes and underscores; avoid spaces and special characters.
- Wildcards
+and#can be used when subscribing, within the topics you are allowed to access.
Best practices
Unique client IDs
Two clients with the same client ID disconnect each other. Give every device its own ID.
Keep alive
Use a keep-alive interval of 30–60 seconds so broken connections are detected quickly.
Reconnect automatically
Networks drop. Make your device retry the connection with a short delay instead of stopping.
Choose the right QoS
QoS 0 for frequent telemetry, QoS 1 for most messages, QoS 2 only when duplicates are unacceptable.
Retain and Last Will
Retain the latest state, and register a Last Will message to announce when a device goes offline.
Encrypt on public networks
Use port 8883 (TLS) or 8084 (secure WebSocket) whenever data crosses the internet.
Troubleshooting
| Problem | What to check |
|---|---|
| Connection refused: not authorized | Check the username and password, and make sure you copied the broker address of the same project. |
| Connected, but no messages arrive | Make sure the publisher and subscriber use exactly the same topic and that your user is allowed to subscribe to it. |
| Disconnects every few seconds | Another client is probably using the same client ID. Use a unique ID per device. |
| Cannot connect from the browser | Browsers need WebSocket: use port 8084 with wss:// and the path /mqtt. |
| Connection times out | Your network may block the port. Try another port such as 8883 or 8084, or test from a different network. |