All Products
Search
Document Center

Marketplace:How to Calculate MQTT Connection Parameters

Last Updated:Mar 25, 2025

Important

DISCLAIMER

Please note that all content presented on this page is provided by Tuya (HK) Limited. Alibaba Cloud makes no representations and warranties, explicit or implied, as to the authenticity or accuracy of any such content, nor makes any guarantee to the condition, quality, durability, performance, reliability, merchantability or fitness for a particular purpose, or non-infringement of any products and/or services made available by Tuya (HK) Limited. 

When a device connects to IoT platform through the MQTT access tool you developed, you must enter the MQTT signature authentication parameters username, passwd, and mqttClientId. This topic describes how to obtain the value of the MQTT connection signature parameter.

Overview

You can select the following methods to obtain the MQTT signature parameters based on actual business needs.

Method

Method

Get it directly on the IoT platform

Copy page data for direct use. Note: The default 1883 provided on the page is TCP connection, which is unsafe and can be used during testing and verification. It is not recommended to use it in the production environment. For safe connections, see Device Connection Authentication

Using Web Tools to Calculate

The signature algorithms supported are hmacmd5 and hmacsha1.

How do I obtain MQTT parameters for authentication?

The signature algorithm supported is hmacsha256. The ClientId of the device defaults ${ProductKey} + '.' + ${DeviceName} the string composed of, which can be modified.

Get it directly on the IoT platform

  1. Log on to the IoT Platform console.

  2. In the left navigation bar, choose Device Management> Device List , enter equipment List page.

  3. In the device list, click details button, enter equipment Details page.

  4. In device Information tab, click connection parameters on the right view to obtain the MQTT signature parameter information.

image.png

Important Among them clientId is the mqttClientId value and should not be confused with the clientId of the device. For a detailed description of the MQTT connection parameters, see MQTT-TCP connection communication.

Calculate using web tools

  1. Click to download the MQTT_Password Toolkit and then decompress.

  2. In the folder MQTT_Password use the browser to open sign.html file.

image.png

  1. On the MQTT signature calculation page, enter the corresponding information as prompted, as shown in the following figure.

image.png

Parameters

Description

ProductKey

After you add a device, save the device certificate information, see Create a device. In the console, you can equipment Details page view.

DeviceName

DeviceSecret

Timestamp

The timestamp. Current time millisecond value, automatically populated. Every time the page is refreshed, it is updated.

ClientId

The Client ID of the device, which can be customized and can be less than 64 characters in length. We recommend that you use the MAC address or SN code of your device to identify and distinguish different devices.

Method

Signature algorithm type, supported hmacmd5 and hmacsha1 .

  1. Click Generate , calculation results displays the signature parameter values.

image.png

Use java language to calculate connection parameters and use paho to connect

Click to download java language code sample

  1. The code shows three ways to connect to the platform, running the corresponding main method to connect and publish and subscribe.

    1. Use TCP to establish an unencrypted and insecure connection. See ConnectTuyaIotPlatformTcpDemo

    2. Use a standard certificate to establish a secure TLS connection. See ConnectTuyaIotPlatformStandardCertDemo

    3. Use the Tuya self-signed certificate to establish a secure TLS connection. See ConnectTuyaIotPlatformSelfSignCertDemo

  2. The code calculates the connection parameters. You need to replace the variables productKey, deviceName, deviceSecret, and endpoint in the code.