Before you connect a device to IoT Platform, you must register the device with IoT Platform. This way, IoT Platform can identify the device.
Overview
You can use the following methods to register devices:
Unique-certificate-per-device verification: Create a device in IoT Platform, obtain the device certificate, and then use the certificate information as the unique identifier. The certificate information includes the ProductKey, DeviceName, and DeviceSecret. Burn the certificate information into the firmware of the device. After the device is connected to IoT Platform, the device can communicate with IoT Platform. For more information, see Unique-certificate-per-device verification.
The following table describes the protocols over which you can register devices.
Device
Supported protocol
Device registration
References
Directly connected devices
MQTT
HTTPS
Gateways and sub-devices
MQTT
Unique-certificate-per-product verification: Burn a product certificate to all devices of the product. The product certificate includes a ProductKey and a ProductSecret. You must enable the dynamic registration feature for the product to which your device belongs.
The following dynamic registration methods are supported:
Pre-registration: If you use this method, you must register a device in the IoT Platform console. The device is dynamically registered to obtain a DeviceSecret.
Preregistration-free: If you use this method, you do not need to register a device in the IoT Platform console. The device is dynamically registered to obtain a ClientID and a DeviceToken.
NoteYou cannot implement preregistration-free unique-certificate-per-product verification over HTTPS.
For more information about how to register a device, see Unique-certificate-per-product verification. Gateway sub-devices support only the pre-registration method. For more information about the registration process, see Gateways and sub-devices.
The following table describes the protocols over which you can register devices.
Device
Supported protocol
Device registration
Data format description
Directly connected devices
MQTT
HTTPS
Gateways and sub-devices
MQTT
MQTT-based dynamic registration for sub-devices
Request topic:
/sys/{productKey}/{deviceName}/thing/sub/register
Response topic:
/sys/{productKey}/{deviceName}/thing/sub/register_reply
Sample request:
{
"id": "123",
"version": "1.0",
"sys":{
"ack":0
},
"params": [
{
"deviceName": "deviceName1234",
"productKey": "a1234******"
}
],
"method": "thing.sub.register"
}
Sample response:
{
"id": "123",
"code": 200,
"data": [
{
"iotId": "12344",
"productKey": "a1234******",
"deviceName": "deviceName1234",
"deviceSecret": "xxxxxx"
}
]
}
The following table describes the parameters.
Parameter | Data type | Description |
id | String | The ID of the message. Valid values: 0 to 4294967295. Each message ID must be unique for the device. |
version | String | The version number of the protocol. Set the value to 1.0. |
sys | Object | The parameter for extended features. The value contains the fields for each feature. Note If no extended features are configured when you use a device SDK to develop device features, this parameter is unavailable. The extended features use the default configurations. |
ack | Integer | The extended feature field in the sys parameter. This field specifies whether IoT Platform returns response data for a registration request. Valid values:
Important For more information about the parameter, see Examples on how to use a TSL model. If the feature is not configured, this parameter is unavailable. By default, IoT Platform returns response data for a registration request. |
params | List | The parameters used for dynamic registration. |
deviceName | String | The DeviceName of the sub-device. |
productKey | String | The ProductKey of the product to which the sub-device belongs. |
iotId | String | The unique identifier of the sub-device. |
deviceSecret | String | The DeviceSecret of the device. |
method | String | The request method. Set the value to thing.sub.register. |
code | Integer | The status code that indicates the result. |
The following table describes the error codes.
Error code | Message | Description |
460 | request parameter error | The request parameters are invalid. |
6402 | topo relation cannot add by self | A device cannot be added as a sub-device of itself. |
401 | request auth error | The system failed to verify the signature. |
HTTPS-based dynamic registration for directly connected devices
URL format:
https://iot-auth.${YourRegionId}.aliyuncs.com/auth/register/device
HTTP method: POST.
Sample request:
POST /auth/register/device HTTP/1.1 Host: iot-auth.cn-shanghai.aliyuncs.com Content-Type: application/x-www-form-urlencoded Content-Length: 123 productKey=a1234******&deviceName=deviceName1234&random=567345&sign=adfv123hdfdh&signMethod=HmacMD5
Sample response:
{ "code": 200, "data": { "productKey": "a1234******", "deviceName": "deviceName1234", "deviceSecret": "adsfw******" }, "message": "success" }
The following table describes the parameters.
Parameter
Data type
Description
Method
String
The request method. Valid value: POST.
Host
String
The endpoint that is used to dynamically register devices over HTTPS. Format:
iot-auth.${YourRegionId}.aliyuncs.com
.${YourRegionId}
: Replace this variable with the ID of the region where your IoT Platform device resides.The following regions support HTTPS-based dynamic registration: all regions except the China (Beijing) and China (Shenzhen) regions.
For information about the format of region IDs, see Supported regions.
Content-Type
String
The encoding format of the upstream data that the device sends to IoT Platform.
productKey
String
The unique identifier of the product.
deviceName
String
The DeviceName of the device.
random
String
A random string.
sign
String
The signature.
You can create a signature by using the following method:
Sort all parameters that are submitted to IoT Platform excluding sign and signMethod in alphabetical order, and concatenate the parameters and values in sequence without concatenation operators.
Use the signature method that is specified by the signMethod parameter and the ProductSecret of the product to generate a signature.
Example:
hmac_sha1(productSecret, deviceNamedeviceName1234productKeya1234******random123)
signMethod
String
The signature method. Valid values: hmacmd5, hmacsha1, and hmacsha256.
code
Integer
The status code that indicates the result.
deviceSecret
String
The DeviceSecret of the device.