Cloud
ThingsBoard Documentation
Cloud Professional Edition Community Edition Edge IoT Gateway License Server Trendz Analytics Mobile Application PE Mobile Application
Try it now Pricing
Documentation > Security > MQTT Transport > Access Token based authentication
Getting Started
Guides API FAQ

On this page

Access Token authentication for MQTT

Access Token based authentication is the default device authentication type. The unique access token is generated once the device is created in ThingsBoard. It can be changed afterwards. The client must specify the access token as a username in MQTT connect message.

Plain MQTT (without SSL)

Let’s review a simple command to upload temperature readings using Access Token YOUR_ACCESS_TOKEN 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" -u "YOUR_ACCESS_TOKEN" -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 SSL)

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 certificate chain using this link and save it to your working directory as “tb-cloud-chain.pem”.

1
wget https://thingsboard.io/docs/paas/user-guide/resources/mqtt-over-ssl/tb-cloud-chain.pem

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

1
mosquitto_pub --cafile tb-cloud-chain.pem -d -q 1 -h "mqtt.thingsboard.cloud" -p "8883" -t "v1/devices/me/telemetry" -u "YOUR_ACCESS_TOKEN" -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