Parameter | Description |
Endpoint | The endpoint of the public instance or Enterprise Edition instance to which you want to connect the MQTT client. For more information about the supported endpoints, see Manage the endpoint of an instance. |
Variable header: Keep Alive | The CONNECT message must include the Keep Alive parameter. The keep-alive period can be 30 to 1,200 seconds. We recommend that you set a keep-alive period that is longer than 300 seconds. If the network connection is unstable, we recommend that you set a longer keep-alive period. If the value of the Keep Alive parameter is not in this range, IoT Platform rejects the connection. For more information, see MQTT keep-alive mechanism. |
Parameters in an MQTT CONNECT message | Unique-certificate-per-device verification and pre-registration unique-certificate-per-product verification: Use the device certificate (ProductKey, DeviceName, and DeviceSecret) to connect the device to IoT Platform.
mqttClientId: clientId+"|securemode=3,signmethod=hmacsha1,timestamp=132323232|"
mqttUsername: deviceName+"&"+productKey
mqttPassword: sign_hmac(deviceSecret,content)
- mqttClientId: Extended parameters are placed between vertical bars (
| | ). - clientId: the ID of the client. You can specify a client ID based on your business requirements. The client ID cannot exceed 64 characters in length. We recommend that you use the MAC address or serial number (SN) of the device as the client ID.
- securemode: the current security mode. Valid values: 2 (direct TLS connection) and 3 (direct TCP connection).
- signmethod: the signature algorithm. Valid values: hmacmd5, hmacsha1, hmacsha256, and sha256. Default value: hmacmd5.
- timestamp: the current time, in milliseconds. This parameter is optional.
- mqttPassword: the password. Calculation method: Sort the parameters that are submitted to the server in alphabetical order and encrypt the parameters based on the specified signature algorithm. For more information about the signature calculation example, see Examples of creating signatures for MQTT connections.
- content: a concatenated string consisting of the parameters that are submitted to the server. These parameters include productKey, deviceName, timestamp, and clientId. The parameters are sorted in alphabetical order and concatenated without delimiters.
Important productKey and deviceName are required. timestamp and clientId are optional. If you configure the timestamp or clientId parameter, the parameter value must be the same as the value that is specified for the mqttClientId parameter.
Example: The following values are specified: clientId=12345, deviceName=device, productKey=pk, timestamp=789, signmethod=hmacsha1, deviceSecret=secret . The following code shows the parameters in an MQTT CONNECT message that is sent over TCP:
mqttclientId=12345|securemode=3,signmethod=hmacsha1,timestamp=789|
mqttUsername=device&pk
mqttPassword=hmacsha1("secret","clientId12345deviceNamedeviceproductKeypktimestamp789").toHexString();
The encrypted password is a hexadecimal string that is converted from a binary string. The following code shows the result:
FAFD82A3D602B37FB0FA8B7892F24A477F85****
For more information about how to obtain the MQTT signature parameters, see How do I obtain MQTT parameters for authentication?. |
Preregistration-free unique-certificate-per-product verification: Use ProductKey, DeviceName, ClientID, and DeviceToken to connect the device to IoT Platform.
mqttClientId: clientId+"|securemode=-2,authType=connwl|"
mqttUsername: deviceName+"&"+productKey
mqttPassword: deviceToken
- mqttClientId: Extended parameters are placed between vertical bars (
| | ). - clientId, deviceToken: the ClientID and DeviceToken that are obtained when the device is dynamically registered. For more information, see MQTT-based dynamic registration.
- securemode: the current security mode. If you use preregistration-free unique-certificate-per-product verification, set the value to -2.
- authType: the verification method. If you use preregistration-free unique-certificate-per-product verification, set the value to connwl.
|