When you connect a device to IoT Platform using a custom MQTT client, you must provide the MQTT signature authentication parameters: username, passwd, and mqttClientId.
Overview
Choose one of the following methods to obtain MQTT signature parameters.
|
Method |
Description |
|
The supported signature algorithm is hmacsha256. The device's client ID defaults to |
|
|
The supported signature algorithm is hmacsha256. The device's client ID defaults to |
Obtain from the IoT Platform console
-
Log on to the IoT Platform console.
On the Overview page, find the instance that you want to manage and click the instance ID or instance name.
-
In the left-side navigation pane, select to go to the Device page.
-
Find your device and click View to go to the Device Details page.
-
On the Device Information tab, click View next to MQTT Connection Parameters to view the MQTT signature parameters.
ImportantThe clientId parameter here maps to
mqttClientId, not the device's client ID. MQTT-TLS communication.The MQTT Connection Parameters dialog box displays the clientId, username, passwd, mqttHostUrl, and port values. Click Copy All to copy them.
Calculate using a Node.js script
-
Download and decompress the signTool.zip package, then modify and save the following parameters in the mqttSignTool.js file.
Parameter
Example
Description
productKey
a1Ee***
The device certificate saved when you added the device. Device certificate information.
View this information on the Device Details page in the console.
deviceName
8Co5***
deviceSecret
bcabcf***
timestamp
2524608000000
The current time in milliseconds.
briefId
12345
Optional. The device client ID.
Defaults to
${ProductKey} + '.' + ${DeviceName}. Example:var briefId = '12345'.ImportantCustom value, up to 64 characters. Use the device MAC address or SN for easy identification.
-
Download and install Node.js. This example uses Ubuntu 16.04 (64-bit) with
node-v16.5.0-linux-x64.tar.gz.-
Log on to your Linux VM.
-
Download and decompress the package.
wget https://nodejs.org/dist/v16.5.0/node-v16.5.0-linux-x64.tar.gz tar xf node-v16.5.0-linux-x64.tar.gz cd node-v16.5.0-linux-x64 ./bin/node -vA successful installation returns the version number.
v16.5.0 -
Add the node and npm commands from node-v16.5.0-linux-x64/bin to global PATH.
ln -s /root/node-v16.5.0-linux-x64/bin/npm /usr/local/bin/ ln -s /root/node-v16.5.0-linux-x64/bin/node /usr/local/bin/
-
-
Exit the node-v16.5.0-linux-x64 directory and create a signTool project folder.
cd.. mkdir signTool cd signTool/ -
Upload the modified mqttSignTool.js from step 1 to the signTool directory.
-
In the signTool directory, download the signature library.
npm install crypto-js lsExpected directory contents:
mqttSignTool.js node_modules package.json package-lock.json -
Run the mqttSignTool.js script.
node mqttSignTool.jsThe output contains the MQTT signature authentication parameters.
ImportantThe clientId parameter here maps to
mqttClientId, not the device's client ID. MQTT-TLS communication.username: xxx clientId: xxx|securemode=2,signmethod=hmacsha256,timestamp=2524608000000| passwd: xxx