Creating an Edge Device Template

Function

This API is used to create an edge device template.

URI

POST /v2/{project_id}/edgemgr/device_templates

Table 1 URI parameter

Parameter

Mandatory

Description

project_id

Yes

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

Request

Table 2 Parameters in the request body

Parameter

Mandatory

Type

Description

device_template

Yes

device_template object

Device template information.

Table 3 device_template

Parameter

Mandatory

Type

Description

name

Yes

String

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

access_protocol

Yes

String

Access protocol. The options are as follows:

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

description

No

String

Device template description. The value contains a maximum of 255 characters.

attributes

No

Object

Static properties of an edge device. 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

No

Object

Dynamic properties of an edge device. 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"
                }
            }
        }

tags

No

Object

Device template tag, in key-value pair format.

property_visitors

No

Object

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

Example request

{
    "device_template": {
        "name": "CameraTemplate",
        "access_protocol": "userdefine",
        "description": "This is a camera template",
        "attributes": {
            "cameraURL": {
                "value": "127.0.0.1",
                "optional": true,
                "metadata": {
                    "type": "string"
                }
            }
        },
        "twin": {
            "runstate": {
                "expected": {
                    "value": "running"
                },
                "optional": false,
                "metadata": {
                    "type": "string"
                }
            }
        },
        "tags": {
            "dev": "dev1"
        }
    }
}

Response

Table 4 Parameters in the response body

Parameter

Type

Description

device_template

device_template object

Device template information.

Table 5 device_template

Parameter

Type

Description

id

String

Edge device template ID.

name

String

Edge device template name.

access_protocol

String

Access protocol.

description

String

Edge device template description.

attributes

Object

Static properties of an edge device. 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 of an edge device. 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" } 
                     }

project_id

String

Project ID.

created_at

String

Time when the edge device template is created.

updated_at

String

Time when the edge device is updated.

access_config

Table 24 object

Access configuration, which varies depending on access_protocol.

property_visitors

Table 25 object

Twin property configuration, which varies depending on access_protocol.

tags

Object

Device template tag, in key-value pair format.

Example response

{
    "device_template": {
        "name": "CameraTemplate",
        "description": "This is a camera template",
        "in_use": null,
        "created_at": "2018-07-16T04:01:21.212072",
        "updated_at": null,
        "project_id": "d16e6eb6cc0d49a0941df2f31285757a",
        "id": "82952098-ec24-4643-94e6-9989174fce05",
        "attributes": {
            "cameraURL": {
                "value": "127.0.0.1",
                "metadata": {
                    "type": "string"
                }
            }
            "twin": {
                "runstate": {
                    "expected": {
                        "value": "running"
                    },
                    "metadata": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

Error Codes

For details, see Error Codes.