Stop the war

Stand with Ukraine flag

Support Ukraine

Try it now Pricing
Cloud
Community Edition Professional Edition Cloud Edge PE Edge IoT Gateway License Server Trendz Analytics Mobile Application PE Mobile Application MQTT Broker
Documentation > Security > MQTT Transport > Basic MQTT Credentials
Getting Started
Devices Library Guides API FAQ
On this page

Basic MQTT authentication

MQTT Based Authentication is available for devices that connect using MQTT. You may change the device credential type from ‘Access Token’ to ‘MQTT Basic’. Basic MQTT credentials consist of the optional client id, username and password. There are three options available:

Authentication based on Client ID only.

For this purpose, you should populate only Client ID in the credentials form below. MQTT Clients will be able to connect with any username or password if they specify correct Client ID;

Let’s review a simple command to upload temperature readings using MQTT Client Id to ThingsBoard Cloud. See MQTT API for more details. The command is using plain MQTT without TLS:

1
mosquitto_pub -d -q 1 -h "mqtt.thingsboard.cloud" -p "1883" -t "v1/devices/me/telemetry" -i "YOUR_CLIENT_ID" -m {"temperature":25}

The above command uses mqtt.thingsboard.cloud host and 1883 port and requires mosquitto clients library that you can install using the following command: apt-get install mosquitto-clients

Authentication based on Username and Password.

For this purpose, you should populate only Username and Password in the credentials form below. MQTT Clients will be able to connect with any client ID if they specify correct Username and Password. Password is optional;

Let’s review a simple command to upload temperature readings using MQTT Client username and password to ThingsBoard Cloud. See MQTT API for more details. The command is using plain MQTT without TLS:

1
2
mosquitto_pub -d -q 1 -h "mqtt.thingsboard.cloud" -p "1883" \
-t "v1/devices/me/telemetry" -u "YOUR_CLIENT_USERNAME" -P "YOUR_CLIENT_PASSWORD" -m {"temperature":25}

The above command uses mqtt.thingsboard.cloud host and 1883 port and requires mosquitto clients library that you can install using the following command: apt-get install mosquitto-clients

Authentication based on Client ID, Username and Password.

For this option, you should populate Client ID, Username and Password. MQTT Clients will be able to connect if they specify correct combination of Client ID, Username and Password;

Let’s review a simple command to upload temperature readings using MQTT Client ID, username and password to ThingsBoard Cloud. See MQTT API for more details. The command is using plain MQTT without TLS:

1
2
mosquitto_pub -d -q 1 -h "mqtt.thingsboard.cloud" -p "1883" \
-t "v1/devices/me/telemetry" -i "YOUR_CLIENT_ID" -u "YOUR_CLIENT_USERNAME" -P "YOUR_CLIENT_PASSWORD" -m {"temperature":25}

The above command uses mqtt.thingsboard.cloud host and 1883 port and requires mosquitto clients library that you can install using the following command: apt-get install mosquitto-clients

MQTTS (MQTT over TLS)

One-way SSL authentication is a standard authentication mode, where your client device verifies the identity of a server using server certificate. ThingsBoard Cloud uses a valid certificate. Please download the CA root certificate using this link and save it to your working directory as “ca-root.pem”.

1
wget https://thingsboard.io/docs/paas/user-guide/resources/mqtt-over-ssl/ca-root.pem

Now you may use the ca-root.pem to setup secure connection to ThingsBoard Cloud and Access Token YOUR_ACCESS_TOKEN to authenticate the device to upload telemetry:

1
2
mosquitto_pub --cafile ca-root.pem -d -q 1 -h "mqtt.thingsboard.cloud" -p "8883" \
-t "v1/devices/me/telemetry" -i "YOUR_CLIENT_ID" -u "YOUR_CLIENT_USERNAME" -P "YOUR_CLIENT_PASSWORD" -m {"temperature":25}

The above command uses mqtt.thingsboard.cloud host and 8883 port and requires mosquitto clients library that you can install using the following command: apt-get install mosquitto-clients