Updated on 2023-11-23 GMT+08:00

Registering an End Device

Function

This API is used to register an end device.

URI

POST /v2/{project_id}/edgemgr/devices

Table 1 Path parameter

Parameter

Mandatory

Description

project_id

Yes

Project ID. For details about how to obtain a project ID, see Obtaining a Project ID.

Request

Request parameters

Table 2 Parameters in the request header

Parameter

Mandatory

Type

Description

Content-Type

Yes

String

Message body type (format).

The default value application/json is recommended.

X-Auth-Token

Yes

String

User token. The token can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

Table 3 Parameters in the request body

Parameter

Mandatory

Type

Description

device

Yes

Table 4 object

End device information.

Table 4 device

Parameter

Mandatory

Type

Description

id

No

String

End device ID. Enter 24 to 64 characters starting with a letter or digit. Only letters, digits, underscores (_), and hyphens (-) are allowed.

name

Yes

String

End device name. The name contains a maximum of 64 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

description

No

String

End device description. The description contains a maximum of 255 characters. The following characters are not allowed: ^~#$%&*<>()[]{}'"\

attributes

No

Object

Static properties. A maximum of 64 key-value pairs are supported.

The key indicates the property name. For details about the format of value, see Table 6. The following is an example:

"attributes": {
            "username": {
                "value": "test",
                "optional": true,
                "metadata": {
                    "type": "string"
                }
            }
        }

connection_type

No

String

Connection type. The default value is edge.

access_protocol

No

String

Access protocol. The options are as follows:

  • userdefine: custom protocol
  • modbus: Modbus protocol
  • opc-ua: OPC UA protocol

The default value is userdefine.

twin

No

Object

Dynamic properties. A maximum of 64 key-value pairs are supported.

The key indicates the property name. For details about the format of value, see Table 7. The following is an example:

"twin": {
            "devicestate": {
                "optional": true,
                "expected": {
                    "value": "running"
                },
                "metadata": {
                    "type": "string"
                }
            }
        }

access_config

No

Table 24 object

Access configuration, which varies depending on access_protocol.

property_visitors

No

Object

Twin property configuration. The key must be the same as that of the corresponding twin property. For details about the value format, see Table 25.

Example request

{
    "device": {
        "access_protocol": "userdefine",
        "name": "device",
        "connection_type": "edge",
        "description": "",
        "attributes": {}
    }
}

Response

Response parameters
Table 5 Parameters in the response body

Parameter

Type

Description

device

Table 6 object

Details about the end device.

Table 6 device

Parameter

Type

Description

id

String

End device ID.

name

String

End device name.

access_protocol

String

Access protocol.

description

String

End device description.

project_id

String

Project ID.

created_at

String

Creation time.

updated_at

String

Update time.

attributes

Object

Static properties. A maximum of 64 key-value pairs are supported.

The key indicates the property name. For details about the format of value, see Table 6. The following is an example:

"attributes": {
            "username": {
                "value": "test",
                "optional": true,
                "metadata": {
                    "type": "string"
                }
            }
        }

twin

Object

Dynamic properties. A maximum of 64 key-value pairs are supported.

The key indicates the property name. For details about the format of value, see Table 21. The following is an example:

"devicestate":{ 
                      "expected":{ 
                           "value":"running", 
                           "metadata":{ 
                                "timestamp":1536822119463 
                                } 
                           }, 
                     "optional":true, 
                     "metadata":{ "type":"string" } 
                     }

access_config

Table 24 object

Access configuration, which varies depending on access_protocol.

property_visitors

Object

Twin property configuration, which varies depending on access_protocol. The key indicates the property name. For details about the format of value, see Table 25.

connection_type

String

Connection type. The default value is edge.

Example response

{
    "device": {
        "id": "1398f13d-f24d-4de4-8cd3-5905db1d6d9f",
        "name": "device",
        "access_protocol": "",
        "project_id": "05e1aef9040010e22fccc009adecb056",
        "description": "",
        "created_at": "2020-09-23T02:00:22.858736Z",
        "updated_at": "",
        "access_config": {},
        "connection_type": "edge"
    }
}

Error Codes

For details, see Error Codes.